X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fpeer_handler.rs;h=22568e506668f127a3f8d179f8df356d383724cd;hb=e82318d374fc6dd8e0aec5155bb06bca432ae4b7;hp=2470058f58960378f199a3e02e5703d22feb92e2;hpb=088daf79aa375a69089ba2054ecf9820ae2c8871;p=rust-lightning diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 2470058f..22568e50 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -37,6 +37,7 @@ use sync::{Arc, Mutex}; use core::sync::atomic::{AtomicUsize, Ordering}; use core::{cmp, hash, fmt, mem}; use core::ops::Deref; +use core::convert::Infallible; #[cfg(feature = "std")] use std::error; use bitcoin::hashes::sha256::Hash as Sha256; @@ -80,21 +81,21 @@ impl Deref for IgnoringMessageHandler { fn deref(&self) -> &Self { self } } -impl wire::Type for () { +// Implement Type for Infallible, note that it cannot be constructed, and thus you can never call a +// method that takes self for it. +impl wire::Type for Infallible { fn type_id(&self) -> u16 { - // We should never call this for `DummyCustomType` unreachable!(); } } - -impl Writeable for () { +impl Writeable for Infallible { fn write(&self, _: &mut W) -> Result<(), io::Error> { unreachable!(); } } impl wire::CustomMessageReader for IgnoringMessageHandler { - type CustomMessage = (); + type CustomMessage = Infallible; fn read(&self, _message_type: u16, _buffer: &mut R) -> Result, msgs::DecodeError> { Ok(None) } @@ -720,7 +721,7 @@ impl P /// Append a message to a peer's pending outbound/write buffer, and update the map of peers needing sends accordingly. fn enqueue_message(&self, peer: &mut Peer, message: &M) { - let mut buffer = VecWriter(Vec::new()); + let mut buffer = VecWriter(Vec::with_capacity(2048)); wire::write(message, &mut buffer).unwrap(); // crash if the write failed let encoded_message = buffer.0; @@ -1169,6 +1170,9 @@ impl P /// May call [`send_data`] on [`SocketDescriptor`]s. Thus, be very careful with reentrancy /// issues! /// + /// You don't have to call this function explicitly if you are using [`lightning-net-tokio`] + /// or one of the other clients provided in our language bindings. + /// /// [`send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment /// [`ChannelManager::process_pending_htlc_forwards`]: crate::ln::channelmanager::ChannelManager::process_pending_htlc_forwards /// [`send_data`]: SocketDescriptor::send_data