Browse Source
lnworker: (fix) a listening node would busy-loop if remote DC-ed early
StreamReader.read() returns b'' on EOF, resulting in a busy loop
patch-4
SomberNight
4 years ago
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
2 changed files with
10 additions and
4 deletions
-
electrum/lntransport.py
-
electrum/lnworker.py
|
|
@ -172,7 +172,10 @@ class LNResponderTransport(LNTransportBase): |
|
|
|
hs = HandshakeState(privkey_to_pubkey(self.privkey)) |
|
|
|
act1 = b'' |
|
|
|
while len(act1) < 50: |
|
|
|
act1 += await self.reader.read(50 - len(act1)) |
|
|
|
buf = await self.reader.read(50 - len(act1)) |
|
|
|
if not buf: |
|
|
|
raise HandshakeFailed('responder disconnected') |
|
|
|
act1 += buf |
|
|
|
if len(act1) != 50: |
|
|
|
raise HandshakeFailed('responder: short act 1 read, length is ' + str(len(act1))) |
|
|
|
if bytes([act1[0]]) != HandshakeState.handshake_version: |
|
|
@ -200,7 +203,10 @@ class LNResponderTransport(LNTransportBase): |
|
|
|
# act 3 |
|
|
|
act3 = b'' |
|
|
|
while len(act3) < 66: |
|
|
|
act3 += await self.reader.read(66 - len(act3)) |
|
|
|
buf = await self.reader.read(66 - len(act3)) |
|
|
|
if not buf: |
|
|
|
raise HandshakeFailed('responder disconnected') |
|
|
|
act3 += buf |
|
|
|
if len(act3) != 66: |
|
|
|
raise HandshakeFailed('responder: short act 3 read, length is ' + str(len(act3))) |
|
|
|
if bytes([act3[0]]) != HandshakeState.handshake_version: |
|
|
|
|
|
@ -193,8 +193,8 @@ class LNWorker(Logger, NetworkRetryManager[LNPeerAddr]): |
|
|
|
transport = LNResponderTransport(self.node_keypair.privkey, reader, writer) |
|
|
|
try: |
|
|
|
node_id = await transport.handshake() |
|
|
|
except: |
|
|
|
self.logger.info('handshake failure from incoming connection') |
|
|
|
except Exception as e: |
|
|
|
self.logger.info(f'handshake failure from incoming connection: {e!r}') |
|
|
|
return |
|
|
|
peer = Peer(self, node_id, transport) |
|
|
|
with self.lock: |
|
|
|