URI: 
       tlnbase: fix read_message - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 1f6646fa256516e72b5840d7fe8c746b9a38e1aa
   DIR parent 6a8e5d59549cbc0384686af2cbf416787e6e4494
  HTML Author: ThomasV <thomasv@electrum.org>
       Date:   Tue, 29 May 2018 06:59:22 +0200
       
       lnbase: fix read_message
       
       Diffstat:
         M lib/lnbase.py                       |      28 +++++++++++++---------------
       
       1 file changed, 13 insertions(+), 15 deletions(-)
       ---
   DIR diff --git a/lib/lnbase.py b/lib/lnbase.py
       t@@ -579,6 +579,7 @@ class Peer(PrintError):
                self.network = network
                self.channel_db = channel_db
                self.path_finder = path_finder
       +        self.read_buffer = b''
                self.ping_time = 0
                self.futures = ["channel_accepted",
                    "funding_signed",
       t@@ -623,24 +624,21 @@ class Peer(PrintError):
            async def read_message(self):
                rn_l, rk_l = self.rn()
                rn_m, rk_m = self.rn()
       -        read_buffer = b''
                while True:
       -            s = await self.reader.read(1)
       +            if len(self.read_buffer) >= 18:
       +                lc = self.read_buffer[:18]
       +                l = aead_decrypt(rk_l, rn_l, b'', lc)
       +                length = int.from_bytes(l, 'big')
       +                offset = 18 + length + 16
       +                if len(self.read_buffer) >= offset:
       +                    c = self.read_buffer[18:offset]
       +                    self.read_buffer = self.read_buffer[offset:]
       +                    msg = aead_decrypt(rk_m, rn_m, b'', c)
       +                    return msg
       +            s = await self.reader.read(2**10)
                    if not s:
                        raise LightningPeerConnectionClosed()
       -            read_buffer += s
       -            if len(read_buffer) < 18:
       -                continue
       -            lc = read_buffer[:18]
       -            l = aead_decrypt(rk_l, rn_l, b'', lc)
       -            length = int.from_bytes(l, 'big')
       -            offset = 18 + length + 16
       -            if len(read_buffer) < offset:
       -                continue
       -            c = read_buffer[18:offset]
       -            read_buffer = read_buffer[offset:]
       -            msg = aead_decrypt(rk_m, rn_m, b'', c)
       -            return msg
       +            self.read_buffer += s
        
            async def handshake(self):
                hs = HandshakeState(self.pubkey)