Browse Source

lnbase: save buffer for next read

dependabot/pip/contrib/deterministic-build/ecdsa-0.13.3
ThomasV 7 years ago
parent
commit
bcb268d554
  1. 13
      lib/lnbase.py

13
lib/lnbase.py

@ -234,6 +234,7 @@ class Peer(PrintError):
self.port = port self.port = port
self.privkey = privkey self.privkey = privkey
self.pubkey = pubkey self.pubkey = pubkey
self.read_buffer = b''
def send_message(self, msg): def send_message(self, msg):
print("Sending %d bytes: "%len(msg), binascii.hexlify(msg)) print("Sending %d bytes: "%len(msg), binascii.hexlify(msg))
@ -246,16 +247,16 @@ class Peer(PrintError):
self.sn += 2 self.sn += 2
async def read_message(self): async def read_message(self):
rspns = b''
while True: while True:
rspns += await self.reader.read(2**10) self.read_buffer += await self.reader.read(2**10)
print("buffer %d bytes:"%len(rspns), binascii.hexlify(rspns)) lc = self.read_buffer[:18]
lc = rspns[:18]
l = aead_decrypt(self.rk, self.rn, b'', lc) l = aead_decrypt(self.rk, self.rn, b'', lc)
length = decode(l) length = decode(l)
if len(rspns) < 18 + length + 16: offset = 18 + length + 16
if len(self.read_buffer) < offset:
continue continue
c = rspns[18:18 + length + 16] c = self.read_buffer[18:offset]
self.read_buffer = self.read_buffer[offset:]
msg = aead_decrypt(self.rk, self.rn+1, b'', c) msg = aead_decrypt(self.rk, self.rn+1, b'', c)
self.rn += 2 self.rn += 2
return msg return msg

Loading…
Cancel
Save