From de083804640749cd128a534c755231818f04c01b Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Wed, 11 Jul 2018 15:10:58 +1000 Subject: [PATCH] Decide where to set proxy for HTTP trackers Remove old ClientConfig.setProxyURL, set this directly now through ClientConfig.TrackerHttpClient.Transport.Proxy (if your Client allows it). --- config.go | 22 ++++------------------ tracker_scraper.go | 2 +- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/config.go b/config.go index af7b2c06..2d9a3afb 100644 --- a/config.go +++ b/config.go @@ -4,7 +4,6 @@ import ( "crypto/tls" "net" "net/http" - "net/url" "time" "github.com/anacrolix/dht" @@ -80,10 +79,10 @@ type ClientConfig struct { // Perform logging and any other behaviour that will help debug. Debug bool `help:"enable debugging"` - // HTTP client used to query the tracker endpoint. Default is DefaultHTTPClient - HTTP *http.Client + // For querying HTTP trackers. + TrackerHttpClient *http.Client // HTTPUserAgent changes default UserAgent for HTTP requests - HTTPUserAgent string `long:"http-user-agent"` + HTTPUserAgent string // Updated occasionally to when there's been some changes to client // behaviour in case other clients are assuming anything of us. See also // `bep20`. @@ -124,7 +123,7 @@ func (cfg *ClientConfig) SetListenAddr(addr string) *ClientConfig { func NewDefaultClientConfig() *ClientConfig { return &ClientConfig{ - HTTP: &http.Client{ + TrackerHttpClient: &http.Client{ Timeout: time.Second * 15, Transport: &http.Transport{ Dial: (&net.Dialer{ @@ -150,19 +149,6 @@ func NewDefaultClientConfig() *ClientConfig { } } -func (cfg *ClientConfig) setProxyURL() { - fixedURL, err := url.Parse(cfg.ProxyURL) - if err != nil { - return - } - - cfg.HTTP.Transport = &http.Transport{ - Proxy: http.ProxyURL(fixedURL), - TLSHandshakeTimeout: 15 * time.Second, - TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, - } -} - type EncryptionPolicy struct { DisableEncryption bool ForceEncryption bool // Don't allow unobfuscated connections. diff --git a/tracker_scraper.go b/tracker_scraper.go index 39359dbe..7b2b5137 100644 --- a/tracker_scraper.go +++ b/tracker_scraper.go @@ -111,7 +111,7 @@ func (me *trackerScraper) announce() (ret trackerAnnounceResult) { req := me.t.announceRequest() me.t.cl.mu.Unlock() res, err := tracker.Announce{ - HttpClient: me.t.cl.config.HTTP, + HttpClient: me.t.cl.config.TrackerHttpClient, UserAgent: me.t.cl.config.HTTPUserAgent, TrackerUrl: me.trackerUrl(ip), Request: req, -- 2.48.1