Skip to content

Commit 3fe33b0

Browse files
committed
Make RoutingMessageHandler a generic Deref instead of an Arc
We also update to use single idents when referencing the Deref=* types since the automated code generator is pretty braindead.
1 parent f8fc32d commit 3fe33b0

File tree

3 files changed

+144
-181
lines changed

3 files changed

+144
-181
lines changed

lightning-net-tokio/src/lib.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ use tokio::io::{AsyncReadExt, AsyncWrite, AsyncWriteExt};
6868

6969
use lightning::ln::peer_handler;
7070
use lightning::ln::peer_handler::SocketDescriptor as LnSocketTrait;
71-
use lightning::ln::msgs::ChannelMessageHandler;
71+
use lightning::ln::msgs::{ChannelMessageHandler, RoutingMessageHandler};
7272

7373
use std::{task, thread};
7474
use std::net::SocketAddr;
@@ -121,7 +121,9 @@ impl Connection {
121121
_ => panic!()
122122
}
123123
}
124-
async fn schedule_read<CMH: ChannelMessageHandler + 'static>(peer_manager: Arc<peer_handler::PeerManager<SocketDescriptor, Arc<CMH>>>, us: Arc<Mutex<Self>>, mut reader: io::ReadHalf<TcpStream>, mut read_wake_receiver: mpsc::Receiver<()>, mut write_avail_receiver: mpsc::Receiver<()>) {
124+
async fn schedule_read<CMH, RMH>(peer_manager: Arc<peer_handler::PeerManager<SocketDescriptor, Arc<CMH>, Arc<RMH>>>, us: Arc<Mutex<Self>>, mut reader: io::ReadHalf<TcpStream>, mut read_wake_receiver: mpsc::Receiver<()>, mut write_avail_receiver: mpsc::Receiver<()>) where
125+
CMH: ChannelMessageHandler + 'static,
126+
RMH: RoutingMessageHandler + 'static {
125127
let peer_manager_ref = peer_manager.clone();
126128
// 8KB is nice and big but also should never cause any issues with stack overflowing.
127129
let mut buf = [0; 8192];
@@ -231,7 +233,9 @@ impl Connection {
231233
/// not need to poll the provided future in order to make progress.
232234
///
233235
/// See the module-level documentation for how to handle the event_notify mpsc::Sender.
234-
pub fn setup_inbound<CMH: ChannelMessageHandler + 'static>(peer_manager: Arc<peer_handler::PeerManager<SocketDescriptor, Arc<CMH>>>, event_notify: mpsc::Sender<()>, stream: TcpStream) -> impl std::future::Future<Output=()> {
236+
pub fn setup_inbound<CMH, RMH>(peer_manager: Arc<peer_handler::PeerManager<SocketDescriptor, Arc<CMH>, Arc<RMH>>>, event_notify: mpsc::Sender<()>, stream: TcpStream) -> impl std::future::Future<Output=()> where
237+
CMH: ChannelMessageHandler + 'static,
238+
RMH: RoutingMessageHandler + 'static {
235239
let (reader, write_receiver, read_receiver, us) = Connection::new(event_notify, stream);
236240
#[cfg(debug_assertions)]
237241
let last_us = Arc::clone(&us);
@@ -270,7 +274,9 @@ pub fn setup_inbound<CMH: ChannelMessageHandler + 'static>(peer_manager: Arc<pee
270274
/// not need to poll the provided future in order to make progress.
271275
///
272276
/// See the module-level documentation for how to handle the event_notify mpsc::Sender.
273-
pub fn setup_outbound<CMH: ChannelMessageHandler + 'static>(peer_manager: Arc<peer_handler::PeerManager<SocketDescriptor, Arc<CMH>>>, event_notify: mpsc::Sender<()>, their_node_id: PublicKey, stream: TcpStream) -> impl std::future::Future<Output=()> {
277+
pub fn setup_outbound<CMH, RMH>(peer_manager: Arc<peer_handler::PeerManager<SocketDescriptor, Arc<CMH>, Arc<RMH>>>, event_notify: mpsc::Sender<()>, their_node_id: PublicKey, stream: TcpStream) -> impl std::future::Future<Output=()> where
278+
CMH: ChannelMessageHandler + 'static,
279+
RMH: RoutingMessageHandler + 'static {
274280
let (reader, mut write_receiver, read_receiver, us) = Connection::new(event_notify, stream);
275281
#[cfg(debug_assertions)]
276282
let last_us = Arc::clone(&us);
@@ -339,7 +345,9 @@ pub fn setup_outbound<CMH: ChannelMessageHandler + 'static>(peer_manager: Arc<pe
339345
/// make progress.
340346
///
341347
/// See the module-level documentation for how to handle the event_notify mpsc::Sender.
342-
pub async fn connect_outbound<CMH: ChannelMessageHandler + 'static>(peer_manager: Arc<peer_handler::PeerManager<SocketDescriptor, Arc<CMH>>>, event_notify: mpsc::Sender<()>, their_node_id: PublicKey, addr: SocketAddr) -> Option<impl std::future::Future<Output=()>> {
348+
pub async fn connect_outbound<CMH, RMH>(peer_manager: Arc<peer_handler::PeerManager<SocketDescriptor, Arc<CMH>, Arc<RMH>>>, event_notify: mpsc::Sender<()>, their_node_id: PublicKey, addr: SocketAddr) -> Option<impl std::future::Future<Output=()>> where
349+
CMH: ChannelMessageHandler + 'static,
350+
RMH: RoutingMessageHandler + 'static {
343351
if let Ok(Ok(stream)) = time::timeout(Duration::from_secs(10), TcpStream::connect(&addr)).await {
344352
Some(setup_outbound(peer_manager, event_notify, their_node_id, stream))
345353
} else { None }
@@ -565,7 +573,7 @@ mod tests {
565573
});
566574
let a_manager = Arc::new(PeerManager::new(MessageHandler {
567575
chan_handler: Arc::clone(&a_handler),
568-
route_handler: Arc::clone(&a_handler) as Arc<dyn RoutingMessageHandler>,
576+
route_handler: Arc::clone(&a_handler),
569577
}, a_key.clone(), &[1; 32], Arc::new(TestLogger())));
570578

571579
let (b_connected_sender, mut b_connected) = mpsc::channel(1);
@@ -578,7 +586,7 @@ mod tests {
578586
});
579587
let b_manager = Arc::new(PeerManager::new(MessageHandler {
580588
chan_handler: Arc::clone(&b_handler),
581-
route_handler: Arc::clone(&b_handler) as Arc<dyn RoutingMessageHandler>,
589+
route_handler: Arc::clone(&b_handler),
582590
}, b_key.clone(), &[2; 32], Arc::new(TestLogger())));
583591

584592
// We bind on localhost, hoping the environment is properly configured with a local

0 commit comments

Comments
 (0)