3636 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
3737 }
3838
39+ torV3IpBytes = []byte {
40+ 0xb8 , 0x39 , 0x1d , 0x20 , 0x03 , 0xbb , 0x3b , 0xd2 ,
41+ 0x85 , 0xb0 , 0x35 , 0xac , 0x8e , 0xb3 , 0x0c , 0x80 ,
42+ 0xc4 , 0xe2 , 0xa2 , 0x9b , 0xb7 , 0xa2 , 0xf0 , 0xce ,
43+ 0x0d , 0xf8 , 0x74 , 0x3c , 0x37 , 0xec , 0x35 , 0x93 ,
44+ }
45+
3946 serializedIPv4NetAddressBytes = []byte {
4047 0x29 , 0xab , 0x5f , 0x49 , 0x00 , 0x00 , 0x00 , 0x00 , // Timestamp
4148 0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , // Services
@@ -60,12 +67,24 @@ var (
6067 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
6168 0x8f , 0x20 ,
6269 }
70+
71+ serializedTORv3NetAddressBytes = []byte {
72+ 0x29 , 0xab , 0x5f , 0x49 , 0x00 , 0x00 , 0x00 , 0x00 ,
73+ 0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
74+ 0x04 ,
75+ 0xb8 , 0x39 , 0x1d , 0x20 , 0x03 , 0xbb , 0x3b , 0xd2 ,
76+ 0x85 , 0xb0 , 0x35 , 0xac , 0x8e , 0xb3 , 0x0c , 0x80 ,
77+ 0xc4 , 0xe2 , 0xa2 , 0x9b , 0xb7 , 0xa2 , 0xf0 , 0xce ,
78+ 0x0d , 0xf8 , 0x74 , 0x3c , 0x37 , 0xec , 0x35 , 0x93 ,
79+ 0x90 , 0x20 ,
80+ }
6381)
6482
6583var (
6684 ipv4Address = newNetAddressV2 (IPv4Address , ipv4IpBytes , 8333 )
6785 ipv6Address = newNetAddressV2 (IPv6Address , ipv6IpBytes , 8334 )
6886 torv2Address = newNetAddressV2 (TORv2Address , torV2IpBytes , 8335 )
87+ torv3Address = newNetAddressV2 (TORv3Address , torV3IpBytes , 8336 )
6988)
7089
7190// TestMaxPayloadLength verifies the maximum payload length equals the expected
@@ -84,10 +103,14 @@ func TestMaxPayloadLength(t *testing.T) {
84103 name : "protocol version 10" ,
85104 pver : AddrV2Version ,
86105 want : 35003 ,
106+ }, {
107+ name : "protocol version 11" ,
108+ pver : RelayTORv3Version ,
109+ want : 51003 ,
87110 }, {
88111 name : "latest protocol version" ,
89112 pver : ProtocolVersion ,
90- want : 35003 ,
113+ want : 51003 ,
91114 }}
92115
93116 for _ , test := range tests {
@@ -179,12 +202,14 @@ func TestAddrV2Wire(t *testing.T) {
179202 ipv4Address ,
180203 ipv6Address ,
181204 torv2Address ,
205+ torv3Address ,
182206 },
183207 wantBytes : bytes .Join ([][]byte {
184- {0x03 },
208+ {0x04 },
185209 serializedIPv4NetAddressBytes ,
186210 serializedIPv6NetAddressBytes ,
187211 serializedTORv2NetAddressBytes ,
212+ serializedTORv3NetAddressBytes ,
188213 }, []byte {}),
189214 }}
190215
@@ -230,6 +255,7 @@ func TestAddrV2WireErrors(t *testing.T) {
230255 pver := ProtocolVersion
231256 na := ipv4Address
232257 addrs := []* NetAddressV2 {na }
258+ addrv2 := NewMsgAddrV2 ()
233259
234260 tests := []struct {
235261 name string
@@ -285,6 +311,14 @@ func TestAddrV2WireErrors(t *testing.T) {
285311 ioLimit : 3 ,
286312 writeErr : ErrTooManyAddrs ,
287313 readErr : ErrTooManyAddrs ,
314+ }, {
315+ name : "torv3 address invalid on protocol version 10" ,
316+ pver : RelayTORv3Version - 1 ,
317+ addrs : []* NetAddressV2 {torv3Address },
318+ bytes : []byte {0x01 },
319+ ioLimit : int (addrv2 .MaxPayloadLength (RelayTORv3Version - 1 )),
320+ writeErr : ErrInvalidMsg ,
321+ readErr : ErrInvalidMsg ,
288322 }}
289323
290324 t .Logf ("Running %d tests" , len (tests ))
0 commit comments