2018-07-10 10:20:36 +08:00
|
|
|
package peer_protocol
|
|
|
|
|
2021-06-18 13:04:07 +08:00
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
)
|
2018-07-11 22:00:07 +08:00
|
|
|
|
2018-07-10 10:20:36 +08:00
|
|
|
// http://www.bittorrent.org/beps/bep_0010.html
|
|
|
|
type (
|
|
|
|
ExtendedHandshakeMessage struct {
|
|
|
|
M map[ExtensionName]ExtensionNumber `bencode:"m"`
|
|
|
|
V string `bencode:"v,omitempty"`
|
|
|
|
Reqq int `bencode:"reqq,omitempty"`
|
|
|
|
Encryption bool `bencode:"e,omitempty"`
|
|
|
|
// BEP 9
|
|
|
|
MetadataSize int `bencode:"metadata_size,omitempty"`
|
|
|
|
// The local client port. It would be redundant for the receiving side of
|
|
|
|
// a connection to send this.
|
|
|
|
Port int `bencode:"p,omitempty"`
|
|
|
|
YourIp CompactIp `bencode:"yourip,omitempty"`
|
2018-07-11 22:00:07 +08:00
|
|
|
Ipv4 CompactIp `bencode:"ipv4,omitempty"`
|
|
|
|
Ipv6 net.IP `bencode:"ipv6,omitempty"`
|
2018-07-10 10:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ExtensionName string
|
|
|
|
ExtensionNumber int
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// http://www.bittorrent.org/beps/bep_0011.html
|
|
|
|
ExtensionNamePex ExtensionName = "ut_pex"
|
2021-06-18 13:04:07 +08:00
|
|
|
|
|
|
|
ExtensionDeleteNumber ExtensionNumber = 0
|
2018-07-10 10:20:36 +08:00
|
|
|
)
|
2021-09-30 07:01:10 +08:00
|
|
|
|
|
|
|
func (me *ExtensionNumber) UnmarshalBinary(b []byte) error {
|
|
|
|
*me = ExtensionNumber(b[0])
|
|
|
|
return nil
|
|
|
|
}
|