From 669c69faac0cd2f36bbfa9102afeebda05aee59b Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Wed, 11 May 2022 16:08:19 +1000 Subject: [PATCH] Disable update requests timer --- client.go | 4 +++- peerconn.go | 2 +- requesting.go | 9 +++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/client.go b/client.go index b498339e..71f37e3c 100644 --- a/client.go +++ b/client.go @@ -991,7 +991,9 @@ func (p *Peer) initUpdateRequestsTimer() { panic(p.updateRequestsTimer) } } - p.updateRequestsTimer = time.AfterFunc(math.MaxInt64, p.updateRequestsTimerFunc) + if enableUpdateRequestsTimer { + p.updateRequestsTimer = time.AfterFunc(math.MaxInt64, p.updateRequestsTimerFunc) + } } const peerUpdateRequestsTimerReason = "updateRequestsTimer" diff --git a/peerconn.go b/peerconn.go index 0b2d85f6..554da65f 100644 --- a/peerconn.go +++ b/peerconn.go @@ -503,7 +503,7 @@ var ( // The actual value to use as the maximum outbound requests. func (cn *Peer) nominalMaxRequests() maxRequests { - return maxRequests(maxInt(1, minInt(cn.PeerMaxRequests, cn.peakRequests*2, maxLocalToRemoteRequests))) + return maxInt(1, minInt(cn.PeerMaxRequests, cn.peakRequests*2, maxLocalToRemoteRequests)) } func (cn *Peer) totalExpectingTime() (ret time.Duration) { diff --git a/requesting.go b/requesting.go index 98e9e88b..f1831346 100644 --- a/requesting.go +++ b/requesting.go @@ -312,9 +312,14 @@ func (p *Peer) applyRequestState(next desiredRequestState) { p.peakRequests = newPeakRequests p.needRequestUpdate = "" p.lastRequestUpdate = time.Now() - p.updateRequestsTimer.Reset(updateRequestsTimerDuration) + if enableUpdateRequestsTimer { + p.updateRequestsTimer.Reset(updateRequestsTimerDuration) + } } // This could be set to 10s to match the unchoke/request update interval recommended by some // specifications. I've set it shorter to trigger it more often for testing for now. -const updateRequestsTimerDuration = 3 * time.Second +const ( + updateRequestsTimerDuration = 3 * time.Second + enableUpdateRequestsTimer = false +)