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).
This commit is contained in:
parent
b9cfe71d90
commit
de08380464
22
config.go
22
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.
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user