From dfd59e8823f7d7cfb6dc9535889171bcda0f93b2 Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Wed, 26 Aug 2015 16:14:11 -0400 Subject: [PATCH] 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. --- tracker/announce.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/tracker/announce.go b/tracker/announce.go index 57b1c3d..874eb0a 100644 --- a/tracker/announce.go +++ b/tracker/announce.go @@ -225,13 +225,18 @@ func (tkr *Tracker) handlePeerEvent(ann *models.Announce, p *models.Peer) (snatc stats.RecordPeerEvent(stats.DeletedLeech, p.HasIPv6()) } - case ann.Event == "completed": - tkr.leecherFinished(t, p) - snatched = true - - case t.Leechers.Contains(p.Key()) && ann.Left == 0: - // A leecher completed but the event was never received. + case t.Leechers.Contains(p.Key()) && (ann.Event == "completed" || ann.Left == 0): + // A leecher has completed or this is the first time we've seen them since + // they've completed. 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 @@ -239,10 +244,8 @@ func (tkr *Tracker) handlePeerEvent(ann *models.Announce, p *models.Peer) (snatc // leecherFinished moves a peer from the leeching pool to the seeder pool. 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 { - return err - } + if err := tkr.DeleteLeecher(t.Infohash, p); err != nil { + return err } if err := tkr.PutSeeder(t.Infohash, p); err != nil {