]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix peer request sleepiness
authorMatt Joiner <anacrolix@gmail.com>
Wed, 28 Oct 2020 23:45:38 +0000 (10:45 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 29 Oct 2020 22:13:39 +0000 (09:13 +1100)
New requests weren't being issued to the current peer when being deleted. For webseeds, this would cause them to not bother issuing new requests indefinitely.

(cherry picked from commit 146a16df4ea26d33b0ce0391c8220de14c9e18f4)

peerconn.go

index 08f74c5dbb9d736d5048689bd0dc87d210e36ce0..60d004650028e50b3ec6b4f85076a0cfad40a2a2 100644 (file)
@@ -1493,17 +1493,26 @@ func (c *peer) deleteRequest(r request) bool {
        if n < 0 {
                panic(n)
        }
-       // If a request is rejected, updating the requests for the current peer first will miss the
-       // opportunity to try other peers for that request instead. I'm not sure about the interested
-       // check in the following loop however.
-       if false {
+       // If a request fails, updating the requests for the current peer first may miss the opportunity
+       // to try other peers for that request instead, depending on the request strategy. This might
+       // only affect webseed peers though, since they synchronously issue new requests: PeerConns do
+       // it in the writer routine.
+       const updateCurrentConnRequestsFirst = false
+       if updateCurrentConnRequestsFirst {
                c.updateRequests()
        }
+       // Give other conns a chance to pick up the request.
        c.t.iterPeers(func(_c *peer) {
-               if !_c.interested && _c != c && c.peerHasPiece(pieceIndex(r.Index)) {
+               // We previously checked that the peer wasn't interested to to only wake connections that
+               // were unable to issue requests due to starvation by the request strategy. There could be
+               // performance ramifications.
+               if _c != c && c.peerHasPiece(pieceIndex(r.Index)) {
                        _c.updateRequests()
                }
        })
+       if !updateCurrentConnRequestsFirst {
+               c.updateRequests()
+       }
        return true
 }