Don't write to the peer maps in the announce code

This commit is contained in:
Justin Li 2014-08-01 14:09:29 -04:00
parent 2a12685007
commit f48e1e452f

View file

@ -110,14 +110,12 @@ func updatePeer(c Conn, ann *models.Announce, peer *models.Peer) (created bool,
if err != nil { if err != nil {
return return
} }
t.Seeders[p.Key()] = *p
case t.InLeecherPool(p): case t.InLeecherPool(p):
err = c.PutLeecher(t.Infohash, p) err = c.PutLeecher(t.Infohash, p)
if err != nil { if err != nil {
return return
} }
t.Leechers[p.Key()] = *p
default: default:
if ann.Event != "" && ann.Event != "started" { if ann.Event != "" && ann.Event != "started" {
@ -130,7 +128,6 @@ func updatePeer(c Conn, ann *models.Announce, peer *models.Peer) (created bool,
if err != nil { if err != nil {
return return
} }
t.Seeders[p.Key()] = *p
stats.RecordPeerEvent(stats.NewSeed, p.HasIPv6()) stats.RecordPeerEvent(stats.NewSeed, p.HasIPv6())
} else { } else {
@ -138,7 +135,6 @@ func updatePeer(c Conn, ann *models.Announce, peer *models.Peer) (created bool,
if err != nil { if err != nil {
return return
} }
t.Leechers[p.Key()] = *p
stats.RecordPeerEvent(stats.NewLeech, p.HasIPv6()) stats.RecordPeerEvent(stats.NewLeech, p.HasIPv6())
} }
created = true created = true
@ -187,7 +183,6 @@ func handlePeerEvent(c Conn, ann *models.Announce, p *models.Peer) (snatched boo
if err != nil { if err != nil {
return return
} }
delete(t.Seeders, p.Key())
stats.RecordPeerEvent(stats.DeletedSeed, p.HasIPv6()) stats.RecordPeerEvent(stats.DeletedSeed, p.HasIPv6())
} else if t.InLeecherPool(p) { } else if t.InLeecherPool(p) {
@ -195,7 +190,6 @@ func handlePeerEvent(c Conn, ann *models.Announce, p *models.Peer) (snatched boo
if err != nil { if err != nil {
return return
} }
delete(t.Leechers, p.Key())
stats.RecordPeerEvent(stats.DeletedLeech, p.HasIPv6()) stats.RecordPeerEvent(stats.DeletedLeech, p.HasIPv6())
} }
@ -228,13 +222,9 @@ func leecherFinished(c Conn, t *models.Torrent, p *models.Peer) error {
if err := c.DeleteLeecher(t.Infohash, p); err != nil { if err := c.DeleteLeecher(t.Infohash, p); err != nil {
return err return err
} }
delete(t.Leechers, p.Key())
if err := c.PutSeeder(t.Infohash, p); err != nil { if err := c.PutSeeder(t.Infohash, p); err != nil {
return err return err
} }
t.Seeders[p.Key()] = *p
stats.RecordPeerEvent(stats.Completed, p.HasIPv6()) stats.RecordPeerEvent(stats.Completed, p.HasIPv6())
return nil return nil
} }