forked from anacrolix/torrent
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Peer.go
41 lines (35 loc) · 869 Bytes
/
Peer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package torrent
import (
"net"
"github.com/anacrolix/dht/v2/krpc"
"github.com/scionproto/scion/go/lib/snet"
"github.com/anacrolix/torrent/peer_protocol"
)
type Peer struct {
Id [20]byte
IP net.IP
Port int
Source peerSource
IsScion bool
ScionAddr *snet.UDPAddr
ScionPath *snet.Path
// Peer is known to support encryption.
SupportsEncryption bool
peer_protocol.PexPeerFlags
}
func (me *Peer) FromPex(na krpc.NodeAddr, fs peer_protocol.PexPeerFlags) {
me.IP = append([]byte(nil), na.IP...)
me.Port = na.Port
me.Source = peerSourcePEX
// If they prefer encryption, they must support it.
if fs.Get(peer_protocol.PexPrefersEncryption) {
me.SupportsEncryption = true
}
me.PexPeerFlags = fs
}
func (me Peer) addr() IpPort {
if me.IsScion {
panic("addr() called on scion peer")
}
return IpPort{me.IP, uint16(me.Port)}
}