Browse Source

lnbase: fix read_message, reduce verbosity

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

12
lib/lnbase.py

@ -330,6 +330,8 @@ class Peer(PrintError):
self.writer.write(lc+c) self.writer.write(lc+c)
async def read_message(self): async def read_message(self):
rn_l = self.rn()
rn_m = self.rn()
while True: while True:
s = await self.reader.read(2**10) s = await self.reader.read(2**10)
if not s: if not s:
@ -338,14 +340,14 @@ class Peer(PrintError):
if len(self.read_buffer) < 18: if len(self.read_buffer) < 18:
continue continue
lc = self.read_buffer[:18] lc = self.read_buffer[:18]
l = aead_decrypt(self.rk, self.rn(), b'', lc) l = aead_decrypt(self.rk, rn_l, b'', lc)
length = int.from_bytes(l, byteorder="big") length = int.from_bytes(l, byteorder="big")
offset = 18 + length + 16 offset = 18 + length + 16
if len(self.read_buffer) < offset: if len(self.read_buffer) < offset:
continue continue
c = self.read_buffer[18:offset] c = self.read_buffer[18:offset]
self.read_buffer = self.read_buffer[offset:] self.read_buffer = self.read_buffer[offset:]
msg = aead_decrypt(self.rk, self.rn(), b'', c) msg = aead_decrypt(self.rk, rn_m, b'', c)
return msg return msg
async def handshake(self): async def handshake(self):
@ -400,10 +402,10 @@ class Peer(PrintError):
def process_message(self, message): def process_message(self, message):
message_type, payload = decode_msg(message) message_type, payload = decode_msg(message)
self.print_error("Received '%s'" % message_type.upper(), payload)
try: try:
f = getattr(self, 'on_' + message_type) f = getattr(self, 'on_' + message_type)
except AttributeError: except AttributeError:
self.print_error("Received '%s'" % message_type.upper(), payload)
return return
# raw message is needed to check signature # raw message is needed to check signature
if message_type=='node_announcement': if message_type=='node_announcement':
@ -467,10 +469,10 @@ class Peer(PrintError):
pass pass
def on_channel_update(self, payload): def on_channel_update(self, payload):
pass self.print_error('channel update')
def on_channel_announcement(self, payload): def on_channel_announcement(self, payload):
pass self.print_error('channel announcement')
#def open_channel(self, funding_sat, push_msat): #def open_channel(self, funding_sat, push_msat):
# self.send_message(gen_msg('open_channel', funding_satoshis=funding_sat, push_msat=push_msat)) # self.send_message(gen_msg('open_channel', funding_satoshis=funding_sat, push_msat=push_msat))

Loading…
Cancel
Save