Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/messages.py
Show First 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | |||||
NODE_COMPACT_FILTERS = (1 << 6) | NODE_COMPACT_FILTERS = (1 << 6) | ||||
NODE_NETWORK_LIMITED = (1 << 10) | NODE_NETWORK_LIMITED = (1 << 10) | ||||
NODE_AVALANCHE = (1 << 24) | NODE_AVALANCHE = (1 << 24) | ||||
MSG_TX = 1 | MSG_TX = 1 | ||||
MSG_BLOCK = 2 | MSG_BLOCK = 2 | ||||
MSG_FILTERED_BLOCK = 3 | MSG_FILTERED_BLOCK = 3 | ||||
MSG_CMPCT_BLOCK = 4 | MSG_CMPCT_BLOCK = 4 | ||||
MSG_AVALANCHE_PROOF = 5 | |||||
MSG_TYPE_MASK = 0xffffffff >> 2 | MSG_TYPE_MASK = 0xffffffff >> 2 | ||||
FILTER_TYPE_BASIC = 0 | FILTER_TYPE_BASIC = 0 | ||||
# Serialization/deserialization tools | # Serialization/deserialization tools | ||||
def sha256(s): | def sha256(s): | ||||
▲ Show 20 Lines • Show All 223 Lines • ▼ Show 20 Lines | |||||
class CInv: | class CInv: | ||||
__slots__ = ("hash", "type") | __slots__ = ("hash", "type") | ||||
typemap = { | typemap = { | ||||
0: "Error", | 0: "Error", | ||||
MSG_TX: "TX", | MSG_TX: "TX", | ||||
MSG_BLOCK: "Block", | MSG_BLOCK: "Block", | ||||
MSG_FILTERED_BLOCK: "filtered Block", | MSG_FILTERED_BLOCK: "filtered Block", | ||||
MSG_CMPCT_BLOCK: "CompactBlock" | MSG_CMPCT_BLOCK: "CompactBlock", | ||||
MSG_AVALANCHE_PROOF: "avalanche proof", | |||||
} | } | ||||
def __init__(self, t=0, h=0): | def __init__(self, t=0, h=0): | ||||
self.type = t | self.type = t | ||||
self.hash = h | self.hash = h | ||||
def deserialize(self, f): | def deserialize(self, f): | ||||
self.type = struct.unpack("<i", f.read(4))[0] | self.type = struct.unpack("<i", f.read(4))[0] | ||||
▲ Show 20 Lines • Show All 533 Lines • ▼ Show 20 Lines | def serialize(self): | ||||
r += ser_vector(self.invs) | r += ser_vector(self.invs) | ||||
return r | return r | ||||
def __repr__(self): | def __repr__(self): | ||||
return "AvalanchePoll(round={}, invs={})".format( | return "AvalanchePoll(round={}, invs={})".format( | ||||
self.round, repr(self.invs)) | self.round, repr(self.invs)) | ||||
# TODO: implement the Proof with all its attributes | |||||
class AvalancheProof: | |||||
__slots__ = ("blob") | |||||
def __init__(self, blob: bytes = b""): | |||||
self.blob: bytes = blob | |||||
def deserialize(self, f): | |||||
self.blob = f.read() | |||||
def serialize(self): | |||||
r = b"" | |||||
r += self.blob | |||||
return r | |||||
def __repr__(self): | |||||
return "AvalancheProof({})".format(self.serialize().hex()) | |||||
class AvalancheVote(): | class AvalancheVote(): | ||||
__slots__ = ("error", "hash") | __slots__ = ("error", "hash") | ||||
def __init__(self, e=0, h=0): | def __init__(self, e=0, h=0): | ||||
self.error = e | self.error = e | ||||
self.hash = h | self.hash = h | ||||
def deserialize(self, f): | def deserialize(self, f): | ||||
▲ Show 20 Lines • Show All 951 Lines • ▼ Show 20 Lines | def serialize(self): | ||||
r = b"" | r = b"" | ||||
r += self.poll.serialize() | r += self.poll.serialize() | ||||
return r | return r | ||||
def __repr__(self): | def __repr__(self): | ||||
return "msg_avapoll(poll={})".format(repr(self.poll)) | return "msg_avapoll(poll={})".format(repr(self.poll)) | ||||
class msg_avaproof(): | |||||
__slots__ = ("proof",) | |||||
msgtype = b"avaproof" | |||||
def __init__(self): | |||||
self.proof = AvalancheProof() | |||||
def deserialize(self, f): | |||||
self.proof.deserialize(f) | |||||
def serialize(self): | |||||
r = b"" | |||||
r += self.proof.serialize() | |||||
return r | |||||
def __repr__(self): | |||||
return "msg_avaproof(proof={})".format(repr(self.proof)) | |||||
class msg_avaresponse(): | class msg_avaresponse(): | ||||
__slots__ = ("response",) | __slots__ = ("response",) | ||||
msgtype = b"avaresponse" | msgtype = b"avaresponse" | ||||
def __init__(self): | def __init__(self): | ||||
self.response = AvalancheResponse() | self.response = AvalancheResponse() | ||||
def deserialize(self, f): | def deserialize(self, f): | ||||
▲ Show 20 Lines • Show All 47 Lines • Show Last 20 Lines |