18
18
- proxy on IPv6
19
19
20
20
- Create various proxies (as threads)
21
- - Create bitcoinds that connect to them
22
- - Manipulate the bitcoinds using addnode (onetry) an observe effects
21
+ - Create nodes that connect to them
22
+ - Manipulate the peer connections using addnode (onetry) and observe effects
23
+ - Test the getpeerinfo `network` field for the peer
23
24
24
25
addnode connect to IPv4
25
26
addnode connect to IPv6
40
41
from test_framework .netutil import test_ipv6_local
41
42
42
43
RANGE_BEGIN = PORT_MIN + 2 * PORT_RANGE # Start after p2p and rpc ports
44
+ # From GetNetworkName() in netbase.cpp:
45
+ NET_UNROUTABLE = ""
46
+ NET_IPV4 = "ipv4"
47
+ NET_IPV6 = "ipv6"
48
+ NET_ONION = "onion"
49
+
43
50
44
51
class ProxyTest (BitcoinTestFramework ):
45
52
def set_test_params (self ):
@@ -90,10 +97,16 @@ def setup_nodes(self):
90
97
self .add_nodes (self .num_nodes , extra_args = args )
91
98
self .start_nodes ()
92
99
100
+ def network_test (self , node , addr , network ):
101
+ for peer in node .getpeerinfo ():
102
+ if peer ["addr" ] == addr :
103
+ assert_equal (peer ["network" ], network )
104
+
93
105
def node_test (self , node , proxies , auth , test_onion = True ):
94
106
rv = []
95
- # Test: outgoing IPv4 connection through node
96
- node .addnode ("15.61.23.23:1234" , "onetry" )
107
+ addr = "15.61.23.23:1234"
108
+ self .log .debug ("Test: outgoing IPv4 connection through node for address {}" .format (addr ))
109
+ node .addnode (addr , "onetry" )
97
110
cmd = proxies [0 ].queue .get ()
98
111
assert isinstance (cmd , Socks5Command )
99
112
# Note: bitcoind's SOCKS5 implementation only sends atyp DOMAINNAME, even if connecting directly to IPv4/IPv6
@@ -104,10 +117,12 @@ def node_test(self, node, proxies, auth, test_onion=True):
104
117
assert_equal (cmd .username , None )
105
118
assert_equal (cmd .password , None )
106
119
rv .append (cmd )
120
+ self .network_test (node , addr , network = NET_IPV4 )
107
121
108
122
if self .have_ipv6 :
109
- # Test: outgoing IPv6 connection through node
110
- node .addnode ("[1233:3432:2434:2343:3234:2345:6546:4534]:5443" , "onetry" )
123
+ addr = "[1233:3432:2434:2343:3234:2345:6546:4534]:5443"
124
+ self .log .debug ("Test: outgoing IPv6 connection through node for address {}" .format (addr ))
125
+ node .addnode (addr , "onetry" )
111
126
cmd = proxies [1 ].queue .get ()
112
127
assert isinstance (cmd , Socks5Command )
113
128
# Note: bitcoind's SOCKS5 implementation only sends atyp DOMAINNAME, even if connecting directly to IPv4/IPv6
@@ -118,10 +133,12 @@ def node_test(self, node, proxies, auth, test_onion=True):
118
133
assert_equal (cmd .username , None )
119
134
assert_equal (cmd .password , None )
120
135
rv .append (cmd )
136
+ self .network_test (node , addr , network = NET_IPV6 )
121
137
122
138
if test_onion :
123
- # Test: outgoing onion connection through node
124
- node .addnode ("bitcoinostk4e4re.onion:8333" , "onetry" )
139
+ addr = "bitcoinostk4e4re.onion:8333"
140
+ self .log .debug ("Test: outgoing onion connection through node for address {}" .format (addr ))
141
+ node .addnode (addr , "onetry" )
125
142
cmd = proxies [2 ].queue .get ()
126
143
assert isinstance (cmd , Socks5Command )
127
144
assert_equal (cmd .atyp , AddressType .DOMAINNAME )
@@ -131,9 +148,11 @@ def node_test(self, node, proxies, auth, test_onion=True):
131
148
assert_equal (cmd .username , None )
132
149
assert_equal (cmd .password , None )
133
150
rv .append (cmd )
151
+ self .network_test (node , addr , network = NET_ONION )
134
152
135
- # Test: outgoing DNS name connection through node
136
- node .addnode ("node.noumenon:8333" , "onetry" )
153
+ addr = "node.noumenon:8333"
154
+ self .log .debug ("Test: outgoing DNS name connection through node for address {}" .format (addr ))
155
+ node .addnode (addr , "onetry" )
137
156
cmd = proxies [3 ].queue .get ()
138
157
assert isinstance (cmd , Socks5Command )
139
158
assert_equal (cmd .atyp , AddressType .DOMAINNAME )
@@ -143,6 +162,7 @@ def node_test(self, node, proxies, auth, test_onion=True):
143
162
assert_equal (cmd .username , None )
144
163
assert_equal (cmd .password , None )
145
164
rv .append (cmd )
165
+ self .network_test (node , addr , network = NET_UNROUTABLE )
146
166
147
167
return rv
148
168
@@ -197,5 +217,6 @@ def networks_dict(d):
197
217
assert_equal (n3 [net ]['proxy_randomize_credentials' ], False )
198
218
assert_equal (n3 ['onion' ]['reachable' ], False )
199
219
220
+
200
221
if __name__ == '__main__' :
201
222
ProxyTest ().main ()
0 commit comments