// Return how long to wait before trying again. For most errors, we return 5 // minutes, a relatively quick turn around for DNS changes. func (me *trackerScraper) announce() (ret trackerAnnounceResult) { defer func() { ret.Completed = time.Now() }() ret.Interval = 5 * time.Minute blocked, urlToUse, host, err := me.t.cl.prepareTrackerAnnounceUnlocked(me.url) if err != nil { ret.Err = err return } if blocked { ret.Err = errors.New("blocked by IP") return } me.t.cl.mu.Lock() req := me.t.announceRequest() me.t.cl.mu.Unlock() res, err := tracker.AnnounceHost(urlToUse, &req, host) if err != nil { ret.Err = err return } me.t.AddPeers(trackerToTorrentPeers(res.Peers)) ret.NumPeers = len(res.Peers) ret.Interval = time.Duration(res.Interval) * time.Second return }
// Return how long to wait before trying again. For most errors, we return 5 // minutes, a relatively quick turn around for DNS changes. func (me *trackerScraper) announce() time.Duration { blocked, urlToUse, host, err := me.t.cl.prepareTrackerAnnounceUnlocked(me.url) if err != nil { log.Printf("error preparing announce to %q: %s", me.url, err) return 5 * time.Minute } if blocked { log.Printf("announce to tracker %q blocked by IP", me.url) return 5 * time.Minute } me.t.cl.mu.Lock() req := me.t.announceRequest() me.t.cl.mu.Unlock() res, err := tracker.AnnounceHost(urlToUse, &req, host) if err != nil { log.Printf("error announcing %s %q to %q: %s", me.t.InfoHash().HexString(), me.t.Name(), me.url, err) return 5 * time.Minute } me.t.AddPeers(trackerToTorrentPeers(res.Peers)) return time.Duration(res.Interval) * time.Second }