X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fpeer_handler.rs;h=d38afcbacb304620851d92de9eb54f4de813e5c0;hb=2e7d924d9ba7255e787c6fff1f38e39dc8c9a0e8;hp=a94c9a091981fe65415774d2bf8cfe664f12c2f8;hpb=b78359af9ebe4e1b98b875913cc8980188e35b31;p=rust-lightning diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index a94c9a09..d38afcba 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -73,7 +73,7 @@ impl RoutingMessageHandler for IgnoringMessageHandler { fn get_next_channel_announcement(&self, _starting_point: u64) -> Option<(msgs::ChannelAnnouncement, Option, Option)> { None } fn get_next_node_announcement(&self, _starting_point: Option<&PublicKey>) -> Option { None } - fn peer_connected(&self, _their_node_id: &PublicKey, _init: &msgs::Init) {} + fn peer_connected(&self, _their_node_id: &PublicKey, _init: &msgs::Init) -> Result<(), ()> { Ok(()) } fn handle_reply_channel_range(&self, _their_node_id: &PublicKey, _msg: msgs::ReplyChannelRange) -> Result<(), LightningError> { Ok(()) } fn handle_reply_short_channel_ids_end(&self, _their_node_id: &PublicKey, _msg: msgs::ReplyShortChannelIdsEnd) -> Result<(), LightningError> { Ok(()) } fn handle_query_channel_range(&self, _their_node_id: &PublicKey, _msg: msgs::QueryChannelRange) -> Result<(), LightningError> { Ok(()) } @@ -88,7 +88,7 @@ impl OnionMessageProvider for IgnoringMessageHandler { } impl OnionMessageHandler for IgnoringMessageHandler { fn handle_onion_message(&self, _their_node_id: &PublicKey, _msg: &msgs::OnionMessage) {} - fn peer_connected(&self, _their_node_id: &PublicKey, _init: &msgs::Init) {} + fn peer_connected(&self, _their_node_id: &PublicKey, _init: &msgs::Init) -> Result<(), ()> { Ok(()) } fn peer_disconnected(&self, _their_node_id: &PublicKey, _no_connection_possible: bool) {} fn provided_node_features(&self) -> NodeFeatures { NodeFeatures::empty() } fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures { @@ -209,13 +209,26 @@ impl ChannelMessageHandler for ErroringMessageHandler { // msgs::ChannelUpdate does not contain the channel_id field, so we just drop them. fn handle_channel_update(&self, _their_node_id: &PublicKey, _msg: &msgs::ChannelUpdate) {} fn peer_disconnected(&self, _their_node_id: &PublicKey, _no_connection_possible: bool) {} - fn peer_connected(&self, _their_node_id: &PublicKey, _msg: &msgs::Init) {} + fn peer_connected(&self, _their_node_id: &PublicKey, _init: &msgs::Init) -> Result<(), ()> { Ok(()) } fn handle_error(&self, _their_node_id: &PublicKey, _msg: &msgs::ErrorMessage) {} fn provided_node_features(&self) -> NodeFeatures { NodeFeatures::empty() } fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures { - // Use our known channel feature set as peers may otherwise not be willing to talk to us at - // all. - InitFeatures::known_channel_features() + // Set a number of features which various nodes may require to talk to us. It's totally + // reasonable to indicate we "support" all kinds of channel features...we just reject all + // channels. + let mut features = InitFeatures::empty(); + features.set_data_loss_protect_optional(); + features.set_upfront_shutdown_script_optional(); + features.set_variable_length_onion_optional(); + features.set_static_remote_key_optional(); + features.set_payment_secret_optional(); + features.set_basic_mpp_optional(); + features.set_wumbo_optional(); + features.set_shutdown_any_segwit_optional(); + features.set_channel_type_optional(); + features.set_scid_privacy_optional(); + features.set_zero_conf_optional(); + features } } impl Deref for ErroringMessageHandler { @@ -368,8 +381,10 @@ struct Peer { pending_outbound_buffer: LinkedList>, pending_outbound_buffer_first_msg_offset: usize, - // Queue gossip broadcasts separately from `pending_outbound_buffer` so we can easily prioritize - // channel messages over them. + /// Queue gossip broadcasts separately from `pending_outbound_buffer` so we can easily + /// prioritize channel messages over them. + /// + /// Note that these messages are *not* encrypted/MAC'd, and are only serialized. gossip_broadcast_buffer: LinkedList>, awaiting_write_event: bool, @@ -823,7 +838,7 @@ impl(&self, peer: &mut Peer, message: &M) { - let mut buffer = VecWriter(Vec::with_capacity(2048)); - wire::write(message, &mut buffer).unwrap(); // crash if the write failed - if is_gossip_msg(message.type_id()) { log_gossip!(self.logger, "Enqueueing message {:?} to {}", message, log_pubkey!(peer.their_node_id.unwrap())); } else { log_trace!(self.logger, "Enqueueing message {:?} to {}", message, log_pubkey!(peer.their_node_id.unwrap())) } peer.msgs_sent_since_pong += 1; - peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&buffer.0[..])); + peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(message)); } /// Append a message to a peer's pending outbound/write gossip broadcast buffer - fn enqueue_encoded_gossip_broadcast(&self, peer: &mut Peer, encoded_message: &Vec) { + fn enqueue_encoded_gossip_broadcast(&self, peer: &mut Peer, encoded_message: Vec) { peer.msgs_sent_since_pong += 1; - peer.gossip_broadcast_buffer.push_back(peer.channel_encryptor.encrypt_message(&encoded_message[..])); + peer.gossip_broadcast_buffer.push_back(encoded_message); } fn do_read_event(&self, peer_descriptor: &mut Descriptor, data: &[u8]) -> Result { @@ -1128,7 +1140,10 @@ impl { log_gossip!(self.logger, "Got an invalid value while deserializing a gossip message"); - self.enqueue_message(peer, &msgs::WarningMessage { channel_id: [0; 32], data: "Unreadable/bogus gossip message".to_owned() }); + self.enqueue_message(peer, &msgs::WarningMessage { + channel_id: [0; 32], + data: format!("Unreadable/bogus gossip message of type {}", ty), + }); continue; } (msgs::DecodeError::UnknownRequiredFeature, ty) => { @@ -1211,14 +1226,18 @@ impl { @@ -1459,7 +1478,7 @@ impl { @@ -1479,7 +1498,7 @@ impl debug_assert!(false, "We shouldn't attempt to forward anything but gossip messages"),