]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Pass HTTP Proxy config into webseeding HTTP client
authorMatt Joiner <anacrolix@gmail.com>
Fri, 12 Nov 2021 03:16:14 +0000 (14:16 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Fri, 12 Nov 2021 03:16:14 +0000 (14:16 +1100)
client.go
torrent.go

index 30ab0cd6cf0ef3ab78b8c82b8fb844394f656816..cb988201c9cc8fee9abaabbb15bd900c30ac1456 100644 (file)
--- a/client.go
+++ b/client.go
@@ -82,6 +82,7 @@ type Client struct {
        websocketTrackers websocketTrackers
 
        activeAnnounceLimiter limiter.Instance
+       webseedHttpClient     *http.Client
 }
 
 type ipStr string
@@ -199,9 +200,14 @@ func (cl *Client) init(cfg *ClientConfig) {
        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) {
index b9ecb0f636ac0764f25f395cd71bdcb38bd06224..441f613c17d5242ec4719c32354da9ca6ec524a3 100644 (file)
@@ -8,7 +8,6 @@ import (
        "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 @@ func (t *Torrent) addWebSeed(url string) {
                        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),