]> Sergey Matveev's repositories - btrtrc.git/blob - Peer.go
goimports -local
[btrtrc.git] / Peer.go
1 package torrent
2
3 import (
4         "net"
5
6         "github.com/anacrolix/dht/v2/krpc"
7
8         "github.com/anacrolix/torrent/peer_protocol"
9 )
10
11 type Peer struct {
12         Id     [20]byte
13         IP     net.IP
14         Port   int
15         Source peerSource
16         // Peer is known to support encryption.
17         SupportsEncryption bool
18         peer_protocol.PexPeerFlags
19 }
20
21 func (me *Peer) FromPex(na krpc.NodeAddr, fs peer_protocol.PexPeerFlags) {
22         me.IP = append([]byte(nil), na.IP...)
23         me.Port = na.Port
24         me.Source = peerSourcePEX
25         // If they prefer encryption, they must support it.
26         if fs.Get(peer_protocol.PexPrefersEncryption) {
27                 me.SupportsEncryption = true
28         }
29         me.PexPeerFlags = fs
30 }
31
32 func (me Peer) addr() IpPort {
33         return IpPort{me.IP, uint16(me.Port)}
34 }