Put leecherFinished in announce.go and remove unnecessary code

This commit is contained in:
Justin Li 2014-07-22 23:31:19 -04:00
parent de69eaeafe
commit 11d06f7830
2 changed files with 19 additions and 26 deletions

View file

@ -191,23 +191,36 @@ func handleEvent(c Conn, ann *models.Announce, p *models.Peer, u *models.User, t
if t.InLeecherPool(p) { if t.InLeecherPool(p) {
err = leecherFinished(c, t.Infohash, p) err = leecherFinished(c, t.Infohash, p)
if err != nil {
return
}
} }
snatched = true snatched = true
case t.InLeecherPool(p) && ann.Left == 0: case t.InLeecherPool(p) && ann.Left == 0:
// A leecher completed but the event was never received. // A leecher completed but the event was never received.
err = leecherFinished(c, t.Infohash, p) err = leecherFinished(c, t.Infohash, p)
if err != nil {
return
}
} }
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 { func newAnnounceResponse(ann *models.Announce, announcer *models.Peer, t *models.Torrent) *models.AnnounceResponse {
seedCount := len(t.Seeders) seedCount := len(t.Seeders)
leechCount := len(t.Leechers) leechCount := len(t.Leechers)

View file

@ -10,7 +10,6 @@ import (
"time" "time"
"github.com/chihaya/chihaya/config" "github.com/chihaya/chihaya/config"
"github.com/chihaya/chihaya/stats"
"github.com/chihaya/chihaya/tracker/models" "github.com/chihaya/chihaya/tracker/models"
) )
@ -97,22 +96,3 @@ type Conn interface {
PutClient(clientID string) error PutClient(clientID string) error
DeleteClient(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
}