X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-net-tokio%2Fsrc%2Flib.rs;fp=lightning-net-tokio%2Fsrc%2Flib.rs;h=47e179189789f953f0944b017b0bc3a5ff9faaec;hb=4833d1acf9fd7755db5aaaaa50f3e54e8446d6b3;hp=0bc36b28075f887476ac782d52a955c80b56cb0c;hpb=9a0211543762ae15ce4a0b7cb5aa3cf295a4b61f;p=rust-lightning diff --git a/lightning-net-tokio/src/lib.rs b/lightning-net-tokio/src/lib.rs index 0bc36b28..47e17918 100644 --- a/lightning-net-tokio/src/lib.rs +++ b/lightning-net-tokio/src/lib.rs @@ -19,6 +19,7 @@ use tokio::net::TcpStream; use lightning::ln::peer_handler; use lightning::ln::peer_handler::SocketDescriptor as LnSocketTrait; +use lightning::ln::msgs::ChannelMessageHandler; use std::mem; use std::net::SocketAddr; @@ -42,7 +43,7 @@ pub struct Connection { id: u64, } impl Connection { - fn schedule_read(peer_manager: Arc>, us: Arc>, reader: futures::stream::SplitStream>) { + fn schedule_read(peer_manager: Arc, Arc>>, us: Arc>, reader: futures::stream::SplitStream>) { let us_ref = us.clone(); let us_close_ref = us.clone(); let peer_manager_ref = peer_manager.clone(); @@ -110,7 +111,7 @@ impl Connection { /// /// You should poll the Receive end of event_notify and call get_and_clear_pending_events() on /// ChannelManager and ChannelMonitor objects. - pub fn setup_inbound(peer_manager: Arc>, event_notify: mpsc::Sender<()>, stream: TcpStream) { + pub fn setup_inbound(peer_manager: Arc, Arc>>, event_notify: mpsc::Sender<()>, stream: TcpStream) { let (reader, us) = Self::new(event_notify, stream); if let Ok(_) = peer_manager.new_inbound_connection(SocketDescriptor::new(us.clone(), peer_manager.clone())) { @@ -124,7 +125,7 @@ impl Connection { /// /// You should poll the Receive end of event_notify and call get_and_clear_pending_events() on /// ChannelManager and ChannelMonitor objects. - pub fn setup_outbound(peer_manager: Arc>, event_notify: mpsc::Sender<()>, their_node_id: PublicKey, stream: TcpStream) { + pub fn setup_outbound(peer_manager: Arc, Arc>>, event_notify: mpsc::Sender<()>, their_node_id: PublicKey, stream: TcpStream) { let (reader, us) = Self::new(event_notify, stream); if let Ok(initial_send) = peer_manager.new_outbound_connection(their_node_id, SocketDescriptor::new(us.clone(), peer_manager.clone())) { @@ -142,7 +143,7 @@ impl Connection { /// /// You should poll the Receive end of event_notify and call get_and_clear_pending_events() on /// ChannelManager and ChannelMonitor objects. - pub fn connect_outbound(peer_manager: Arc>, event_notify: mpsc::Sender<()>, their_node_id: PublicKey, addr: SocketAddr) { + pub fn connect_outbound(peer_manager: Arc, Arc>>, event_notify: mpsc::Sender<()>, their_node_id: PublicKey, addr: SocketAddr) { let connect_timeout = Delay::new(Instant::now() + Duration::from_secs(10)).then(|_| { future::err(std::io::Error::new(std::io::ErrorKind::TimedOut, "timeout reached")) }); @@ -157,19 +158,18 @@ impl Connection { } } -#[derive(Clone)] -pub struct SocketDescriptor { +pub struct SocketDescriptor { conn: Arc>, id: u64, - peer_manager: Arc>, + peer_manager: Arc, Arc>>, } -impl SocketDescriptor { - fn new(conn: Arc>, peer_manager: Arc>) -> Self { +impl SocketDescriptor { + fn new(conn: Arc>, peer_manager: Arc, Arc>>) -> Self { let id = conn.lock().unwrap().id; Self { conn, id, peer_manager } } } -impl peer_handler::SocketDescriptor for SocketDescriptor { +impl peer_handler::SocketDescriptor for SocketDescriptor { fn send_data(&mut self, data: &[u8], resume_read: bool) -> usize { macro_rules! schedule_read { ($us_ref: expr) => { @@ -256,13 +256,22 @@ impl peer_handler::SocketDescriptor for SocketDescriptor { us.read_paused = true; } } -impl Eq for SocketDescriptor {} -impl PartialEq for SocketDescriptor { +impl Clone for SocketDescriptor { + fn clone(&self) -> Self { + Self { + conn: Arc::clone(&self.conn), + id: self.id, + peer_manager: Arc::clone(&self.peer_manager), + } + } +} +impl Eq for SocketDescriptor {} +impl PartialEq for SocketDescriptor { fn eq(&self, o: &Self) -> bool { self.id == o.id } } -impl Hash for SocketDescriptor { +impl Hash for SocketDescriptor { fn hash(&self, state: &mut H) { self.id.hash(state); }