client.go | 8 +++++++- torrent.go | 10 +--------- diff --git a/client.go b/client.go index 30ab0cd6cf0ef3ab78b8c82b8fb844394f656816..cb988201c9cc8fee9abaabbb15bd900c30ac1456 100644 --- a/client.go +++ b/client.go @@ -82,6 +82,7 @@ websocketTrackers websocketTrackers activeAnnounceLimiter limiter.Instance + webseedHttpClient *http.Client } type ipStr string @@ -199,9 +200,14 @@ cl.dopplegangerAddrs = make(map[string]struct{}) cl.torrents = make(map[metainfo.Hash]*Torrent) cl.dialRateLimiter = rate.NewLimiter(10, 10) cl.activeAnnounceLimiter.SlotsPerKey = 2 - cl.event.L = cl.locker() cl.ipBlockList = cfg.IPBlocklist + cl.webseedHttpClient = &http.Client{ + Transport: &http.Transport{ + Proxy: cfg.HTTPProxy, + MaxConnsPerHost: 10, + }, + } } func NewClient(cfg *ClientConfig) (cl *Client, err error) { diff --git a/torrent.go b/torrent.go index b9ecb0f636ac0764f25f395cd71bdcb38bd06224..441f613c17d5242ec4719c32354da9ca6ec524a3 100644 --- a/torrent.go +++ b/torrent.go @@ -8,7 +8,6 @@ "crypto/sha1" "errors" "fmt" "io" - "net/http" "net/url" "sort" "strings" @@ -2180,12 +2179,6 @@ func (t *Torrent) callbacks() *Callbacks { return &t.cl.config.Callbacks } -var WebseedHttpClient = &http.Client{ - Transport: &http.Transport{ - MaxConnsPerHost: 10, - }, -} - func (t *Torrent) addWebSeed(url string) { if t.cl.config.DisableWebseeds { return @@ -2212,8 +2205,7 @@ RemoteAddr: remoteAddrFromUrl(url), callbacks: t.callbacks(), }, client: webseed.Client{ - // Consider a MaxConnsPerHost in the transport for this, possibly in a global Client. - HttpClient: WebseedHttpClient, + HttpClient: t.cl.webseedHttpClient, Url: url, }, activeRequests: make(map[Request]webseed.Request, maxRequests),