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