]> Sergey Matveev's repositories - btrtrc.git/blobdiff - torrent.go
Rework webseed peers to use a pool of requesters
[btrtrc.git] / torrent.go
index 51921c12052f2e0f268e5df833fd2c657971f54b..26f49b82a6b289a08e9526d015b5d974db90f902 100644 (file)
@@ -26,6 +26,7 @@ import (
        "github.com/anacrolix/dht/v2"
        "github.com/anacrolix/log"
        "github.com/anacrolix/missinggo"
+       "github.com/anacrolix/missinggo/iter"
        "github.com/anacrolix/missinggo/perf"
        "github.com/anacrolix/missinggo/pubsub"
        "github.com/anacrolix/missinggo/slices"
@@ -2118,17 +2119,20 @@ func (t *Torrent) addWebSeed(url string) {
                        reconciledHandshakeStats: true,
                        peerSentHaveAll:          true,
                        // TODO: Raise this limit, and instead limit concurrent fetches.
-                       PeerMaxRequests: maxRequests,
+                       PeerMaxRequests: 32,
                        RemoteAddr:      remoteAddrFromUrl(url),
                        callbacks:       t.callbacks(),
                },
                client: webseed.Client{
-                       // TODO: Investigate a MaxConnsPerHost in the transport for this, possibly in a global
-                       // Client.
+                       // Consider a MaxConnsPerHost in the transport for this, possibly in a global Client.
                        HttpClient: http.DefaultClient,
                        Url:        url,
                },
-               requests: make(map[Request]webseed.Request, maxRequests),
+               activeRequests: make(map[Request]webseed.Request, maxRequests),
+       }
+       ws.requesterCond.L = t.cl.locker()
+       for range iter.N(maxRequests) {
+               go ws.requester()
        }
        for _, f := range t.callbacks().NewPeer {
                f(&ws.peer)