Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/mininode.py
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | |||||
# from version 70001 onwards, fRelay should be appended to version messages (BIP37) | # from version 70001 onwards, fRelay should be appended to version messages (BIP37) | ||||
MY_RELAY = 1 | MY_RELAY = 1 | ||||
MAX_INV_SZ = 50000 | MAX_INV_SZ = 50000 | ||||
COIN = 100000000 # 1 btc in satoshis | COIN = 100000000 # 1 btc in satoshis | ||||
NODE_NETWORK = (1 << 0) | NODE_NETWORK = (1 << 0) | ||||
NODE_GETUTXO = (1 << 1) | # NODE_GETUTXO = (1 << 1) | ||||
NODE_BLOOM = (1 << 2) | # NODE_BLOOM = (1 << 2) | ||||
NODE_WITNESS = (1 << 3) | NODE_WITNESS = (1 << 3) | ||||
NODE_XTHIN = (1 << 4) | NODE_XTHIN = (1 << 4) | ||||
NODE_BITCOIN_CASH = (1 << 5) | NODE_BITCOIN_CASH = (1 << 5) | ||||
# Howmuch data will be read from the network at once | # Howmuch data will be read from the network at once | ||||
READ_BUFFER_SIZE = 8192 | READ_BUFFER_SIZE = 8192 | ||||
logger = logging.getLogger("TestFramework.mininode") | logger = logging.getLogger("TestFramework.mininode") | ||||
▲ Show 20 Lines • Show All 790 Lines • ▼ Show 20 Lines | def deserialize(self, f): | ||||
self.addrs = deser_vector(f, CAddress) | self.addrs = deser_vector(f, CAddress) | ||||
def serialize(self): | def serialize(self): | ||||
return ser_vector(self.addrs) | return ser_vector(self.addrs) | ||||
def __repr__(self): | def __repr__(self): | ||||
return "msg_addr(addrs=%s)" % (repr(self.addrs)) | return "msg_addr(addrs=%s)" % (repr(self.addrs)) | ||||
class msg_inv(): | class msg_inv(): | ||||
command = b"inv" | command = b"inv" | ||||
def __init__(self, inv=None): | def __init__(self, inv=None): | ||||
if inv is None: | if inv is None: | ||||
self.inv = [] | self.inv = [] | ||||
else: | else: | ||||
self.inv = inv | self.inv = inv | ||||
▲ Show 20 Lines • Show All 393 Lines • ▼ Show 20 Lines | def __init__(self): | ||||
# A count of the number of ping messages we've sent to the node | # A count of the number of ping messages we've sent to the node | ||||
self.ping_counter = 1 | self.ping_counter = 1 | ||||
# deliver_sleep_time is helpful for debugging race conditions in p2p | # deliver_sleep_time is helpful for debugging race conditions in p2p | ||||
# tests; it causes message delivery to sleep for the specified time | # tests; it causes message delivery to sleep for the specified time | ||||
# before acquiring the global lock and delivering the next message. | # before acquiring the global lock and delivering the next message. | ||||
self.deliver_sleep_time = None | self.deliver_sleep_time = None | ||||
# Remember the services our peer has advertised | |||||
self.peer_services = None | |||||
# Message receiving methods | # Message receiving methods | ||||
def deliver(self, conn, message): | def deliver(self, conn, message): | ||||
"""Receive message and dispatch message to appropriate callback. | """Receive message and dispatch message to appropriate callback. | ||||
We keep a count of how many of each message type has been received | We keep a count of how many of each message type has been received | ||||
and the most recent message of each type. | and the most recent message of each type. | ||||
Show All 9 Lines | def deliver(self, conn, message): | ||||
self.message_count[command] += 1 | self.message_count[command] += 1 | ||||
self.last_message[command] = message | self.last_message[command] = message | ||||
getattr(self, 'on_' + command)(conn, message) | getattr(self, 'on_' + command)(conn, message) | ||||
except: | except: | ||||
print("ERROR delivering %s (%s)" % (repr(message), | print("ERROR delivering %s (%s)" % (repr(message), | ||||
sys.exc_info()[0])) | sys.exc_info()[0])) | ||||
raise | raise | ||||
def set_deliver_sleep_time(self, value): | |||||
with mininode_lock: | |||||
self.deliver_sleep_time = value | |||||
def get_deliver_sleep_time(self): | def get_deliver_sleep_time(self): | ||||
with mininode_lock: | with mininode_lock: | ||||
return self.deliver_sleep_time | return self.deliver_sleep_time | ||||
# Callback methods. Can be overridden by subclasses in individual test | # Callback methods. Can be overridden by subclasses in individual test | ||||
# cases to provide custom message handling behaviour. | # cases to provide custom message handling behaviour. | ||||
def on_open(self, conn): | def on_open(self, conn): | ||||
▲ Show 20 Lines • Show All 375 Lines • Show Last 20 Lines |