Skip to content

Commit b01d740

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, add a timer_tick_occurred method to OnionMessageHandler so that buffered messages can be dropped. This will be called in lightning-background-processor every 10 seconds.
1 parent d9e2a66 commit b01d740

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

lightning/src/ln/msgs.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,6 +1580,9 @@ pub trait OnionMessageHandler: EventsProvider {
15801580
/// drop and refuse to forward onion messages to this peer.
15811581
fn peer_disconnected(&self, their_node_id: &PublicKey);
15821582

1583+
/// Performs actions that should happen on startup and roughly every ten seconds thereafter.
1584+
fn timer_tick_occurred(&self);
1585+
15831586
// Handler information:
15841587
/// Gets the node feature flags which this handler itself supports. All available handlers are
15851588
/// queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]

lightning/src/ln/peer_handler.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ impl OnionMessageHandler for IgnoringMessageHandler {
118118
fn next_onion_message_for_peer(&self, _peer_node_id: PublicKey) -> Option<msgs::OnionMessage> { None }
119119
fn peer_connected(&self, _their_node_id: &PublicKey, _init: &msgs::Init, _inbound: bool) -> Result<(), ()> { Ok(()) }
120120
fn peer_disconnected(&self, _their_node_id: &PublicKey) {}
121+
fn timer_tick_occurred(&self) {}
121122
fn provided_node_features(&self) -> NodeFeatures { NodeFeatures::empty() }
122123
fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures {
123124
InitFeatures::empty()

lightning/src/onion_message/messenger.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,16 @@ where
871871
self.message_buffers.lock().unwrap().remove(their_node_id);
872872
}
873873

874+
fn timer_tick_occurred(&self) {
875+
// Drop any pending recipients since the last call to avoid retaining buffered messages for
876+
// too long.
877+
self.message_buffers.lock().unwrap().retain(|_, recipient| match recipient {
878+
OnionMessageBuffer::PendingConnection(_, None) => false,
879+
OnionMessageBuffer::PendingConnection(_, Some(_)) => true,
880+
_ => true,
881+
});
882+
}
883+
874884
fn provided_node_features(&self) -> NodeFeatures {
875885
let mut features = NodeFeatures::empty();
876886
features.set_onion_messages_optional();

0 commit comments

Comments
 (0)