Skip to content

Commit

Permalink
Merge pull request #2384 from jkczyz/2023-06-message-router
Browse files Browse the repository at this point in the history
Define a default `MessageRouter` implementation
  • Loading branch information
TheBlueMatt authored Jul 2, 2023
2 parents 63c77a9 + 129dd30 commit 86fd9e7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
3 changes: 1 addition & 2 deletions lightning-background-processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<lightning::sign::InMemorySigner, Arc<MyFilter>, Arc<MyBroadcaster>, Arc<MyFeeEstimator>, Arc<MyLogger>, Arc<MyPersister>>;
/// # type MyPeerManager = lightning::ln::peer_handler::SimpleArcPeerManager<MySocketDescriptor, MyChainMonitor, MyBroadcaster, MyFeeEstimator, MyUtxoLookup, MyLogger, MyMessageRouter>;
/// # type MyPeerManager = lightning::ln::peer_handler::SimpleArcPeerManager<MySocketDescriptor, MyChainMonitor, MyBroadcaster, MyFeeEstimator, MyUtxoLookup, MyLogger>;
/// # type MyNetworkGraph = lightning::routing::gossip::NetworkGraph<Arc<MyLogger>>;
/// # type MyGossipSync = lightning::routing::gossip::P2PGossipSync<Arc<MyNetworkGraph>, Arc<MyUtxoLookup>, Arc<MyLogger>>;
/// # type MyChannelManager = lightning::ln::channelmanager::SimpleArcChannelManager<MyChainMonitor, MyBroadcaster, MyFeeEstimator, MyLogger>;
Expand Down
8 changes: 4 additions & 4 deletions lightning/src/ln/peer_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SD, M, T, F, C, L, R> = PeerManager<
pub type SimpleArcPeerManager<SD, M, T, F, C, L> = PeerManager<
SD,
Arc<SimpleArcChannelManager<M, T, F, L>>,
Arc<P2PGossipSync<Arc<NetworkGraph<Arc<L>>>, Arc<C>, Arc<L>>>,
Arc<SimpleArcOnionMessenger<L, R>>,
Arc<SimpleArcOnionMessenger<L>>,
Arc<L>,
IgnoringMessageHandler,
Arc<KeysManager>
Expand All @@ -626,12 +626,12 @@ pub type SimpleArcPeerManager<SD, M, T, F, C, L, R> = 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
Expand Down
19 changes: 15 additions & 4 deletions lightning/src/onion_message/messenger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,17 @@ pub trait MessageRouter {
) -> Result<OnionMessagePath, ()>;
}

/// A [`MessageRouter`] that always fails.
pub struct DefaultMessageRouter;

impl MessageRouter for DefaultMessageRouter {
fn find_path(
&self, _sender: PublicKey, _peers: Vec<PublicKey>, _destination: Destination
) -> Result<OnionMessagePath, ()> {
Err(())
}
}

/// A path for sending an [`msgs::OnionMessage`].
#[derive(Clone)]
pub struct OnionMessagePath {
Expand Down Expand Up @@ -598,11 +609,11 @@ where
///
/// [`SimpleArcChannelManager`]: crate::ln::channelmanager::SimpleArcChannelManager
/// [`SimpleArcPeerManager`]: crate::ln::peer_handler::SimpleArcPeerManager
pub type SimpleArcOnionMessenger<L, R> = OnionMessenger<
pub type SimpleArcOnionMessenger<L> = OnionMessenger<
Arc<KeysManager>,
Arc<KeysManager>,
Arc<L>,
Arc<R>,
Arc<DefaultMessageRouter>,
IgnoringMessageHandler,
IgnoringMessageHandler
>;
Expand All @@ -614,11 +625,11 @@ pub type SimpleArcOnionMessenger<L, R> = 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
>;
Expand Down

0 comments on commit 86fd9e7

Please sign in to comment.