Skip to content

Commit 2252bda

Browse files
committed
connectd: gate uniform message padding behind --dev-uniform-padding
Uniform padding (sending all messages as 1460-byte chunks) breaks peers running LND-based nodes: LND disconnects on receiving a ping(num_pong_bytes=65535) with "pong bytes exceeded" instead of ignoring it as required by BOLT #1. Gate the feature behind --dev-uniform-padding so it is opt-in rather than forced on all connections. Nodes that only peer with CLN can enable it for the traffic analysis defence. Changelog-Changed: uniform message padding is now opt-in via the --dev-uniform-padding flag.
1 parent f844eb0 commit 2252bda

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

connectd/multiplex.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,10 +484,16 @@ static bool have_empty_encrypted_queue(const struct peer *peer)
484484
/* (Continue) writing the encrypted_peer_out array */
485485
static struct io_plan *write_encrypted_to_peer(struct peer *peer)
486486
{
487-
assert(membuf_num_elems(&peer->encrypted_peer_out) >= UNIFORM_MESSAGE_SIZE);
487+
size_t avail = membuf_num_elems(&peer->encrypted_peer_out);
488+
/* With padding: always a full uniform-size chunk.
489+
* Without: flush whatever we have (caller ensures non-zero). */
490+
size_t write_size = peer->daemon->dev_uniform_padding
491+
? UNIFORM_MESSAGE_SIZE : avail;
492+
493+
assert(avail >= write_size && write_size > 0);
488494
return io_write_partial(peer->to_peer,
489495
membuf_elems(&peer->encrypted_peer_out),
490-
UNIFORM_MESSAGE_SIZE,
496+
write_size,
491497
&peer->encrypted_peer_out_sent,
492498
write_to_peer, peer);
493499
}
@@ -1244,8 +1250,11 @@ static struct io_plan *write_to_peer(struct io_conn *peer_conn,
12441250
/* Wait for them to wake us */
12451251
return msg_queue_wait(peer_conn, peer->peer_outq, write_to_peer, peer);
12461252
}
1247-
/* OK, add padding. */
1248-
pad_encrypted_queue(peer);
1253+
/* OK, add padding (only if --dev-uniform-padding enabled). */
1254+
if (peer->daemon->dev_uniform_padding)
1255+
pad_encrypted_queue(peer);
1256+
else
1257+
break;
12491258
} else {
12501259
if (peer->draining_state == WRITING_TO_PEER)
12511260
status_peer_debug(&peer->id, "draining, but sending %s.",
@@ -1263,6 +1272,14 @@ static struct io_plan *write_to_peer(struct io_conn *peer_conn,
12631272
}
12641273

12651274
peer->nonurgent_flush_timer = tal_free(peer->nonurgent_flush_timer);
1275+
1276+
/* With uniform padding the buffer is always a full UNIFORM_MESSAGE_SIZE.
1277+
* Without it, write whatever we have; if nothing, go back to waiting. */
1278+
if (have_empty_encrypted_queue(peer)) {
1279+
io_wake(&peer->subds);
1280+
io_wake(&peer->peer_in);
1281+
return msg_queue_wait(peer_conn, peer->peer_outq, write_to_peer, peer);
1282+
}
12661283
return write_encrypted_to_peer(peer);
12671284
}
12681285

0 commit comments

Comments
 (0)