Skip to content

Commit

Permalink
don't recalculate badwidth if clock was adjusted too much
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Oct 18, 2023
1 parent 04adc14 commit d04b19d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions libi2pd/TransportSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,16 @@ namespace transport

void UpdateBandwidth ()
{
uint64_t interval = m_LastActivityTimestamp - m_LastBandwidthUpdateTimestamp;
if (interval > TRANSPORT_SESSION_BANDWIDTH_UPDATE_MIN_INTERVAL)
int64_t interval = m_LastActivityTimestamp - m_LastBandwidthUpdateTimestamp;
if (interval < 0 || interval > 60*10) // 10 minutes
{
// clock was adjusted, copy new values
m_LastBandWidthUpdateNumSentBytes = m_NumSentBytes;
m_LastBandWidthUpdateNumReceivedBytes = m_NumReceivedBytes;
m_LastBandwidthUpdateTimestamp = m_LastActivityTimestamp;
return;
}
if ((uint64_t)interval > TRANSPORT_SESSION_BANDWIDTH_UPDATE_MIN_INTERVAL)
{
m_OutBandwidth = (m_NumSentBytes - m_LastBandWidthUpdateNumSentBytes)/interval;
m_LastBandWidthUpdateNumSentBytes = m_NumSentBytes;
Expand Down

0 comments on commit d04b19d

Please sign in to comment.