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:
Jimmy Zelinskie 2015-06-27 00:09:57 -04:00
parent 8df5f8e193
commit 520a357e37

View file

@ -226,12 +226,7 @@ func (tkr *Tracker) handlePeerEvent(ann *models.Announce, p *models.Peer) (snatc
}
case ann.Event == "completed":
if t.Leechers.Contains(p.Key()) {
err = tkr.leecherFinished(t, p)
} else {
err = models.ErrBadRequest
}
tkr.leecherFinished(t, p)
snatched = true
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.
func (tkr *Tracker) leecherFinished(t *models.Torrent, p *models.Peer) error {
if err := tkr.DeleteLeecher(t.Infohash, p); err != nil {
return err
if t.Leechers.Contains(p.Key()) {
if err := tkr.DeleteLeecher(t.Infohash, p); err != nil {
return err
}
}
if err := tkr.PutSeeder(t.Infohash, p); err != nil {
return err
}
stats.RecordPeerEvent(stats.Completed, p.HasIPv6())
return nil
}