|
|
|
@ -181,19 +181,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)
|
|
|
|
@ -853,11 +858,11 @@ class msg_version():
|
|
|
|
|
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)
|
|
|
|
|
else:
|
|
|
|
@ -885,8 +890,8 @@ class msg_version():
|
|
|
|
|
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)
|
|
|
|
|
r += struct.pack("<i", self.nStartingHeight)
|
|
|
|
|