mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-01 16:31:33 +01:00
[test] Move MY_SUBVERSION to p2p.py
The messages.py module should contain code and helpers for [de]serializing p2p messages. Specific usage of those messages should be in p2p.py. Therefore move MY_SUBVERSION to p2p.py. Also rename to P2P_SUBVERSION.
This commit is contained in:
@@ -21,6 +21,7 @@ from test_framework.messages import (
|
|||||||
)
|
)
|
||||||
from test_framework.p2p import (
|
from test_framework.p2p import (
|
||||||
P2PInterface,
|
P2PInterface,
|
||||||
|
P2P_SUBVERSION,
|
||||||
P2P_VERSION,
|
P2P_VERSION,
|
||||||
p2p_lock,
|
p2p_lock,
|
||||||
)
|
)
|
||||||
@@ -223,6 +224,7 @@ class FilterTest(BitcoinTestFramework):
|
|||||||
# Send version with fRelay=False
|
# Send version with fRelay=False
|
||||||
version_without_fRelay = msg_version()
|
version_without_fRelay = msg_version()
|
||||||
version_without_fRelay.nVersion = P2P_VERSION
|
version_without_fRelay.nVersion = P2P_VERSION
|
||||||
|
version_without_fRelay.strSubVer = P2P_SUBVERSION
|
||||||
version_without_fRelay.nRelay = 0
|
version_without_fRelay.nRelay = 0
|
||||||
filter_peer_without_nrelay.send_message(version_without_fRelay)
|
filter_peer_without_nrelay.send_message(version_without_fRelay)
|
||||||
filter_peer_without_nrelay.wait_for_verack()
|
filter_peer_without_nrelay.wait_for_verack()
|
||||||
|
|||||||
@@ -17,7 +17,10 @@ from test_framework.messages import (
|
|||||||
msg_ping,
|
msg_ping,
|
||||||
msg_version,
|
msg_version,
|
||||||
)
|
)
|
||||||
from test_framework.p2p import P2PInterface
|
from test_framework.p2p import (
|
||||||
|
P2PInterface,
|
||||||
|
P2P_SUBVERSION,
|
||||||
|
)
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import (
|
from test_framework.util import (
|
||||||
assert_equal,
|
assert_equal,
|
||||||
@@ -131,6 +134,7 @@ class P2PLeakTest(BitcoinTestFramework):
|
|||||||
p2p_old_peer = self.nodes[0].add_p2p_connection(P2PInterface(), send_version=False, wait_for_verack=False)
|
p2p_old_peer = self.nodes[0].add_p2p_connection(P2PInterface(), send_version=False, wait_for_verack=False)
|
||||||
old_version_msg = msg_version()
|
old_version_msg = msg_version()
|
||||||
old_version_msg.nVersion = 31799
|
old_version_msg.nVersion = 31799
|
||||||
|
old_version_msg.strSubVer = P2P_SUBVERSION
|
||||||
with self.nodes[0].assert_debug_log(['peer=3 using obsolete version 31799; disconnecting']):
|
with self.nodes[0].assert_debug_log(['peer=3 using obsolete version 31799; disconnecting']):
|
||||||
p2p_old_peer.send_message(old_version_msg)
|
p2p_old_peer.send_message(old_version_msg)
|
||||||
p2p_old_peer.wait_for_disconnect()
|
p2p_old_peer.wait_for_disconnect()
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ import time
|
|||||||
from test_framework.siphash import siphash256
|
from test_framework.siphash import siphash256
|
||||||
from test_framework.util import hex_str_to_bytes, assert_equal
|
from test_framework.util import hex_str_to_bytes, assert_equal
|
||||||
|
|
||||||
MY_SUBVERSION = "/python-p2p-tester:0.0.3/"
|
|
||||||
MY_RELAY = 1 # from version 70001 onwards, fRelay should be appended to version messages (BIP37)
|
MY_RELAY = 1 # from version 70001 onwards, fRelay should be appended to version messages (BIP37)
|
||||||
|
|
||||||
MAX_LOCATOR_SZ = 101
|
MAX_LOCATOR_SZ = 101
|
||||||
@@ -1030,7 +1029,7 @@ class msg_version:
|
|||||||
self.addrTo = CAddress()
|
self.addrTo = CAddress()
|
||||||
self.addrFrom = CAddress()
|
self.addrFrom = CAddress()
|
||||||
self.nNonce = random.getrandbits(64)
|
self.nNonce = random.getrandbits(64)
|
||||||
self.strSubVer = MY_SUBVERSION
|
self.strSubVer = ''
|
||||||
self.nStartingHeight = -1
|
self.nStartingHeight = -1
|
||||||
self.nRelay = MY_RELAY
|
self.nRelay = MY_RELAY
|
||||||
|
|
||||||
|
|||||||
@@ -83,6 +83,8 @@ MIN_P2P_VERSION_SUPPORTED = 60001
|
|||||||
# The P2P version that this test framework implements and sends in its `version` message
|
# The P2P version that this test framework implements and sends in its `version` message
|
||||||
# Version 70016 supports wtxid relay
|
# Version 70016 supports wtxid relay
|
||||||
P2P_VERSION = 70016
|
P2P_VERSION = 70016
|
||||||
|
# The P2P user agent string that this test framework sends in its `version` message
|
||||||
|
P2P_SUBVERSION = "/python-p2p-tester:0.0.3/"
|
||||||
|
|
||||||
MESSAGEMAP = {
|
MESSAGEMAP = {
|
||||||
b"addr": msg_addr,
|
b"addr": msg_addr,
|
||||||
@@ -333,6 +335,7 @@ class P2PInterface(P2PConnection):
|
|||||||
# Send a version msg
|
# Send a version msg
|
||||||
vt = msg_version()
|
vt = msg_version()
|
||||||
vt.nVersion = P2P_VERSION
|
vt.nVersion = P2P_VERSION
|
||||||
|
vt.strSubVer = P2P_SUBVERSION
|
||||||
vt.nServices = services
|
vt.nServices = services
|
||||||
vt.addrTo.ip = self.dstaddr
|
vt.addrTo.ip = self.dstaddr
|
||||||
vt.addrTo.port = self.dstport
|
vt.addrTo.port = self.dstport
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import sys
|
|||||||
|
|
||||||
from .authproxy import JSONRPCException
|
from .authproxy import JSONRPCException
|
||||||
from .descriptors import descsum_create
|
from .descriptors import descsum_create
|
||||||
from .messages import MY_SUBVERSION
|
from .p2p import P2P_SUBVERSION
|
||||||
from .util import (
|
from .util import (
|
||||||
MAX_NODES,
|
MAX_NODES,
|
||||||
append_config,
|
append_config,
|
||||||
@@ -572,7 +572,7 @@ class TestNode():
|
|||||||
|
|
||||||
def num_test_p2p_connections(self):
|
def num_test_p2p_connections(self):
|
||||||
"""Return number of test framework p2p connections to the node."""
|
"""Return number of test framework p2p connections to the node."""
|
||||||
return len([peer for peer in self.getpeerinfo() if peer['subver'] == MY_SUBVERSION])
|
return len([peer for peer in self.getpeerinfo() if peer['subver'] == P2P_SUBVERSION])
|
||||||
|
|
||||||
def disconnect_p2ps(self):
|
def disconnect_p2ps(self):
|
||||||
"""Close all p2p connections to the node."""
|
"""Close all p2p connections to the node."""
|
||||||
|
|||||||
Reference in New Issue
Block a user