From: Matt Corallo Date: Mon, 1 Mar 2021 23:04:20 +0000 (-0500) Subject: Add utility constructors to PeerHandler to use a dummy handler X-Git-Tag: v0.0.13~15^2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=d95f14568b6efbc4722f3d7ee78477328678c052;p=rust-lightning Add utility constructors to PeerHandler to use a dummy handler --- diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index bba7faaf5..b977f7913 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -353,6 +353,44 @@ macro_rules! encode_msg { }} } +impl PeerManager where + CM::Target: ChannelMessageHandler, + L::Target: Logger { + /// Constructs a new PeerManager with the given ChannelMessageHandler. No routing message + /// handler is used and network graph messages are ignored. + /// + /// ephemeral_random_data is used to derive per-connection ephemeral keys and must be + /// cryptographically secure random bytes. + /// + /// (C-not exported) as we can't export a PeerManager with a dummy route handler + pub fn new_channel_only(channel_message_handler: CM, our_node_secret: SecretKey, ephemeral_random_data: &[u8; 32], logger: L) -> Self { + Self::new(MessageHandler { + chan_handler: channel_message_handler, + route_handler: IgnoringMessageHandler{}, + }, our_node_secret, ephemeral_random_data, logger) + } +} + +impl PeerManager where + RM::Target: RoutingMessageHandler, + L::Target: Logger { + /// Constructs a new PeerManager with the given RoutingMessageHandler. No channel message + /// handler is used and messages related to channels will be ignored (or generate error + /// messages). Note that some other lightning implementations time-out connections after some + /// time if no channel is built with the peer. + /// + /// ephemeral_random_data is used to derive per-connection ephemeral keys and must be + /// cryptographically secure random bytes. + /// + /// (C-not exported) as we can't export a PeerManager with a dummy channel handler + pub fn new_routing_only(routing_message_handler: RM, our_node_secret: SecretKey, ephemeral_random_data: &[u8; 32], logger: L) -> Self { + Self::new(MessageHandler { + chan_handler: ErroringMessageHandler::new(), + route_handler: routing_message_handler, + }, our_node_secret, ephemeral_random_data, logger) + } +} + /// Manages and reacts to connection events. You probably want to use file descriptors as PeerIds. /// PeerIds may repeat, but only after socket_disconnected() has been called. impl PeerManager where