]> Sergey Matveev's repositories - btrtrc.git/blobdiff - peer_protocol/extended.go
Drop support for go 1.20
[btrtrc.git] / peer_protocol / extended.go
index a02a96f6b808f475cc6ce11084232fbc1956c4dc..8bc518163394ec8bbf619b135edf055c6f715b87 100644 (file)
@@ -1,20 +1,26 @@
 package peer_protocol
 
+import (
+       "net"
+)
+
 // 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"`
+               M    map[ExtensionName]ExtensionNumber `bencode:"m"`
+               V    string                            `bencode:"v,omitempty"`
+               Reqq int                               `bencode:"reqq,omitempty"`
+               // The only mention of this I can find is in https://www.bittorrent.org/beps/bep_0011.html
+               // for bit 0x01.
+               Encryption bool `bencode:"e"`
                // 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"`
-               Ipv4   [4]byte   `bencode:"ipv4,omitempty"`
-               Ipv6   [16]byte  `bencode:"ipv6,omitempty"`
+               Ipv4   CompactIp `bencode:"ipv4,omitempty"`
+               Ipv6   net.IP    `bencode:"ipv6,omitempty"`
        }
 
        ExtensionName   string
@@ -24,7 +30,11 @@ type (
 const (
        // http://www.bittorrent.org/beps/bep_0011.html
        ExtensionNamePex ExtensionName = "ut_pex"
-       // http://bittorrent.org/beps/bep_0009.html. Note that there's an
-       // LT_metadata, but I've never implemented it.
-       ExtensionNameMetadata = "ut_metadata"
+
+       ExtensionDeleteNumber ExtensionNumber = 0
 )
+
+func (me *ExtensionNumber) UnmarshalBinary(b []byte) error {
+       *me = ExtensionNumber(b[0])
+       return nil
+}