]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Send tracker stopped event from the tracker scraper routine v1.3.1
authorMatt Joiner <anacrolix@gmail.com>
Wed, 17 Jul 2019 01:56:25 +0000 (11:56 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Wed, 17 Jul 2019 01:56:25 +0000 (11:56 +1000)
Fixes potential blocking on the announce while the client lock is held, as well as differing arguments to the other announces introduced by #321.

torrent.go
tracker_scraper.go

index 266d345d93ae44abf1f9cfe5b8274973fff89626..33f43b30bcef09240250573eeaae219d5830a873 100644 (file)
@@ -666,9 +666,6 @@ func (t *Torrent) numPiecesCompleted() (num int) {
 }
 
 func (t *Torrent) close() (err error) {
-       for _, ta := range t.trackerAnnouncers {
-               ta.Stop()
-       }
        t.closed.Set()
        t.tickleReaders()
        if t.storage != nil {
index 8148c0f6059e6306ba3e40d90cfa8dac3706f82c..d382017944698289c1e40985fe47185ba81c893a 100644 (file)
@@ -9,16 +9,13 @@ import (
        "time"
 
        "github.com/anacrolix/dht/krpc"
-       "github.com/anacrolix/missinggo"
        "github.com/anacrolix/torrent/tracker"
 )
 
 // Announces a torrent to a tracker at regular intervals, when peers are
 // required.
 type trackerScraper struct {
-       u url.URL
-       // Causes the trackerScraper to stop running.
-       stop         missinggo.Event
+       u            url.URL
        t            *Torrent
        lastAnnounce trackerAnnounceResult
 }
@@ -109,6 +106,7 @@ func (me *trackerScraper) announce(event tracker.AnnounceEvent) (ret trackerAnno
        me.t.cl.lock()
        req := me.t.announceRequest(event)
        me.t.cl.unlock()
+       //log.Printf("announcing %s %s to %q", me.t, req.Event, me.u.String())
        res, err := tracker.Announce{
                HTTPProxy:  me.t.cl.config.HTTPProxy,
                UserAgent:  me.t.cl.config.HTTPUserAgent,
@@ -131,6 +129,7 @@ func (me *trackerScraper) announce(event tracker.AnnounceEvent) (ret trackerAnno
 }
 
 func (me *trackerScraper) Run() {
+       defer me.announceStopped()
        // make sure first announce is a "started"
        e := tracker.Started
        for {
@@ -159,8 +158,6 @@ func (me *trackerScraper) Run() {
                select {
                case <-me.t.closed.LockedChan(me.t.cl.locker()):
                        return
-               case <-me.stop.LockedChan(me.t.cl.locker()):
-                       return
                case <-wantPeers:
                        goto wait
                case <-time.After(time.Until(ar.Completed.Add(interval))):
@@ -168,15 +165,6 @@ func (me *trackerScraper) Run() {
        }
 }
 
-func (me *trackerScraper) Stop() {
-       req := me.t.announceRequest(tracker.Stopped)
-       ip, _ := me.getIp()
-       tracker.Announce{
-               HTTPProxy:  me.t.cl.config.HTTPProxy,
-               UserAgent:  me.t.cl.config.HTTPUserAgent,
-               TrackerUrl: me.trackerUrl(ip),
-               Request:    req,
-               HostHeader: me.u.Host,
-               ServerName: me.u.Hostname(),
-       }.Do()
+func (me *trackerScraper) announceStopped() {
+       me.announce(tracker.Stopped)
 }