7
7
from test_framework .socks5 import Socks5Configuration , Socks5Command , Socks5Server , AddressType
8
8
from test_framework .test_framework import BitcoinTestFramework
9
9
from test_framework .util import *
10
+ from test_framework .netutil import test_ipv6_local
10
11
'''
11
12
Test plan:
12
13
- Start bitcoind's with different proxy configurations
34
35
35
36
class ProxyTest (BitcoinTestFramework ):
36
37
def __init__ (self ):
38
+ self .have_ipv6 = test_ipv6_local ()
37
39
# Create two proxies on different ports
38
40
# ... one unauthenticated
39
41
self .conf1 = Socks5Configuration ()
@@ -45,29 +47,36 @@ def __init__(self):
45
47
self .conf2 .addr = ('127.0.0.1' , 14000 + (os .getpid () % 1000 ))
46
48
self .conf2 .unauth = True
47
49
self .conf2 .auth = True
48
- # ... one on IPv6 with similar configuration
49
- self .conf3 = Socks5Configuration ()
50
- self .conf3 .af = socket .AF_INET6
51
- self .conf3 .addr = ('::1' , 15000 + (os .getpid () % 1000 ))
52
- self .conf3 .unauth = True
53
- self .conf3 .auth = True
50
+ if self .have_ipv6 :
51
+ # ... one on IPv6 with similar configuration
52
+ self .conf3 = Socks5Configuration ()
53
+ self .conf3 .af = socket .AF_INET6
54
+ self .conf3 .addr = ('::1' , 15000 + (os .getpid () % 1000 ))
55
+ self .conf3 .unauth = True
56
+ self .conf3 .auth = True
57
+ else :
58
+ print "Warning: testing without local IPv6 support"
54
59
55
60
self .serv1 = Socks5Server (self .conf1 )
56
61
self .serv1 .start ()
57
62
self .serv2 = Socks5Server (self .conf2 )
58
63
self .serv2 .start ()
59
- self .serv3 = Socks5Server (self .conf3 )
60
- self .serv3 .start ()
64
+ if self .have_ipv6 :
65
+ self .serv3 = Socks5Server (self .conf3 )
66
+ self .serv3 .start ()
61
67
62
68
def setup_nodes (self ):
63
69
# Note: proxies are not used to connect to local nodes
64
70
# this is because the proxy to use is based on CService.GetNetwork(), which return NET_UNROUTABLE for localhost
65
- return start_nodes ( 4 , self . options . tmpdir , extra_args = [
71
+ args = [
66
72
['-listen' , '-debug=net' , '-debug=proxy' , '-proxy=%s:%i' % (self .conf1 .addr ),'-proxyrandomize=1' ],
67
73
['-listen' , '-debug=net' , '-debug=proxy' , '-proxy=%s:%i' % (self .conf1 .addr ),'-onion=%s:%i' % (self .conf2 .addr ),'-proxyrandomize=0' ],
68
74
['-listen' , '-debug=net' , '-debug=proxy' , '-proxy=%s:%i' % (self .conf2 .addr ),'-proxyrandomize=1' ],
69
- ['-listen' , '-debug=net' , '-debug=proxy' , '-proxy=[%s]:%i' % (self .conf3 .addr ),'-proxyrandomize=0' , '-noonion' ]
70
- ])
75
+ []
76
+ ]
77
+ if self .have_ipv6 :
78
+ args [3 ] = ['-listen' , '-debug=net' , '-debug=proxy' , '-proxy=[%s]:%i' % (self .conf3 .addr ),'-proxyrandomize=0' , '-noonion' ]
79
+ return start_nodes (4 , self .options .tmpdir , extra_args = args )
71
80
72
81
def node_test (self , node , proxies , auth , test_onion = True ):
73
82
rv = []
@@ -84,18 +93,19 @@ def node_test(self, node, proxies, auth, test_onion=True):
84
93
assert_equal (cmd .password , None )
85
94
rv .append (cmd )
86
95
87
- # Test: outgoing IPv6 connection through node
88
- node .addnode ("[1233:3432:2434:2343:3234:2345:6546:4534]:5443" , "onetry" )
89
- cmd = proxies [1 ].queue .get ()
90
- assert (isinstance (cmd , Socks5Command ))
91
- # Note: bitcoind's SOCKS5 implementation only sends atyp DOMAINNAME, even if connecting directly to IPv4/IPv6
92
- assert_equal (cmd .atyp , AddressType .DOMAINNAME )
93
- assert_equal (cmd .addr , "1233:3432:2434:2343:3234:2345:6546:4534" )
94
- assert_equal (cmd .port , 5443 )
95
- if not auth :
96
- assert_equal (cmd .username , None )
97
- assert_equal (cmd .password , None )
98
- rv .append (cmd )
96
+ if self .have_ipv6 :
97
+ # Test: outgoing IPv6 connection through node
98
+ node .addnode ("[1233:3432:2434:2343:3234:2345:6546:4534]:5443" , "onetry" )
99
+ cmd = proxies [1 ].queue .get ()
100
+ assert (isinstance (cmd , Socks5Command ))
101
+ # Note: bitcoind's SOCKS5 implementation only sends atyp DOMAINNAME, even if connecting directly to IPv4/IPv6
102
+ assert_equal (cmd .atyp , AddressType .DOMAINNAME )
103
+ assert_equal (cmd .addr , "1233:3432:2434:2343:3234:2345:6546:4534" )
104
+ assert_equal (cmd .port , 5443 )
105
+ if not auth :
106
+ assert_equal (cmd .username , None )
107
+ assert_equal (cmd .password , None )
108
+ rv .append (cmd )
99
109
100
110
if test_onion :
101
111
# Test: outgoing onion connection through node
@@ -135,10 +145,11 @@ def run_test(self):
135
145
rv = self .node_test (self .nodes [2 ], [self .serv2 , self .serv2 , self .serv2 , self .serv2 ], True )
136
146
# Check that credentials as used for -proxyrandomize connections are unique
137
147
credentials = set ((x .username ,x .password ) for x in rv )
138
- assert_equal (len (credentials ), 4 )
148
+ assert_equal (len (credentials ), len ( rv ) )
139
149
140
- # proxy on IPv6 localhost
141
- self .node_test (self .nodes [3 ], [self .serv3 , self .serv3 , self .serv3 , self .serv3 ], False , False )
150
+ if self .have_ipv6 :
151
+ # proxy on IPv6 localhost
152
+ self .node_test (self .nodes [3 ], [self .serv3 , self .serv3 , self .serv3 , self .serv3 ], False , False )
142
153
143
154
def networks_dict (d ):
144
155
r = {}
@@ -167,11 +178,12 @@ def networks_dict(d):
167
178
assert_equal (n2 [net ]['proxy_randomize_credentials' ], True )
168
179
assert_equal (n2 ['onion' ]['reachable' ], True )
169
180
170
- n3 = networks_dict (self .nodes [3 ].getnetworkinfo ())
171
- for net in ['ipv4' ,'ipv6' ]:
172
- assert_equal (n3 [net ]['proxy' ], '[%s]:%i' % (self .conf3 .addr ))
173
- assert_equal (n3 [net ]['proxy_randomize_credentials' ], False )
174
- assert_equal (n3 ['onion' ]['reachable' ], False )
181
+ if self .have_ipv6 :
182
+ n3 = networks_dict (self .nodes [3 ].getnetworkinfo ())
183
+ for net in ['ipv4' ,'ipv6' ]:
184
+ assert_equal (n3 [net ]['proxy' ], '[%s]:%i' % (self .conf3 .addr ))
185
+ assert_equal (n3 [net ]['proxy_randomize_credentials' ], False )
186
+ assert_equal (n3 ['onion' ]['reachable' ], False )
175
187
176
188
if __name__ == '__main__' :
177
189
ProxyTest ().main ()
0 commit comments