Clean up types more

This commit is contained in:
Justin Li 2014-07-17 01:14:50 -04:00
parent 9dde295b7c
commit 67a8473f6e
4 changed files with 12 additions and 11 deletions

View file

@ -95,8 +95,8 @@ func loadTestData(tkr *tracker.Tracker) error {
torrent := &models.Torrent{ torrent := &models.Torrent{
ID: 1, ID: 1,
Infohash: infoHash, Infohash: infoHash,
Seeders: make(map[string]models.Peer), Seeders: models.PeerMap{},
Leechers: make(map[string]models.Peer), Leechers: models.PeerMap{},
} }
return conn.PutTorrent(torrent) return conn.PutTorrent(torrent)

View file

@ -41,8 +41,8 @@ func (t *Tracker) HandleAnnounce(ann *models.Announce, w Writer) error {
case !t.cfg.Private && err == ErrTorrentDNE: case !t.cfg.Private && err == ErrTorrentDNE:
torrent = &models.Torrent{ torrent = &models.Torrent{
Infohash: ann.Infohash, Infohash: ann.Infohash,
Seeders: make(map[string]models.Peer), Seeders: models.PeerMap{},
Leechers: make(map[string]models.Peer), Leechers: models.PeerMap{},
} }
err = conn.PutTorrent(torrent) err = conn.PutTorrent(torrent)
@ -149,7 +149,7 @@ func handleEvent(c Conn, ann *models.Announce, p *models.Peer, u *models.User, t
t.Snatches++ t.Snatches++
if t.InLeecherPool(p) { if t.InLeecherPool(p) {
err = LeecherFinished(c, t.Infohash, p) err = leecherFinished(c, t.Infohash, p)
if err != nil { if err != nil {
return return
} }
@ -157,7 +157,7 @@ func handleEvent(c Conn, ann *models.Announce, p *models.Peer, u *models.User, t
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 { if err != nil {
return return
} }
@ -198,7 +198,7 @@ func getPeers(ann *models.Announce, announcer *models.Peer, t *models.Torrent, w
return appendPeers(ipv4s, ipv6s, announcer, t.Leechers, wanted-len(ipv4s)-len(ipv6s)) return appendPeers(ipv4s, ipv6s, announcer, t.Leechers, wanted-len(ipv4s)-len(ipv6s))
} }
func appendPeers(ipv4s, ipv6s models.PeerList, announcer *models.Peer, peers map[string]models.Peer, wanted int) (models.PeerList, models.PeerList) { func appendPeers(ipv4s, ipv6s models.PeerList, announcer *models.Peer, peers models.PeerMap, wanted int) (models.PeerList, models.PeerList) {
count := 0 count := 0
for _, peer := range peers { for _, peer := range peers {

View file

@ -93,8 +93,8 @@ type Conn interface {
DeleteClient(clientID string) error DeleteClient(clientID string) error
} }
// 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 LeecherFinished(c Conn, infohash string, p *models.Peer) error { func leecherFinished(c Conn, infohash string, p *models.Peer) error {
err := c.DeleteLeecher(infohash, p.Key()) err := c.DeleteLeecher(infohash, p.Key())
if err != nil { if err != nil {
return err return err

View file

@ -35,6 +35,7 @@ type Peer struct {
} }
type PeerList []Peer type PeerList []Peer
type PeerMap map[string]Peer
// NewPeer returns the Peer representation of an Announce. When provided nil // NewPeer returns the Peer representation of an Announce. When provided nil
// for the announce parameter, it panics. When provided nil for the user or // for the announce parameter, it panics. When provided nil for the user or
@ -79,8 +80,8 @@ type Torrent struct {
ID uint64 `json:"id"` ID uint64 `json:"id"`
Infohash string `json:"infohash"` Infohash string `json:"infohash"`
Seeders map[string]Peer `json:"seeders"` Seeders PeerMap `json:"seeders"`
Leechers map[string]Peer `json:"leechers"` Leechers PeerMap `json:"leechers"`
Snatches uint64 `json:"snatches"` Snatches uint64 `json:"snatches"`
UpMultiplier float64 `json:"up_multiplier"` UpMultiplier float64 `json:"up_multiplier"`