From a28c0c1f895b3df820dd8698192aca2370cbd664 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 31 Jan 2020 20:57:01 -0500 Subject: [PATCH] Swap read_event read type for a slice isntead of a Vec It looks like we don't currently use the Vec as a Vec, and can happily take a slice, which makes things easier on the calling side. --- fuzz/src/full_stack.rs | 2 +- lightning-net-tokio/src/lib.rs | 4 ++-- lightning/src/ln/peer_handler.rs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/fuzz/src/full_stack.rs b/fuzz/src/full_stack.rs index e29e24ca4..2237e9133 100644 --- a/fuzz/src/full_stack.rs +++ b/fuzz/src/full_stack.rs @@ -380,7 +380,7 @@ pub fn do_test(data: &[u8], logger: &Arc) { 3 => { let peer_id = get_slice!(1)[0]; if !peers.borrow()[peer_id as usize] { return; } - match loss_detector.handler.read_event(&mut Peer{id: peer_id, peers_connected: &peers}, get_slice!(get_slice!(1)[0]).to_vec()) { + match loss_detector.handler.read_event(&mut Peer{id: peer_id, peers_connected: &peers}, get_slice!(get_slice!(1)[0])) { Ok(res) => assert!(!res), Err(_) => { peers.borrow_mut()[peer_id as usize] = false; } } diff --git a/lightning-net-tokio/src/lib.rs b/lightning-net-tokio/src/lib.rs index 47e179189..ca12cad40 100644 --- a/lightning-net-tokio/src/lib.rs +++ b/lightning-net-tokio/src/lib.rs @@ -62,7 +62,7 @@ impl Connection { //TODO: There's a race where we don't meet the requirements of disconnect_socket if its //called right here, after we release the us_ref lock in the scope above, but before we //call read_event! - match peer_manager.read_event(&mut SocketDescriptor::new(us_ref.clone(), peer_manager.clone()), pending_read) { + match peer_manager.read_event(&mut SocketDescriptor::new(us_ref.clone(), peer_manager.clone()), &pending_read) { Ok(pause_read) => { if pause_read { let mut lock = us_ref.lock().unwrap(); @@ -181,7 +181,7 @@ impl peer_handler::SocketDescriptor for SocketDescri } if !read_data.is_empty() { let mut us_clone = $us_ref.clone(); - match $us_ref.peer_manager.read_event(&mut us_clone, read_data) { + match $us_ref.peer_manager.read_event(&mut us_clone, &read_data) { Ok(pause_read) => { if pause_read { return Ok(()); } }, diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index a0ab8ffce..f715e26a0 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -445,7 +445,7 @@ impl PeerManager where /// this file descriptor has resume_read set (preventing DoS issues in the send buffer). /// /// Panics if the descriptor was not previously registered in a new_*_connection event. - pub fn read_event(&self, peer_descriptor: &mut Descriptor, data: Vec) -> Result { + pub fn read_event(&self, peer_descriptor: &mut Descriptor, data: &[u8]) -> Result { match self.do_read_event(peer_descriptor, data) { Ok(res) => Ok(res), Err(e) => { @@ -455,7 +455,7 @@ impl PeerManager where } } - fn do_read_event(&self, peer_descriptor: &mut Descriptor, data: Vec) -> Result { + fn do_read_event(&self, peer_descriptor: &mut Descriptor, data: &[u8]) -> Result { let pause_read = { let mut peers_lock = self.peers.lock().unwrap(); let peers = &mut *peers_lock; -- 2.39.5