]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Decide where to set proxy for HTTP trackers
authorMatt Joiner <anacrolix@gmail.com>
Wed, 11 Jul 2018 05:10:58 +0000 (15:10 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Wed, 11 Jul 2018 05:10:58 +0000 (15:10 +1000)
Remove old ClientConfig.setProxyURL, set this directly now through ClientConfig.TrackerHttpClient.Transport.Proxy (if your Client allows it).

config.go
tracker_scraper.go

index af7b2c06ff63a5d1becb783373f25f276a04d686..2d9a3afb9168365b2e198f41f86ca6811e6b51a3 100644 (file)
--- 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.
index 39359dbe464e80b0ec747c519b891a08438e1fc0..7b2b5137e8aa995a08ee1597680698c5b34186c9 100644 (file)
@@ -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,