FedP2P/Peers.go

34 lines
560 B
Go
Raw Normal View History

2018-02-12 21:50:32 +08:00
package torrent
2018-02-19 13:19:18 +08:00
import (
"github.com/anacrolix/dht/krpc"
"github.com/anacrolix/torrent/tracker"
)
2018-02-12 21:50:32 +08:00
type Peers []Peer
func (me *Peers) FromPex(nas []krpc.NodeAddr, fs []pexPeerFlags) {
for i, na := range nas {
var p Peer
var f pexPeerFlags
if i < len(fs) {
f = fs[i]
}
p.FromPex(na, f)
*me = append(*me, p)
}
}
2018-02-19 13:19:18 +08:00
func (ret Peers) FromTracker(ps []tracker.Peer) Peers {
for _, p := range ps {
_p := Peer{
IP: p.IP,
Port: p.Port,
Source: peerSourceTracker,
}
copy(_p.Id[:], p.ID)
ret = append(ret, _p)
}
return ret
}