mirror of
https://github.com/sot-tech/mochi.git
synced 2026-05-04 19:29:09 -07:00
tracker: remove last "bad request"
A peer can join a swarm immediately as completed if they already have the file before they ever announce. If we don't have them in our leechers, we were previously failing to add them as a seeder.
This commit is contained in:
@@ -226,12 +226,7 @@ func (tkr *Tracker) handlePeerEvent(ann *models.Announce, p *models.Peer) (snatc
|
|||||||
}
|
}
|
||||||
|
|
||||||
case ann.Event == "completed":
|
case ann.Event == "completed":
|
||||||
if t.Leechers.Contains(p.Key()) {
|
tkr.leecherFinished(t, p)
|
||||||
err = tkr.leecherFinished(t, p)
|
|
||||||
} else {
|
|
||||||
err = models.ErrBadRequest
|
|
||||||
}
|
|
||||||
|
|
||||||
snatched = true
|
snatched = true
|
||||||
|
|
||||||
case t.Leechers.Contains(p.Key()) && ann.Left == 0:
|
case t.Leechers.Contains(p.Key()) && ann.Left == 0:
|
||||||
@@ -244,12 +239,16 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
stats.RecordPeerEvent(stats.Completed, p.HasIPv6())
|
stats.RecordPeerEvent(stats.Completed, p.HasIPv6())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user