FedP2P/Peers.go

36 lines
650 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 (
2019-08-10 16:46:07 +08:00
"github.com/anacrolix/dht/v2/krpc"
2019-08-21 18:58:40 +08:00
2018-07-10 09:21:24 +08:00
"github.com/anacrolix/torrent/peer_protocol"
2018-02-19 13:19:18 +08:00
"github.com/anacrolix/torrent/tracker"
)
2018-02-12 21:50:32 +08:00
type Peers []Peer
2018-07-10 09:21:24 +08:00
func (me *Peers) AppendFromPex(nas []krpc.NodeAddr, fs []peer_protocol.PexPeerFlags) {
2018-02-12 21:50:32 +08:00
for i, na := range nas {
var p Peer
2018-07-10 09:21:24 +08:00
var f peer_protocol.PexPeerFlags
2018-02-12 21:50:32 +08:00
if i < len(fs) {
f = fs[i]
}
p.FromPex(na, f)
*me = append(*me, p)
}
}
2018-02-19 13:19:18 +08:00
2018-07-10 09:21:24 +08:00
func (ret Peers) AppendFromTracker(ps []tracker.Peer) Peers {
2018-02-19 13:19:18 +08:00
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
}