peerconn.go | 11 +++++++++-- torrent.go | 7 +++++-- webseed-peer.go | 3 ++- diff --git a/peerconn.go b/peerconn.go index 1f9a3a531e6ab94512700ad908ffcdc99d8ebb52..f9bec8e1d51c3138bde109e0438216dce34a7dd7 100644 --- a/peerconn.go +++ b/peerconn.go @@ -1365,7 +1365,14 @@ if c.peerChoking && c.peerAllowedFast.Get(int(req.Index)) { 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 @@ } } else { torrent.Add("chunks received unwanted", 1) } - }() + } // Do we actually want this chunk? if t.haveChunk(req) { diff --git a/torrent.go b/torrent.go index 059e5883bd6e806fbe55c0fbb5b744498c1f56dd..0b858162fb01314e5d9cfd0761b873839f2ddb47 100644 --- a/torrent.go +++ b/torrent.go @@ -2117,10 +2117,13 @@ outgoing: true, 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, }, diff --git a/webseed-peer.go b/webseed-peer.go index 1856a4d0fcbe12e2e1219eea85f819414a8d53e7..0e4676f57a2072d26e5e575cbaba73a8e14a07a4 100644 --- a/webseed-peer.go +++ b/webseed-peer.go @@ -13,7 +13,8 @@ "github.com/pkg/errors" ) type webseedPeer struct { - client webseed.Client + client webseed.Client + // TODO: Remove finished entries from this. requests map[Request]webseed.Request peer Peer }