Clean up types more
This commit is contained in:
parent
9dde295b7c
commit
67a8473f6e
4 changed files with 12 additions and 11 deletions
|
@ -95,8 +95,8 @@ func loadTestData(tkr *tracker.Tracker) error {
|
|||
torrent := &models.Torrent{
|
||||
ID: 1,
|
||||
Infohash: infoHash,
|
||||
Seeders: make(map[string]models.Peer),
|
||||
Leechers: make(map[string]models.Peer),
|
||||
Seeders: models.PeerMap{},
|
||||
Leechers: models.PeerMap{},
|
||||
}
|
||||
|
||||
return conn.PutTorrent(torrent)
|
||||
|
|
|
@ -41,8 +41,8 @@ func (t *Tracker) HandleAnnounce(ann *models.Announce, w Writer) error {
|
|||
case !t.cfg.Private && err == ErrTorrentDNE:
|
||||
torrent = &models.Torrent{
|
||||
Infohash: ann.Infohash,
|
||||
Seeders: make(map[string]models.Peer),
|
||||
Leechers: make(map[string]models.Peer),
|
||||
Seeders: models.PeerMap{},
|
||||
Leechers: models.PeerMap{},
|
||||
}
|
||||
|
||||
err = conn.PutTorrent(torrent)
|
||||
|
@ -149,7 +149,7 @@ func handleEvent(c Conn, ann *models.Announce, p *models.Peer, u *models.User, t
|
|||
t.Snatches++
|
||||
|
||||
if t.InLeecherPool(p) {
|
||||
err = LeecherFinished(c, t.Infohash, p)
|
||||
err = leecherFinished(c, t.Infohash, p)
|
||||
if err != nil {
|
||||
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:
|
||||
// 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
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
for _, peer := range peers {
|
||||
|
|
|
@ -93,8 +93,8 @@ type Conn interface {
|
|||
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 {
|
||||
// leecherFinished moves a peer from the leeching pool to the seeder pool.
|
||||
func leecherFinished(c Conn, infohash string, p *models.Peer) error {
|
||||
err := c.DeleteLeecher(infohash, p.Key())
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -35,6 +35,7 @@ type Peer struct {
|
|||
}
|
||||
|
||||
type PeerList []Peer
|
||||
type PeerMap map[string]Peer
|
||||
|
||||
// NewPeer returns the Peer representation of an Announce. When provided nil
|
||||
// for the announce parameter, it panics. When provided nil for the user or
|
||||
|
@ -79,8 +80,8 @@ type Torrent struct {
|
|||
ID uint64 `json:"id"`
|
||||
Infohash string `json:"infohash"`
|
||||
|
||||
Seeders map[string]Peer `json:"seeders"`
|
||||
Leechers map[string]Peer `json:"leechers"`
|
||||
Seeders PeerMap `json:"seeders"`
|
||||
Leechers PeerMap `json:"leechers"`
|
||||
|
||||
Snatches uint64 `json:"snatches"`
|
||||
UpMultiplier float64 `json:"up_multiplier"`
|
||||
|
|
Loading…
Reference in a new issue