]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Reduce idle request updates due to choke and unchoke messages
authorMatt Joiner <anacrolix@gmail.com>
Mon, 29 Nov 2021 01:12:30 +0000 (12:12 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 29 Nov 2021 01:12:30 +0000 (12:12 +1100)
peerconn.go

index 003e32c57821fd135613ca370219170bb3828405..8efa343f68b3f84330219420ff270466a3928721 100644 (file)
@@ -1107,7 +1107,9 @@ func (c *PeerConn) mainReadLoop() (err error) {
                        c.peerChoking = true
                        // We can now reset our interest. I think we do this after setting the flag in case the
                        // peerImpl updates synchronously (webseeds?).
-                       c.updateRequests("choked")
+                       if !c.actualRequestState.Requests.IsEmpty() {
+                               c.updateRequests("choked")
+                       }
                        c.updateExpectingChunks()
                case pp.Unchoke:
                        if !c.peerChoking {
@@ -1133,7 +1135,9 @@ func (c *PeerConn) mainReadLoop() (err error) {
                                        c.fastEnabled())
                                torrent.Add("requestsPreservedThroughChoking", int64(preservedCount))
                        }
-                       c.updateRequests("unchoked")
+                       if !c.t._pendingPieces.IsEmpty() {
+                               c.updateRequests("unchoked")
+                       }
                        c.updateExpectingChunks()
                case pp.Interested:
                        c.peerInterested = true