Ok(())
}
+ fn forward_broadcast_msg(&self, peers: &mut PeerHolder<Descriptor>, msg: &wire::Message, except_node: Option<&PublicKey>) {
+ match msg {
+ wire::Message::ChannelAnnouncement(ref msg) => {
+ let encoded_msg = encode_msg!(msg);
+
+ for (ref descriptor, ref mut peer) in peers.peers.iter_mut() {
+ if !peer.channel_encryptor.is_ready_for_encryption() || peer.their_features.is_none() ||
+ !peer.should_forward_channel_announcement(msg.contents.short_channel_id) {
+ continue
+ }
+ if peer.their_node_id.as_ref() == Some(&msg.contents.node_id_1) ||
+ peer.their_node_id.as_ref() == Some(&msg.contents.node_id_2) {
+ continue;
+ }
+ if except_node.is_some() && peer.their_node_id.as_ref() == except_node {
+ continue;
+ }
+ peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encoded_msg[..]));
+ peers.peers_needing_send.insert((*descriptor).clone());
+ }
+ },
+ wire::Message::NodeAnnouncement(ref msg) => {
+ let encoded_msg = encode_msg!(msg);
+
+ for (ref descriptor, ref mut peer) in peers.peers.iter_mut() {
+ if !peer.channel_encryptor.is_ready_for_encryption() || peer.their_features.is_none() ||
+ !peer.should_forward_node_announcement(msg.contents.node_id) {
+ continue
+ }
+ if peer.their_node_id.as_ref() == Some(&msg.contents.node_id) {
+ continue;
+ }
+ if except_node.is_some() && peer.their_node_id.as_ref() == except_node {
+ continue;
+ }
+ peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encoded_msg[..]));
+ peers.peers_needing_send.insert((*descriptor).clone());
+ }
+ },
+ wire::Message::ChannelUpdate(ref msg) => {
+ let encoded_msg = encode_msg!(msg);
+
+ for (ref descriptor, ref mut peer) in peers.peers.iter_mut() {
+ if !peer.channel_encryptor.is_ready_for_encryption() || peer.their_features.is_none() ||
+ !peer.should_forward_channel_announcement(msg.contents.short_channel_id) {
+ continue
+ }
+ if except_node.is_some() && peer.their_node_id.as_ref() == except_node {
+ continue;
+ }
+ peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encoded_msg[..]));
+ peers.peers_needing_send.insert((*descriptor).clone());
+ }
+ },
+ _ => debug_assert!(false, "We shouldn't attempt to forward anything but gossip messages"),
+ }
+ }
+
/// Checks for any events generated by our handlers and processes them. Includes sending most
/// response messages as well as messages generated by calls to handler functions directly (eg
/// functions like ChannelManager::process_pending_htlc_forward or send_payment).
peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encode_msg!(msg)));
self.do_attempt_write_data(&mut descriptor, peer);
},
- MessageSendEvent::BroadcastChannelAnnouncement { ref msg, ref update_msg } => {
+ MessageSendEvent::BroadcastChannelAnnouncement { msg, update_msg } => {
log_trace!(self.logger, "Handling BroadcastChannelAnnouncement event in peer_handler for short channel id {}", msg.contents.short_channel_id);
- if self.message_handler.route_handler.handle_channel_announcement(msg).is_ok() && self.message_handler.route_handler.handle_channel_update(update_msg).is_ok() {
- let encoded_msg = encode_msg!(msg);
- let encoded_update_msg = encode_msg!(update_msg);
-
- for (ref descriptor, ref mut peer) in peers.peers.iter_mut() {
- if !peer.channel_encryptor.is_ready_for_encryption() || peer.their_features.is_none() ||
- !peer.should_forward_channel_announcement(msg.contents.short_channel_id) {
- continue
- }
- match peer.their_node_id {
- None => continue,
- Some(their_node_id) => {
- if their_node_id == msg.contents.node_id_1 || their_node_id == msg.contents.node_id_2 {
- continue
- }
- }
- }
- peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encoded_msg[..]));
- peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encoded_update_msg[..]));
- self.do_attempt_write_data(&mut (*descriptor).clone(), peer);
- }
+ if self.message_handler.route_handler.handle_channel_announcement(&msg).is_ok() && self.message_handler.route_handler.handle_channel_update(&update_msg).is_ok() {
+ self.forward_broadcast_msg(peers, &wire::Message::ChannelAnnouncement(msg), None);
+ self.forward_broadcast_msg(peers, &wire::Message::ChannelUpdate(update_msg), None);
}
},
- MessageSendEvent::BroadcastNodeAnnouncement { ref msg } => {
+ MessageSendEvent::BroadcastNodeAnnouncement { msg } => {
log_trace!(self.logger, "Handling BroadcastNodeAnnouncement event in peer_handler");
- if self.message_handler.route_handler.handle_node_announcement(msg).is_ok() {
- let encoded_msg = encode_msg!(msg);
-
- for (ref descriptor, ref mut peer) in peers.peers.iter_mut() {
- if !peer.channel_encryptor.is_ready_for_encryption() || peer.their_features.is_none() ||
- !peer.should_forward_node_announcement(msg.contents.node_id) {
- continue
- }
- peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encoded_msg[..]));
- self.do_attempt_write_data(&mut (*descriptor).clone(), peer);
- }
+ if self.message_handler.route_handler.handle_node_announcement(&msg).is_ok() {
+ self.forward_broadcast_msg(peers, &wire::Message::NodeAnnouncement(msg), None);
}
},
- MessageSendEvent::BroadcastChannelUpdate { ref msg } => {
+ MessageSendEvent::BroadcastChannelUpdate { msg } => {
log_trace!(self.logger, "Handling BroadcastChannelUpdate event in peer_handler for short channel id {}", msg.contents.short_channel_id);
- if self.message_handler.route_handler.handle_channel_update(msg).is_ok() {
- let encoded_msg = encode_msg!(msg);
-
- for (ref descriptor, ref mut peer) in peers.peers.iter_mut() {
- if !peer.channel_encryptor.is_ready_for_encryption() || peer.their_features.is_none() ||
- !peer.should_forward_channel_announcement(msg.contents.short_channel_id) {
- continue
- }
- peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encoded_msg[..]));
- self.do_attempt_write_data(&mut (*descriptor).clone(), peer);
- }
+ if self.message_handler.route_handler.handle_channel_update(&msg).is_ok() {
+ self.forward_broadcast_msg(peers, &wire::Message::ChannelUpdate(msg), None);
}
},
MessageSendEvent::PaymentFailureNetworkUpdate { ref update } => {