6 "github.com/anacrolix/dht/v2/krpc"
8 "github.com/anacrolix/torrent/peer_protocol"
11 // Peer connection info, handed about publicly.
12 type PeerInfo struct {
16 // Peer is known to support encryption.
17 SupportsEncryption bool
18 peer_protocol.PexPeerFlags
19 // Whether we can ignore poor or bad behaviour from the peer.
23 func (me PeerInfo) equal(other PeerInfo) bool {
24 return me.Id == other.Id &&
25 me.Addr.String() == other.Addr.String() &&
26 me.Source == other.Source &&
27 me.SupportsEncryption == other.SupportsEncryption &&
28 me.PexPeerFlags == other.PexPeerFlags &&
29 me.Trusted == other.Trusted
32 // Generate PeerInfo from peer exchange
33 func (me *PeerInfo) FromPex(na krpc.NodeAddr, fs peer_protocol.PexPeerFlags) {
34 me.Addr = ipPortAddr{append([]byte(nil), na.IP...), na.Port}
35 me.Source = PeerSourcePex
36 // If they prefer encryption, they must support it.
37 if fs.Get(peer_protocol.PexPrefersEncryption) {
38 me.SupportsEncryption = true
43 func (me PeerInfo) addr() IpPort {
44 return IpPort{IP: addrIpOrNil(me.Addr), Port: uint16(addrPortOrZero(me.Addr))}