2
0
mirror of synced 2025-02-24 06:38:14 +00:00

fixup! [trackerscraper] Add custom DNS lookup function

This commit is contained in:
afjoseph 2021-10-29 10:34:38 +02:00 committed by Matt Joiner
parent b33b45baf4
commit 487352fa5b
3 changed files with 10 additions and 10 deletions

View File

@ -92,7 +92,7 @@ type ClientConfig struct {
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. // 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) // Used in case DNS lookups require a special setup (i.e., dns-over-https)
TrackerIpFetcher func(*url.URL) ([]net.IP, error) LookupTrackerIp 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

View File

@ -1577,9 +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, lookupTrackerIp: t.cl.config.LookupTrackerIp,
} }
go newAnnouncer.Run() go newAnnouncer.Run()
return newAnnouncer return newAnnouncer

View File

@ -18,10 +18,10 @@ import (
// Announces a torrent to a tracker at regular intervals, when peers are // Announces a torrent to a tracker at regular intervals, when peers are
// required. // required.
type trackerScraper struct { type trackerScraper struct {
u url.URL u url.URL
t *Torrent t *Torrent
lastAnnounce trackerAnnounceResult lastAnnounce trackerAnnounceResult
ipFetcher func(*url.URL) ([]net.IP, error) lookupTrackerIp func(*url.URL) ([]net.IP, error)
} }
type torrentTrackerAnnouncer interface { type torrentTrackerAnnouncer interface {
@ -68,8 +68,8 @@ type trackerAnnounceResult struct {
func (me *trackerScraper) getIp() (ip net.IP, err error) { func (me *trackerScraper) getIp() (ip net.IP, err error) {
var ips []net.IP var ips []net.IP
if me.ipFetcher != nil { if me.lookupTrackerIp != nil {
ips, err = me.ipFetcher(&me.u) ips, err = me.lookupTrackerIp(&me.u)
} else { } else {
// Do a regular dns lookup // Do a regular dns lookup
ips, err = net.LookupIP(me.u.Hostname()) ips, err = net.LookupIP(me.u.Hostname())