parent
5e3f9893f3
commit
ad0c33a50c
|
@ -3,7 +3,6 @@ package main
|
|||
import (
|
||||
"log"
|
||||
"math"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"sync"
|
||||
|
@ -85,7 +84,6 @@ func announces(uri string, ar tracker.AnnounceRequest) (ret []announceResult) {
|
|||
a := tracker.Announce{
|
||||
Request: ar,
|
||||
TrackerUrl: uri,
|
||||
HttpClient: http.DefaultClient,
|
||||
}
|
||||
if u.Scheme == "udp" {
|
||||
a.UdpNetwork = "udp4"
|
||||
|
|
13
config.go
13
config.go
|
@ -1,9 +1,7 @@
|
|||
package torrent
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/anacrolix/dht"
|
||||
|
@ -79,8 +77,6 @@ type ClientConfig struct {
|
|||
// Perform logging and any other behaviour that will help debug.
|
||||
Debug bool `help:"enable debugging"`
|
||||
|
||||
// For querying HTTP trackers.
|
||||
TrackerHttpClient *http.Client
|
||||
// HTTPUserAgent changes default UserAgent for HTTP requests
|
||||
HTTPUserAgent string
|
||||
// Updated occasionally to when there's been some changes to client
|
||||
|
@ -129,15 +125,6 @@ func (cfg *ClientConfig) SetListenAddr(addr string) *ClientConfig {
|
|||
|
||||
func NewDefaultClientConfig() *ClientConfig {
|
||||
return &ClientConfig{
|
||||
TrackerHttpClient: &http.Client{
|
||||
Timeout: time.Second * 15,
|
||||
Transport: &http.Transport{
|
||||
Dial: (&net.Dialer{
|
||||
Timeout: 15 * time.Second,
|
||||
}).Dial,
|
||||
TLSHandshakeTimeout: 15 * time.Second,
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
}},
|
||||
HTTPUserAgent: DefaultHTTPUserAgent,
|
||||
ExtendedHandshakeClientVersion: "go.torrent dev 20150624",
|
||||
Bep20: "-GT0001-",
|
||||
|
|
|
@ -2,11 +2,14 @@ package tracker
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/anacrolix/dht/krpc"
|
||||
"github.com/anacrolix/missinggo/httptoo"
|
||||
|
@ -96,7 +99,19 @@ func announceHTTP(opt Announce, _url *url.URL) (ret AnnounceResponse, err error)
|
|||
req, err := http.NewRequest("GET", _url.String(), nil)
|
||||
req.Header.Set("User-Agent", opt.UserAgent)
|
||||
req.Host = opt.HostHeader
|
||||
resp, err := opt.HttpClient.Do(req)
|
||||
resp, err := (&http.Client{
|
||||
Timeout: time.Second * 15,
|
||||
Transport: &http.Transport{
|
||||
Dial: (&net.Dialer{
|
||||
Timeout: 15 * time.Second,
|
||||
}).Dial,
|
||||
TLSHandshakeTimeout: 15 * time.Second,
|
||||
TLSClientConfig: &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
ServerName: opt.ServerName,
|
||||
},
|
||||
},
|
||||
}).Do(req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package tracker
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/anacrolix/dht/krpc"
|
||||
|
@ -53,8 +52,8 @@ type Announce struct {
|
|||
TrackerUrl string
|
||||
Request AnnounceRequest
|
||||
HostHeader string
|
||||
ServerName string
|
||||
UserAgent string
|
||||
HttpClient *http.Client
|
||||
UdpNetwork string
|
||||
// If the port is zero, it's assumed to be the same as the Request.Port
|
||||
ClientIp4 krpc.NodeAddr
|
||||
|
|
|
@ -111,11 +111,11 @@ func (me *trackerScraper) announce() (ret trackerAnnounceResult) {
|
|||
req := me.t.announceRequest()
|
||||
me.t.cl.unlock()
|
||||
res, err := tracker.Announce{
|
||||
HttpClient: me.t.cl.config.TrackerHttpClient,
|
||||
UserAgent: me.t.cl.config.HTTPUserAgent,
|
||||
TrackerUrl: me.trackerUrl(ip),
|
||||
Request: req,
|
||||
HostHeader: me.u.Host,
|
||||
ServerName: me.u.Hostname(),
|
||||
UdpNetwork: me.u.Scheme,
|
||||
ClientIp4: krpc.NodeAddr{IP: me.t.cl.config.PublicIp4},
|
||||
ClientIp6: krpc.NodeAddr{IP: me.t.cl.config.PublicIp6},
|
||||
|
|
Loading…
Reference in New Issue