2018-02-12 13:50:32 +00:00
|
|
|
package torrent
|
|
|
|
|
2018-02-19 05:19:18 +00:00
|
|
|
import (
|
2019-08-10 08:46:07 +00:00
|
|
|
"github.com/anacrolix/dht/v2/krpc"
|
2019-08-21 10:58:40 +00:00
|
|
|
|
2018-07-10 01:21:24 +00:00
|
|
|
"github.com/anacrolix/torrent/peer_protocol"
|
2018-02-19 05:19:18 +00:00
|
|
|
"github.com/anacrolix/torrent/tracker"
|
|
|
|
)
|
2018-02-12 13:50:32 +00:00
|
|
|
|
2020-05-29 09:44:48 +00:00
|
|
|
// Helper-type used to bulk-manage PeerInfos.
|
|
|
|
type peerInfos []PeerInfo
|
2018-02-12 13:50:32 +00:00
|
|
|
|
2020-05-29 09:44:48 +00:00
|
|
|
func (me *peerInfos) AppendFromPex(nas []krpc.NodeAddr, fs []peer_protocol.PexPeerFlags) {
|
2018-02-12 13:50:32 +00:00
|
|
|
for i, na := range nas {
|
2020-05-29 09:44:48 +00:00
|
|
|
var p PeerInfo
|
2018-07-10 01:21:24 +00:00
|
|
|
var f peer_protocol.PexPeerFlags
|
2018-02-12 13:50:32 +00:00
|
|
|
if i < len(fs) {
|
|
|
|
f = fs[i]
|
|
|
|
}
|
|
|
|
p.FromPex(na, f)
|
|
|
|
*me = append(*me, p)
|
|
|
|
}
|
|
|
|
}
|
2018-02-19 05:19:18 +00:00
|
|
|
|
2020-05-29 09:44:48 +00:00
|
|
|
func (ret peerInfos) AppendFromTracker(ps []tracker.Peer) peerInfos {
|
2018-02-19 05:19:18 +00:00
|
|
|
for _, p := range ps {
|
2020-05-29 09:44:48 +00:00
|
|
|
_p := PeerInfo{
|
2020-02-20 05:47:37 +00:00
|
|
|
Addr: ipPortAddr{p.IP, p.Port},
|
2020-02-21 00:07:50 +00:00
|
|
|
Source: PeerSourceTracker,
|
2018-02-19 05:19:18 +00:00
|
|
|
}
|
|
|
|
copy(_p.Id[:], p.ID)
|
|
|
|
ret = append(ret, _p)
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|