diff --git a/tracker/announce.go b/tracker/announce.go index 7552287..73e8e5a 100644 --- a/tracker/announce.go +++ b/tracker/announce.go @@ -191,23 +191,36 @@ func handleEvent(c Conn, ann *models.Announce, p *models.Peer, u *models.User, t if t.InLeecherPool(p) { err = leecherFinished(c, t.Infohash, p) - if err != nil { - return - } } snatched = true case t.InLeecherPool(p) && ann.Left == 0: // A leecher completed but the event was never received. err = leecherFinished(c, t.Infohash, p) - if err != nil { - return - } } return } +// leecherFinished moves a peer from the leeching pool to the seeder pool. +func leecherFinished(c Conn, infohash string, p *models.Peer) error { + if err := c.DeleteLeecher(infohash, p.ID); err != nil { + return err + } + + if err := c.PutSeeder(infohash, p); err != nil { + return err + } + + if p.IPv4() { + stats.RecordEvent(stats.CompletedIPv4) + } else { + stats.RecordEvent(stats.CompletedIPv6) + } + + return nil +} + func newAnnounceResponse(ann *models.Announce, announcer *models.Peer, t *models.Torrent) *models.AnnounceResponse { seedCount := len(t.Seeders) leechCount := len(t.Leechers) diff --git a/tracker/conn.go b/tracker/conn.go index a6e2d6c..fae0734 100644 --- a/tracker/conn.go +++ b/tracker/conn.go @@ -10,7 +10,6 @@ import ( "time" "github.com/chihaya/chihaya/config" - "github.com/chihaya/chihaya/stats" "github.com/chihaya/chihaya/tracker/models" ) @@ -97,22 +96,3 @@ type Conn interface { PutClient(clientID string) error DeleteClient(clientID string) error } - -// leecherFinished moves a peer from the leeching pool to the seeder pool. -func leecherFinished(c Conn, infohash string, p *models.Peer) error { - if err := c.DeleteLeecher(infohash, p.ID); err != nil { - return err - } - - if err := c.PutSeeder(infohash, p); err != nil { - return err - } - - if p.IPv4() { - stats.RecordEvent(stats.CompletedIPv4) - } else { - stats.RecordEvent(stats.CompletedIPv6) - } - - return nil -}