]> Sergey Matveev's repositories - btrtrc.git/commitdiff
reverting usage of proxy for http requests
authorDenis Kuzmenok <denis.kuzmenok@gmail.com>
Tue, 30 Oct 2018 22:32:33 +0000 (23:32 +0100)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 30 Oct 2018 23:54:10 +0000 (10:54 +1100)
client.go
config.go
tracker/http.go
tracker/tracker.go
tracker_scraper.go

index 2dba6973c516cdbbcd5a131c5b895c2dd506fc9f..14fff4f64da6fd8b66895f1cb7f0967b936951a0 100644 (file)
--- a/client.go
+++ b/client.go
@@ -10,6 +10,8 @@ import (
        "fmt"
        "io"
        "net"
+       "net/http"
+       "net/url"
        "strconv"
        "strings"
        "time"
@@ -220,6 +222,12 @@ func NewClient(cfg *ClientConfig) (cl *Client, err error) {
                }
        }
 
+       if cl.config.HTTPProxy == nil && cl.config.ProxyURL != "" {
+               if fixedURL, err := url.Parse(cl.config.ProxyURL); err == nil {
+                       cl.config.HTTPProxy = http.ProxyURL(fixedURL)
+               }
+       }
+
        cl.conns, err = listenAll(cl.enabledPeerNetworks(), cl.config.ListenHost, cl.config.ListenPort, cl.config.ProxyURL, cl.firewallCallback)
        if err != nil {
                return
index 8e5346f9e38d09798e869e5318b77937032d135e..964453af536c78176fe89ce55edbcf8dbc265bf6 100644 (file)
--- a/config.go
+++ b/config.go
@@ -2,6 +2,8 @@ package torrent
 
 import (
        "net"
+       "net/http"
+       "net/url"
        "time"
 
        "github.com/anacrolix/dht"
@@ -67,7 +69,8 @@ type ClientConfig struct {
        EncryptionPolicy
 
        // Sets usage of Socks5 Proxy. Authentication should be included in the url if needed.
-       // Example of setting: "socks5://demo:demo@192.168.99.100:1080"
+       // Examples: socks5://demo:demo@192.168.99.100:1080
+       //                       http://proxy.domain.com:3128
        ProxyURL string
 
        IPBlocklist      iplist.Ranger
@@ -77,6 +80,12 @@ type ClientConfig struct {
        // Perform logging and any other behaviour that will help debug.
        Debug bool `help:"enable debugging"`
 
+       // HTTPProxy defines proxy for HTTP requests.
+       // Format: func(*Request) (*url.URL, error),
+       // or result of http.ProxyURL(HTTPProxy).
+       // By default, it is composed from ClientConfig.ProxyURL,
+       // if not set explicitly in ClientConfig struct
+       HTTPProxy func(*http.Request) (*url.URL, error)
        // HTTPUserAgent changes default UserAgent for HTTP requests
        HTTPUserAgent string
        // Updated occasionally to when there's been some changes to client
index 6a99b560ec969fe52f4931c543c4897900045c72..58d9dc1144585b0f3b00dcce7e806a68b9932b7a 100644 (file)
@@ -105,6 +105,7 @@ func announceHTTP(opt Announce, _url *url.URL) (ret AnnounceResponse, err error)
                        Dial: (&net.Dialer{
                                Timeout: 15 * time.Second,
                        }).Dial,
+                       Proxy:               opt.HTTPProxy,
                        TLSHandshakeTimeout: 15 * time.Second,
                        TLSClientConfig: &tls.Config{
                                InsecureSkipVerify: true,
index bd41e6adea4f27d11d21b9f109cd98c904b260eb..a56a99b74adb221ffa48f830f3eb374b5efde7df 100644 (file)
@@ -2,6 +2,7 @@ package tracker
 
 import (
        "errors"
+       "net/http"
        "net/url"
 
        "github.com/anacrolix/dht/krpc"
@@ -52,6 +53,7 @@ type Announce struct {
        TrackerUrl string
        Request    AnnounceRequest
        HostHeader string
+       HTTPProxy  func(*http.Request) (*url.URL, error)
        ServerName string
        UserAgent  string
        UdpNetwork string
index 2e177badea2b9c904471895249bf6280dac5896b..0a87c868662ca464f9df98b483c91f61623c1426 100644 (file)
@@ -111,6 +111,7 @@ func (me *trackerScraper) announce() (ret trackerAnnounceResult) {
        req := me.t.announceRequest()
        me.t.cl.unlock()
        res, err := tracker.Announce{
+               HTTPProxy:  me.t.cl.config.HTTPProxy,
                UserAgent:  me.t.cl.config.HTTPUserAgent,
                TrackerUrl: me.trackerUrl(ip),
                Request:    req,