-
-
Notifications
You must be signed in to change notification settings - Fork 613
/
peer_infos.go
35 lines (30 loc) · 725 Bytes
/
peer_infos.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package torrent
import (
"github.com/anacrolix/dht/v2/krpc"
"github.com/anacrolix/torrent/peer_protocol"
"github.com/anacrolix/torrent/tracker"
)
// Helper-type used to bulk-manage PeerInfos.
type peerInfos []PeerInfo
func (me *peerInfos) AppendFromPex(nas []krpc.NodeAddr, fs []peer_protocol.PexPeerFlags) {
for i, na := range nas {
var p PeerInfo
var f peer_protocol.PexPeerFlags
if i < len(fs) {
f = fs[i]
}
p.FromPex(na, f)
*me = append(*me, p)
}
}
func (ret peerInfos) AppendFromTracker(ps []tracker.Peer) peerInfos {
for _, p := range ps {
_p := PeerInfo{
Addr: ipPortAddr{p.IP, p.Port},
Source: PeerSourceTracker,
}
copy(_p.Id[:], p.ID)
ret = append(ret, _p)
}
return ret
}