[trackerscraper] Add custom DNS lookup function
This commit is contained in:
parent
c2ed60f9f2
commit
2a6152b832
|
@ -90,6 +90,9 @@ type ClientConfig struct {
|
||||||
// Defines proxy for HTTP requests, such as for trackers. It's commonly set from the result of
|
// Defines proxy for HTTP requests, such as for trackers. It's commonly set from the result of
|
||||||
// "net/http".ProxyURL(HTTPProxy).
|
// "net/http".ProxyURL(HTTPProxy).
|
||||||
HTTPProxy func(*http.Request) (*url.URL, error)
|
HTTPProxy func(*http.Request) (*url.URL, error)
|
||||||
|
// Takes a tracker's hostname and requests DNS A and AAAA records.
|
||||||
|
// Used in case DNS lookups require a special setup (i.e., dns-over-https)
|
||||||
|
TrackerIpFetcher func(*url.URL) ([]net.IP, error)
|
||||||
// HTTPUserAgent changes default UserAgent for HTTP requests
|
// HTTPUserAgent changes default UserAgent for HTTP requests
|
||||||
HTTPUserAgent string
|
HTTPUserAgent string
|
||||||
// Updated occasionally to when there's been some changes to client
|
// Updated occasionally to when there's been some changes to client
|
||||||
|
|
|
@ -1577,8 +1577,9 @@ func (t *Torrent) startScrapingTracker(_url string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
newAnnouncer := &trackerScraper{
|
newAnnouncer := &trackerScraper{
|
||||||
u: *u,
|
u: *u,
|
||||||
t: t,
|
t: t,
|
||||||
|
ipFetcher: t.cl.config.TrackerIpFetcher,
|
||||||
}
|
}
|
||||||
go newAnnouncer.Run()
|
go newAnnouncer.Run()
|
||||||
return newAnnouncer
|
return newAnnouncer
|
||||||
|
|
|
@ -21,6 +21,7 @@ type trackerScraper struct {
|
||||||
u url.URL
|
u url.URL
|
||||||
t *Torrent
|
t *Torrent
|
||||||
lastAnnounce trackerAnnounceResult
|
lastAnnounce trackerAnnounceResult
|
||||||
|
ipFetcher func(*url.URL) ([]net.IP, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type torrentTrackerAnnouncer interface {
|
type torrentTrackerAnnouncer interface {
|
||||||
|
@ -66,7 +67,13 @@ type trackerAnnounceResult struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (me *trackerScraper) getIp() (ip net.IP, err error) {
|
func (me *trackerScraper) getIp() (ip net.IP, err error) {
|
||||||
ips, err := net.LookupIP(me.u.Hostname())
|
var ips []net.IP
|
||||||
|
if me.ipFetcher != nil {
|
||||||
|
ips, err = me.ipFetcher(&me.u)
|
||||||
|
} else {
|
||||||
|
// Do a regular dns lookup
|
||||||
|
ips, err = net.LookupIP(me.u.Hostname())
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue