From 026d9a99edec786e1827cacdfc76feb4bfa2369e Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 8 Nov 2026 17:35:55 -0500 Subject: [PATCH] instant download and upload speed calculation with bigger sampling interval --- libi2pd_client/Torrents.cpp | 10 ++-------- libi2pd_client/Torrents.h | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/libi2pd_client/Torrents.cpp b/libi2pd_client/Torrents.cpp index 83c6e2c9..a27248d8 100644 --- a/libi2pd_client/Torrents.cpp +++ b/libi2pd_client/Torrents.cpp @@ -2175,10 +2175,7 @@ namespace torrents auto delta = ts - m_LastBlockDownloadTimestamp; if (delta >= BANDWIDTH_RATE_SAMPLING_INTERVAL) { - if (m_DownloadRate) - m_DownloadRate = (m_DownloadRate + m_ReceivedSinceLastTimestamp*1000/delta)/2; - else - m_DownloadRate = m_ReceivedSinceLastTimestamp*1000/delta; + m_DownloadRate = m_ReceivedSinceLastTimestamp*1000/delta; m_LastBlockDownloadTimestamp = ts; m_ReceivedSinceLastTimestamp = 0; } @@ -2223,10 +2220,7 @@ namespace torrents auto delta = ts - s->m_LastBlockUploadTimestamp; if (delta >= BANDWIDTH_RATE_SAMPLING_INTERVAL) { - if (s->m_UploadRate) - s->m_UploadRate = (s->m_UploadRate + s->m_SentSinceLastTimestamp*1000/delta)/2; - else - s->m_UploadRate = s->m_SentSinceLastTimestamp*1000/delta; + s->m_UploadRate = s->m_SentSinceLastTimestamp*1000/delta; s->m_LastBlockUploadTimestamp = ts; s->m_SentSinceLastTimestamp = 0; } diff --git a/libi2pd_client/Torrents.h b/libi2pd_client/Torrents.h index 0ebc7ec3..eeab5676 100644 --- a/libi2pd_client/Torrents.h +++ b/libi2pd_client/Torrents.h @@ -82,7 +82,7 @@ namespace torrents constexpr size_t MAX_INCOMING_REQUESTS_QUEUE_SIZE = 32; constexpr int PIECE_INACTIVITY_TIMEOUT = 22; // in seconds constexpr int HANDSHAKE_RECEIVE_TIMEOUT = 20; // in seconds - constexpr int BANDWIDTH_RATE_SAMPLING_INTERVAL = 20; // in milliseconds + constexpr int BANDWIDTH_RATE_SAMPLING_INTERVAL = 250; // in milliseconds constexpr int TORRENT_FILE_FLUSH_INTERVAL = 30; // in seconds constexpr int TORRENT_FILE_INACTIVITY_TIMEOUT = 90; // in seconds constexpr int TORRENT_RESUME_FILE_UPDATE_INTERVAL = 120; // in seconds