Skip to content

Commit 44d290d

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 cfe3410 commit 44d290d

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
@@ -866,6 +866,16 @@ where
866866
self.message_buffers.lock().unwrap().remove(their_node_id);
867867
}
868868

869+
fn timer_tick_occurred(&self) {
870+
// Drop any pending recipients since the last call to avoid retaining buffered messages for
871+
// too long.
872+
self.message_buffers.lock().unwrap().retain(|_, recipient| match recipient {
873+
OnionMessageBuffer::PendingConnection(_, None) => false,
874+
OnionMessageBuffer::PendingConnection(_, Some(_)) => true,
875+
_ => true,
876+
});
877+
}
878+
869879
fn provided_node_features(&self) -> NodeFeatures {
870880
let mut features = NodeFeatures::empty();
871881
features.set_onion_messages_optional();

0 commit comments

Comments
 (0)