2015-08-17 17:52:47 +08:00
|
|
|
package torrent
|
|
|
|
|
2018-02-11 12:13:00 +08:00
|
|
|
import "github.com/anacrolix/dht/krpc"
|
2015-08-17 17:52:47 +08:00
|
|
|
|
|
|
|
type peerExchangeMessage struct {
|
2018-02-11 12:13:00 +08:00
|
|
|
Added krpc.CompactIPv4NodeAddrs `bencode:"added"`
|
|
|
|
AddedFlags []pexPeerFlags `bencode:"added.f"`
|
|
|
|
Added6 krpc.CompactIPv6NodeAddrs `bencode:"added6"`
|
2018-02-12 21:50:32 +08:00
|
|
|
Added6Flags []pexPeerFlags `bencode:"added6.f"`
|
2018-02-11 12:13:00 +08:00
|
|
|
Dropped krpc.CompactIPv4NodeAddrs `bencode:"dropped"`
|
|
|
|
Dropped6 krpc.CompactIPv6NodeAddrs `bencode:"dropped6"`
|
2015-08-17 17:52:47 +08:00
|
|
|
}
|
2018-02-11 12:13:00 +08:00
|
|
|
|
|
|
|
type pexPeerFlags byte
|
|
|
|
|
2018-02-12 21:50:32 +08:00
|
|
|
func (me pexPeerFlags) Get(f pexPeerFlags) bool {
|
|
|
|
return me&f == f
|
|
|
|
}
|
|
|
|
|
2018-02-11 12:13:00 +08:00
|
|
|
const (
|
|
|
|
pexPrefersEncryption = 0x01
|
|
|
|
pexSeedUploadOnly = 0x02
|
|
|
|
pexSupportsUtp = 0x04
|
|
|
|
pexHolepunchSupport = 0x08
|
|
|
|
pexOutgoingConn = 0x10
|
|
|
|
)
|
2018-02-12 21:50:32 +08:00
|
|
|
|
|
|
|
func (me *peerExchangeMessage) AddedPeers() (ret Peers) {
|
|
|
|
ret.FromPex(me.Added, me.AddedFlags)
|
|
|
|
ret.FromPex(me.Added6, me.Added6Flags)
|
|
|
|
return
|
|
|
|
}
|