Skip to content

Commit d04b19d

Browse files
committed
don't recalculate badwidth if clock was adjusted too much
1 parent 04adc14 commit d04b19d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

libi2pd/TransportSession.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,16 @@ namespace transport
152152

153153
void UpdateBandwidth ()
154154
{
155-
uint64_t interval = m_LastActivityTimestamp - m_LastBandwidthUpdateTimestamp;
156-
if (interval > TRANSPORT_SESSION_BANDWIDTH_UPDATE_MIN_INTERVAL)
155+
int64_t interval = m_LastActivityTimestamp - m_LastBandwidthUpdateTimestamp;
156+
if (interval < 0 || interval > 60*10) // 10 minutes
157+
{
158+
// clock was adjusted, copy new values
159+
m_LastBandWidthUpdateNumSentBytes = m_NumSentBytes;
160+
m_LastBandWidthUpdateNumReceivedBytes = m_NumReceivedBytes;
161+
m_LastBandwidthUpdateTimestamp = m_LastActivityTimestamp;
162+
return;
163+
}
164+
if ((uint64_t)interval > TRANSPORT_SESSION_BANDWIDTH_UPDATE_MIN_INTERVAL)
157165
{
158166
m_OutBandwidth = (m_NumSentBytes - m_LastBandWidthUpdateNumSentBytes)/interval;
159167
m_LastBandWidthUpdateNumSentBytes = m_NumSentBytes;

0 commit comments

Comments
 (0)