Skip to content

Commit fa404f1

Browse files
author
MarcoFalke
committed
test: Check that the version message does not leak the local address of the node
1 parent 29893ec commit fa404f1

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

test/functional/p2p_leak.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
from test_framework.messages import msg_getaddr, msg_ping, msg_verack
1616
from test_framework.mininode import mininode_lock, P2PInterface
1717
from test_framework.test_framework import BitcoinTestFramework
18-
from test_framework.util import wait_until
18+
from test_framework.util import (
19+
assert_equal,
20+
assert_greater_than_or_equal,
21+
wait_until,
22+
)
1923

2024
banscore = 10
2125

@@ -90,6 +94,14 @@ def on_version(self, message):
9094
self.send_message(msg_getaddr())
9195

9296

97+
class P2PVersionStore(P2PInterface):
98+
version_received = None
99+
100+
def on_version(self, msg):
101+
super().on_version(msg)
102+
self.version_received = msg
103+
104+
93105
class P2PLeakTest(BitcoinTestFramework):
94106
def set_test_params(self):
95107
self.num_nodes = 1
@@ -127,6 +139,18 @@ def run_test(self):
127139
assert no_version_idlenode.unexpected_msg == False
128140
assert no_verack_idlenode.unexpected_msg == False
129141

142+
self.log.info('Check that the version message does not leak the local address of the node')
143+
time_begin = int(time.time())
144+
p2p_version_store = self.nodes[0].add_p2p_connection(P2PVersionStore())
145+
time_end = time.time()
146+
ver = p2p_version_store.version_received
147+
assert_greater_than_or_equal(ver.nTime, time_begin)
148+
assert_greater_than_or_equal(time_end, ver.nTime)
149+
assert_equal(ver.addrFrom.port, 0)
150+
assert_equal(ver.addrFrom.ip, '0.0.0.0')
151+
assert_equal(ver.nStartingHeight, 201)
152+
assert_equal(ver.nRelay, 1)
153+
130154

131155
if __name__ == '__main__':
132156
P2PLeakTest().main()

0 commit comments

Comments
 (0)