From 1f750472236f88f62d930e69c741d1be3ea528ba Mon Sep 17 00:00:00 2001 From: bmng-dev Date: Thu, 22 May 2014 16:21:20 +0000 Subject: [PATCH] Refactor generation of packet headers --- src/class_sendDataThread.py | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/class_sendDataThread.py b/src/class_sendDataThread.py index 5aabaeb5..3dfbf12c 100644 --- a/src/class_sendDataThread.py +++ b/src/class_sendDataThread.py @@ -108,13 +108,9 @@ class sendDataThread(threading.Thread): payload += pack('>H', port) payload = encodeVarint(numberOfAddressesInAddrMessage) + payload - datatosend = '\xE9\xBE\xB4\xD9addr\x00\x00\x00\x00\x00\x00\x00\x00' - datatosend = datatosend + pack('>L', len(payload)) # payload length - datatosend = datatosend + hashlib.sha512(payload).digest()[0:4] - datatosend = datatosend + payload - + packet = shared.CreatePacket('addr', payload) try: - self.sock.sendall(datatosend) + self.sock.sendall(packet) self.lastTimeISentData = int(time.time()) except: print 'sendaddr: self.sock.sendall failed' @@ -131,12 +127,9 @@ class sendDataThread(threading.Thread): payload += hash if payload != '': payload = encodeVarint(len(payload)/32) + payload - headerData = '\xe9\xbe\xb4\xd9' # magic bits, slighly different from Bitcoin's magic bits. - headerData += 'inv\x00\x00\x00\x00\x00\x00\x00\x00\x00' - headerData += pack('>L', len(payload)) - headerData += hashlib.sha512(payload).digest()[:4] + packet = shared.CreatePacket('inv', payload) try: - self.sock.sendall(headerData + payload) + self.sock.sendall(packet) self.lastTimeISentData = int(time.time()) except: print 'sendinv: self.sock.sendall failed' @@ -147,10 +140,9 @@ class sendDataThread(threading.Thread): # Send out a pong message to keep the connection alive. with shared.printLock: print 'Sending pong to', self.peer, 'to keep connection alive.' - + packet = shared.CreatePacket('pong') try: - self.sock.sendall( - '\xE9\xBE\xB4\xD9\x70\x6F\x6E\x67\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xcf\x83\xe1\x35') + self.sock.sendall(packet) self.lastTimeISentData = int(time.time()) except: print 'send pong failed'