]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Remove requests as soon as chunk data is received
authorMatt Joiner <anacrolix@gmail.com>
Thu, 28 Jan 2021 05:36:35 +0000 (16:36 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 28 Jan 2021 05:36:35 +0000 (16:36 +1100)
Note that this breaks the backpressure on webseed responses again, and should be fixed shortly.

peerconn.go
torrent.go
webseed-peer.go

index 1f9a3a531e6ab94512700ad908ffcdc99d8ebb52..f9bec8e1d51c3138bde109e0438216dce34a7dd7 100644 (file)
@@ -1365,7 +1365,14 @@ func (c *Peer) receiveChunk(msg *pp.Message) error {
                torrent.Add("chunks received due to allowed fast", 1)
        }
 
-       defer func() {
+       // TODO: This needs to happen immediately, to prevent cancels occurring asynchronously when have
+       // actually already received the piece, while we have the Client unlocked to write the data out.
+       {
+               if _, ok := c.requests[req]; ok {
+                       for _, f := range c.callbacks.ReceivedRequested {
+                               f(PeerMessageEvent{c, msg})
+                       }
+               }
                // Request has been satisfied.
                if c.deleteRequest(req) {
                        if c.expectingChunks() {
@@ -1374,7 +1381,7 @@ func (c *Peer) receiveChunk(msg *pp.Message) error {
                } else {
                        torrent.Add("chunks received unwanted", 1)
                }
-       }()
+       }
 
        // Do we actually want this chunk?
        if t.haveChunk(req) {
index 059e5883bd6e806fbe55c0fbb5b744498c1f56dd..0b858162fb01314e5d9cfd0761b873839f2ddb47 100644 (file)
@@ -2117,10 +2117,13 @@ func (t *Torrent) addWebSeed(url string) {
                        Network:                  "http",
                        reconciledHandshakeStats: true,
                        peerSentHaveAll:          true,
-                       PeerMaxRequests:          maxRequests,
-                       RemoteAddr:               remoteAddrFromUrl(url),
+                       // TODO: Raise this limit, and instead limit concurrent fetches.
+                       PeerMaxRequests: maxRequests,
+                       RemoteAddr:      remoteAddrFromUrl(url),
                },
                client: webseed.Client{
+                       // TODO: Investigate a MaxConnsPerHost in the transport for this, possibly in a global
+                       // Client.
                        HttpClient: http.DefaultClient,
                        Url:        url,
                },
index 1856a4d0fcbe12e2e1219eea85f819414a8d53e7..0e4676f57a2072d26e5e575cbaba73a8e14a07a4 100644 (file)
@@ -13,7 +13,8 @@ import (
 )
 
 type webseedPeer struct {
-       client   webseed.Client
+       client webseed.Client
+       // TODO: Remove finished entries from this.
        requests map[Request]webseed.Request
        peer     Peer
 }