From: Valentine Wallace Date: Thu, 25 Aug 2022 18:30:29 +0000 (-0400) Subject: Implement buffering onion messages for peers. X-Git-Tag: v0.0.111~23^2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=f4834def9d304002642cc1907432d2053519857d;p=rust-lightning 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. --- diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 6da0bae2..1258026e 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