Skip to content

Commit 33eb6e4

Browse files
SomberNightf321x
andcommitted
lnpeer: on_ping: drain out-socket buffer
might help against some memory exhaustion attacks f321x said: > maybe a peer could just fill up our sockets outgoing buffer by ~234mb/h > if they stop reading from their socket and keep sending pings every second. Co-authored-by: f321x <f@f321x.com>
1 parent 7625efb commit 33eb6e4

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

electrum/lnpeer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,8 @@ async def on_ping(self, payload):
385385
await asyncio.sleep(min_delay - elapsed_since_last)
386386
self._last_ping_recv_time = time.monotonic()
387387
l = payload['num_pong_bytes']
388-
self.send_message('pong', byteslen=l)
388+
raw_msg = encode_msg('pong', byteslen=l)
389+
await self.transport.send_bytes_and_drain(raw_msg)
389390

390391
def on_pong(self, payload):
391392
self.pong_event.set()

tests/lnhelpers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ def __init__(self, keypair, name):
214214
def send_bytes(self, data):
215215
self.other_mock_transport.queue.put_nowait(data)
216216

217+
async def send_bytes_and_drain(self, data):
218+
self.send_bytes(data)
219+
220+
217221
def transport_pair(k1, k2, name1, name2):
218222
t1 = PutIntoOthersQueueTransport(k1, name1)
219223
t2 = PutIntoOthersQueueTransport(k2, name2)

0 commit comments

Comments
 (0)