mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
Merge bitcoin#18584: test: Check that the version message does not leak the local address (#4368)
* Backporting Merge #18584: test: Check that the version message does not leak the local address
fa404f1e4718e8155581f23826480086dfbcfaa6 test: Check that the version message does not leak the local address of the node (MarcoFalke)
Pull request description:
Add test for #8740
ACKs for top commit:
theStack:
ACK fa404f1e47
Tree-SHA512: 4d1c10d1c02fba4b51bd8b9eb3a0d9a682b6aac8c3f6924e295fdca3faefa5ecc3eaa87d347cfec5d2b2bc49963c10fe0a37c463f36088ed0304a2e3716b963b
* Merge #18584: test: Check that the version message does not leak the local address
Co-authored-by: MarcoFalke <falke.marco@gmail.com>
This commit is contained in:
parent
f38aa44bfd
commit
e60b249883
@ -16,7 +16,11 @@ import time
|
|||||||
from test_framework.messages import msg_getaddr, msg_ping, msg_verack
|
from test_framework.messages import msg_getaddr, msg_ping, msg_verack
|
||||||
from test_framework.mininode import mininode_lock, P2PInterface
|
from test_framework.mininode import mininode_lock, P2PInterface
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import wait_until
|
from test_framework.util import (
|
||||||
|
assert_equal,
|
||||||
|
assert_greater_than_or_equal,
|
||||||
|
wait_until,
|
||||||
|
)
|
||||||
|
|
||||||
banscore = 10
|
banscore = 10
|
||||||
|
|
||||||
@ -88,11 +92,24 @@ class CNodeNoVerackIdle(CLazyNode):
|
|||||||
self.send_message(msg_ping())
|
self.send_message(msg_ping())
|
||||||
self.send_message(msg_getaddr())
|
self.send_message(msg_getaddr())
|
||||||
|
|
||||||
|
|
||||||
|
class P2PVersionStore(P2PInterface):
|
||||||
|
version_received = None
|
||||||
|
|
||||||
|
def on_version(self, msg):
|
||||||
|
super().on_version(msg)
|
||||||
|
self.version_received = msg
|
||||||
|
|
||||||
|
|
||||||
class P2PLeakTest(BitcoinTestFramework):
|
class P2PLeakTest(BitcoinTestFramework):
|
||||||
def set_test_params(self):
|
def set_test_params(self):
|
||||||
self.num_nodes = 1
|
self.num_nodes = 1
|
||||||
self.extra_args = [['-banscore=' + str(banscore)]]
|
self.extra_args = [['-banscore=' + str(banscore)]]
|
||||||
|
|
||||||
|
def setup_network(self):
|
||||||
|
self.disable_mocktime()
|
||||||
|
self.setup_nodes()
|
||||||
|
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
no_version_bannode = self.nodes[0].add_p2p_connection(CNodeNoVersionBan(), send_version=False, wait_for_verack=False)
|
no_version_bannode = self.nodes[0].add_p2p_connection(CNodeNoVersionBan(), send_version=False, wait_for_verack=False)
|
||||||
no_version_idlenode = self.nodes[0].add_p2p_connection(CNodeNoVersionIdle(), send_version=False, wait_for_verack=False)
|
no_version_idlenode = self.nodes[0].add_p2p_connection(CNodeNoVersionIdle(), send_version=False, wait_for_verack=False)
|
||||||
@ -121,6 +138,18 @@ class P2PLeakTest(BitcoinTestFramework):
|
|||||||
assert(no_version_idlenode.unexpected_msg == False)
|
assert(no_version_idlenode.unexpected_msg == False)
|
||||||
assert(no_verack_idlenode.unexpected_msg == False)
|
assert(no_verack_idlenode.unexpected_msg == False)
|
||||||
|
|
||||||
|
self.log.info('Check that the version message does not leak the local address of the node')
|
||||||
|
time_begin = int(time.time())
|
||||||
|
p2p_version_store = self.nodes[0].add_p2p_connection(P2PVersionStore())
|
||||||
|
time_end = time.time()
|
||||||
|
ver = p2p_version_store.version_received
|
||||||
|
assert_greater_than_or_equal(ver.nTime, time_begin)
|
||||||
|
assert_greater_than_or_equal(time_end, ver.nTime)
|
||||||
|
assert_equal(ver.addrFrom.port, 0)
|
||||||
|
assert_equal(ver.addrFrom.ip, '0.0.0.0')
|
||||||
|
assert_equal(ver.nStartingHeight, 201)
|
||||||
|
assert_equal(ver.nRelay, 1)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
P2PLeakTest().main()
|
P2PLeakTest().main()
|
||||||
|
Loading…
Reference in New Issue
Block a user