tracker: fix logic recording complete events

520a357 inadvertently changed the logic on how many times
leecherFinished was being called and recording completion events to the
stats. This commit makes this that clearer and avoids over incrementing
the number of Seeders in our stats.
This commit is contained in:
Jimmy Zelinskie 2015-08-26 16:14:11 -04:00
parent 7f1829dd68
commit dfd59e8823

View file

@ -225,13 +225,18 @@ func (tkr *Tracker) handlePeerEvent(ann *models.Announce, p *models.Peer) (snatc
stats.RecordPeerEvent(stats.DeletedLeech, p.HasIPv6()) stats.RecordPeerEvent(stats.DeletedLeech, p.HasIPv6())
} }
case ann.Event == "completed": case t.Leechers.Contains(p.Key()) && (ann.Event == "completed" || ann.Left == 0):
tkr.leecherFinished(t, p) // A leecher has completed or this is the first time we've seen them since
snatched = true // they've completed.
case t.Leechers.Contains(p.Key()) && ann.Left == 0:
// A leecher completed but the event was never received.
err = tkr.leecherFinished(t, p) err = tkr.leecherFinished(t, p)
if err != nil {
return
}
// Only mark as snatched if we receive the completed event.
if ann.Event == "completed" {
snatched = true
}
} }
return return
@ -239,11 +244,9 @@ func (tkr *Tracker) handlePeerEvent(ann *models.Announce, p *models.Peer) (snatc
// leecherFinished moves a peer from the leeching pool to the seeder pool. // leecherFinished moves a peer from the leeching pool to the seeder pool.
func (tkr *Tracker) leecherFinished(t *models.Torrent, p *models.Peer) error { func (tkr *Tracker) leecherFinished(t *models.Torrent, p *models.Peer) error {
if t.Leechers.Contains(p.Key()) {
if err := tkr.DeleteLeecher(t.Infohash, p); err != nil { if err := tkr.DeleteLeecher(t.Infohash, p); err != nil {
return err return err
} }
}
if err := tkr.PutSeeder(t.Infohash, p); err != nil { if err := tkr.PutSeeder(t.Infohash, p); err != nil {
return err return err