config.go | 3 +++ torrent.go | 5 +++-- tracker_scraper.go | 9 ++++++++- diff --git a/config.go b/config.go index 3d370d55fca2f38c182f34f94b0b15e2607c124c..50c46afa06f43da62124152224cc6c5f17692753 100644 --- a/config.go +++ b/config.go @@ -90,6 +90,9 @@ // Defines proxy for HTTP requests, such as for trackers. It's commonly set from the result of // "net/http".ProxyURL(HTTPProxy). 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 string // Updated occasionally to when there's been some changes to client diff --git a/torrent.go b/torrent.go index 5f18df1f3e9bacfd9dc9707fdbb6a4fc66f16bb5..8fa4c7deee61052f35cbff494c681d5318cdd637 100644 --- a/torrent.go +++ b/torrent.go @@ -1577,8 +1577,9 @@ return nil } } newAnnouncer := &trackerScraper{ - u: *u, - t: t, + u: *u, + t: t, + ipFetcher: t.cl.config.TrackerIpFetcher, } go newAnnouncer.Run() return newAnnouncer diff --git a/tracker_scraper.go b/tracker_scraper.go index c339c2b4415f1e865a8337b0600756120c8293d5..f9d37d86586eb5425601208b50aa39dcf851fd89 100644 --- a/tracker_scraper.go +++ b/tracker_scraper.go @@ -21,6 +21,7 @@ type trackerScraper struct { u url.URL t *Torrent lastAnnounce trackerAnnounceResult + ipFetcher func(*url.URL) ([]net.IP, error) } type torrentTrackerAnnouncer interface { @@ -66,7 +67,13 @@ Completed time.Time } 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 { return }