]> Sergey Matveev's repositories - btrtrc.git/blob - peer_protocol/extended.go
Attempt holepunch after initial dial fails
[btrtrc.git] / peer_protocol / extended.go
1 package peer_protocol
2
3 import (
4         "net"
5 )
6
7 // http://www.bittorrent.org/beps/bep_0010.html
8 type (
9         ExtendedHandshakeMessage struct {
10                 M    map[ExtensionName]ExtensionNumber `bencode:"m"`
11                 V    string                            `bencode:"v,omitempty"`
12                 Reqq int                               `bencode:"reqq,omitempty"`
13                 // The only mention of this I can find is in https://www.bittorrent.org/beps/bep_0011.html
14                 // for bit 0x01.
15                 Encryption bool `bencode:"e"`
16                 // BEP 9
17                 MetadataSize int `bencode:"metadata_size,omitempty"`
18                 // The local client port. It would be redundant for the receiving side of
19                 // a connection to send this.
20                 Port   int       `bencode:"p,omitempty"`
21                 YourIp CompactIp `bencode:"yourip,omitempty"`
22                 Ipv4   CompactIp `bencode:"ipv4,omitempty"`
23                 Ipv6   net.IP    `bencode:"ipv6,omitempty"`
24         }
25
26         ExtensionName   string
27         ExtensionNumber int
28 )
29
30 const (
31         // http://www.bittorrent.org/beps/bep_0011.html
32         ExtensionNamePex ExtensionName = "ut_pex"
33
34         ExtensionDeleteNumber ExtensionNumber = 0
35 )
36
37 func (me *ExtensionNumber) UnmarshalBinary(b []byte) error {
38         *me = ExtensionNumber(b[0])
39         return nil
40 }