Skip to content

Commit

Permalink
[QA] fix mininode CAddress ser/deser
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasschnelli authored and furszy committed Aug 10, 2021
1 parent cec9567 commit d496b64
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions test/functional/test_framework/messages.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,24 @@ def ToHex(obj):

class CAddress():
def __init__(self):
self.time = 0
self.nServices = 1
self.pchReserved = b"\x00" * 10 + b"\xff" * 2
self.ip = "0.0.0.0"
self.port = 0

def deserialize(self, f):
def deserialize(self, f, with_time=True):
if with_time:
self.time = struct.unpack("<i", f.read(4))[0]
self.nServices = struct.unpack("<Q", f.read(8))[0]
self.pchReserved = f.read(12)
self.ip = socket.inet_ntoa(f.read(4))
self.port = struct.unpack(">H", f.read(2))[0]

def serialize(self):
def serialize(self, with_time=True):
r = b""
if with_time:
r += struct.pack("<i", self.time)
r += struct.pack("<Q", self.nServices)
r += self.pchReserved
r += socket.inet_aton(self.ip)
Expand Down Expand Up @@ -923,11 +928,11 @@ def deserialize(self, f):
self.nServices = struct.unpack("<Q", f.read(8))[0]
self.nTime = struct.unpack("<q", f.read(8))[0]
self.addrTo = CAddress()
self.addrTo.deserialize(f)
self.addrTo.deserialize(f, False)

if self.nVersion >= 106:
self.addrFrom = CAddress()
self.addrFrom.deserialize(f)
self.addrFrom.deserialize(f, False)
self.nNonce = struct.unpack("<Q", f.read(8))[0]
self.strSubVer = deser_string(f).decode('utf-8')
else:
Expand Down Expand Up @@ -955,8 +960,8 @@ def serialize(self):
r += struct.pack("<i", self.nVersion)
r += struct.pack("<Q", self.nServices)
r += struct.pack("<q", self.nTime)
r += self.addrTo.serialize()
r += self.addrFrom.serialize()
r += self.addrTo.serialize(False)
r += self.addrFrom.serialize(False)
r += struct.pack("<Q", self.nNonce)
r += ser_string(self.strSubVer.encode('utf-8'))
r += struct.pack("<i", self.nStartingHeight)
Expand Down

0 comments on commit d496b64

Please sign in to comment.