mirror of
https://github.com/LBRYFoundation/tracker.git
synced 2025-08-23 17:47:29 +00:00
Merge pull request #86 from chihaya/fixseeders
tracker: fix logic recording complete events
This commit is contained in:
commit
ba97806a6c
1 changed files with 13 additions and 10 deletions
|
@ -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,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.
|
// 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 {
|
||||||
|
|
Loading…
Add table
Reference in a new issue