From 129dd30c453c9c7b1e1981b626bcdba71a009ed3 Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Sun, 25 Jun 2023 14:26:17 -0500 Subject: [PATCH] Define a default MessageRouter implementation Otherwise, users need to define one when using "Simple" type aliases. --- lightning-background-processor/src/lib.rs | 3 +-- lightning/src/ln/peer_handler.rs | 8 ++++---- lightning/src/onion_message/messenger.rs | 19 +++++++++++++++---- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/lightning-background-processor/src/lib.rs b/lightning-background-processor/src/lib.rs index 401c3c19e..517e693de 100644 --- a/lightning-background-processor/src/lib.rs +++ b/lightning-background-processor/src/lib.rs @@ -519,9 +519,8 @@ use core::task; /// # type MyUtxoLookup = dyn lightning::routing::utxo::UtxoLookup + Send + Sync; /// # type MyFilter = dyn lightning::chain::Filter + Send + Sync; /// # type MyLogger = dyn lightning::util::logger::Logger + Send + Sync; -/// # type MyMessageRouter = dyn lightning::onion_message::MessageRouter + Send + Sync; /// # type MyChainMonitor = lightning::chain::chainmonitor::ChainMonitor, Arc, Arc, Arc, Arc>; -/// # type MyPeerManager = lightning::ln::peer_handler::SimpleArcPeerManager; +/// # type MyPeerManager = lightning::ln::peer_handler::SimpleArcPeerManager; /// # type MyNetworkGraph = lightning::routing::gossip::NetworkGraph>; /// # type MyGossipSync = lightning::routing::gossip::P2PGossipSync, Arc, Arc>; /// # type MyChannelManager = lightning::ln::channelmanager::SimpleArcChannelManager; diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 931e8c4e4..60230af78 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -607,11 +607,11 @@ impl Peer { /// issues such as overly long function definitions. /// /// This is not exported to bindings users as `Arc`s don't make sense in bindings. -pub type SimpleArcPeerManager = PeerManager< +pub type SimpleArcPeerManager = PeerManager< SD, Arc>, Arc>>, Arc, Arc>>, - Arc>, + Arc>, Arc, IgnoringMessageHandler, Arc @@ -626,12 +626,12 @@ pub type SimpleArcPeerManager = PeerManager< /// /// This is not exported to bindings users as general type aliases don't make sense in bindings. pub type SimpleRefPeerManager< - 'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, 'i, 'j, 'k, 'l, 'm, 'n, SD, M, T, F, C, L, R + 'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, 'i, 'j, 'k, 'l, 'm, 'n, SD, M, T, F, C, L > = PeerManager< SD, &'n SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'm, M, T, F, L>, &'f P2PGossipSync<&'g NetworkGraph<&'f L>, &'h C, &'f L>, - &'i SimpleRefOnionMessenger<'g, 'm, 'n, L, R>, + &'i SimpleRefOnionMessenger<'g, 'm, 'n, L>, &'f L, IgnoringMessageHandler, &'c KeysManager diff --git a/lightning/src/onion_message/messenger.rs b/lightning/src/onion_message/messenger.rs index 2c3cf4307..a3613605c 100644 --- a/lightning/src/onion_message/messenger.rs +++ b/lightning/src/onion_message/messenger.rs @@ -152,6 +152,17 @@ pub trait MessageRouter { ) -> Result; } +/// A [`MessageRouter`] that always fails. +pub struct DefaultMessageRouter; + +impl MessageRouter for DefaultMessageRouter { + fn find_path( + &self, _sender: PublicKey, _peers: Vec, _destination: Destination + ) -> Result { + Err(()) + } +} + /// A path for sending an [`msgs::OnionMessage`]. #[derive(Clone)] pub struct OnionMessagePath { @@ -598,11 +609,11 @@ where /// /// [`SimpleArcChannelManager`]: crate::ln::channelmanager::SimpleArcChannelManager /// [`SimpleArcPeerManager`]: crate::ln::peer_handler::SimpleArcPeerManager -pub type SimpleArcOnionMessenger = OnionMessenger< +pub type SimpleArcOnionMessenger = OnionMessenger< Arc, Arc, Arc, - Arc, + Arc, IgnoringMessageHandler, IgnoringMessageHandler >; @@ -614,11 +625,11 @@ pub type SimpleArcOnionMessenger = OnionMessenger< /// /// [`SimpleRefChannelManager`]: crate::ln::channelmanager::SimpleRefChannelManager /// [`SimpleRefPeerManager`]: crate::ln::peer_handler::SimpleRefPeerManager -pub type SimpleRefOnionMessenger<'a, 'b, 'c, L, R> = OnionMessenger< +pub type SimpleRefOnionMessenger<'a, 'b, 'c, L> = OnionMessenger< &'a KeysManager, &'a KeysManager, &'b L, - &'c R, + &'c DefaultMessageRouter, IgnoringMessageHandler, IgnoringMessageHandler >; -- 2.39.5