From f4834def9d304002642cc1907432d2053519857d Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Thu, 25 Aug 2022 14:30:29 -0400 Subject: [PATCH] Implement buffering onion messages for peers. In this commit, we check if a peer's outbound buffer has room for onion messages, and if so pulls them from an implementer of a new trait, OnionMessageProvider. Makes sure channel messages are prioritized over OMs, and OMs are prioritized over gossip. The onion_message module remains private until further rate limiting is added. --- lightning/src/ln/peer_handler.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 6da0bae27..1258026e1 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -411,6 +411,13 @@ impl Peer { && self.msgs_sent_since_pong < BUFFER_DRAIN_MSGS_PER_TICK } + /// Determines if we should push an onion message onto a peer's outbound buffer. This is checked + /// every time the peer's buffer may have been drained. + fn should_buffer_onion_message(&self) -> bool { + self.pending_outbound_buffer.is_empty() + && self.msgs_sent_since_pong < BUFFER_DRAIN_MSGS_PER_TICK + } + /// Determines if we should push additional gossip broadcast messages onto a peer's outbound /// buffer. This is checked every time the peer's buffer may have been drained. fn should_buffer_gossip_broadcast(&self) -> bool { @@ -766,6 +773,14 @@ impl