]> 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>
Wed, 28 Oct 2020 23:45:38 +0000 (10:45 +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.

peerconn.go

index c6019d29f078630c76a6e9c87a49e1b1a3333472..64d2f7939244c9ce16e58fdc21a9f02adb69de8d 100644 (file)
@@ -1497,17 +1497,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
 }