mirror of
https://github.com/sot-tech/mochi.git
synced 2026-05-24 08:44:48 -07:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user