4 "github.com/anacrolix/dht/v2/krpc"
6 "github.com/anacrolix/torrent/peer_protocol"
9 // Peer connection info, handed about publicly.
10 type PeerInfo struct {
14 // Peer is known to support encryption.
15 SupportsEncryption bool
16 peer_protocol.PexPeerFlags
17 // Whether we can ignore poor or bad behaviour from the peer.
21 func (me PeerInfo) equal(other PeerInfo) bool {
22 return me.Id == other.Id &&
23 me.Addr.String() == other.Addr.String() &&
24 me.Source == other.Source &&
25 me.SupportsEncryption == other.SupportsEncryption &&
26 me.PexPeerFlags == other.PexPeerFlags &&
27 me.Trusted == other.Trusted
30 // Generate PeerInfo from peer exchange
31 func (me *PeerInfo) FromPex(na krpc.NodeAddr, fs peer_protocol.PexPeerFlags) {
32 me.Addr = ipPortAddr{append([]byte(nil), na.IP...), na.Port}
33 me.Source = PeerSourcePex
34 // If they prefer encryption, they must support it.
35 if fs.Get(peer_protocol.PexPrefersEncryption) {
36 me.SupportsEncryption = true
41 func (me PeerInfo) addr() IpPort {
42 ipPort, _ := tryIpPortFromNetAddr(me.Addr)
43 return IpPort{ipPort.IP, uint16(ipPort.Port)}