Skip to content

Commit 910dbcf

Browse files
committed
Drop buffered messages for timed out nodes
OnionMessenger buffers onion messages for nodes that are pending a connection. To prevent DoS concerns, drop the buffered messages if the node has not connected within one timer tick, which should correspond to 10 seconds for PeerManager when using lightning-background-processor.
1 parent 076c626 commit 910dbcf

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lightning/src/onion_message/messenger.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,19 @@ where
797797
}
798798

799799
fn release_pending_connections(&self) -> Vec<NodeAnnouncement> {
800-
self.message_buffers.lock().unwrap()
800+
let mut message_buffers = self.message_buffers.lock().unwrap();
801+
802+
// Drop any pending recipients since the last call to avoid retaining buffered messages for
803+
// too long.
804+
message_buffers.retain(|_, recipient| match recipient {
805+
OnionMessageBuffer::PendingConnection(_, None) => false,
806+
OnionMessageBuffer::PendingConnection(_, Some(_)) => true,
807+
_ => true,
808+
});
809+
810+
// Release node announcements for pending recipients so that their buffered messages are
811+
// dropped the next time this method is called.
812+
message_buffers
801813
.values_mut()
802814
.filter_map(|recipient| match recipient {
803815
OnionMessageBuffer::PendingConnection(_, node_announcement) => {

0 commit comments

Comments
 (0)