/// Create a Features with the features we support
pub fn supported() -> InitFeatures {
InitFeatures {
- flags: vec![2 | 1 << 5, 1 << (9-8) | 1 << (15 - 8), 1 << (17 - 8*2)],
+ flags: vec![2 | 1 << 3 | 1 << 5, 1 << (9-8) | 1 << (15 - 8), 1 << (17 - 8*2)],
mark: PhantomData,
}
}
pub(crate) fn initial_routing_sync(&self) -> bool {
self.flags.len() > 0 && (self.flags[0] & (1 << 3)) != 0
}
- pub(crate) fn set_initial_routing_sync(&mut self) {
- if self.flags.len() == 0 {
- self.flags.resize(1, 1 << 3);
- } else {
- self.flags[0] |= 1 << 3;
+ pub(crate) fn clear_initial_routing_sync(&mut self) {
+ if self.flags.len() > 0 {
+ self.flags[0] &= !(1 << 3);
}
}
}
assert!(NodeFeatures::supported().supports_basic_mpp());
let mut init_features = InitFeatures::supported();
- init_features.set_initial_routing_sync();
- assert!(!init_features.requires_unknown_bits());
- assert!(!init_features.supports_unknown_bits());
+ assert!(init_features.initial_routing_sync());
+ init_features.clear_initial_routing_sync();
+ assert!(!init_features.initial_routing_sync());
}
#[test]
#[test]
fn test_node_with_known_relevant_init_flags() {
// Create an InitFeatures with initial_routing_sync supported.
- let mut init_features = InitFeatures::supported();
- init_features.set_initial_routing_sync();
+ let init_features = InitFeatures::supported();
+ assert!(init_features.initial_routing_sync());
// Attempt to pull out non-node-context feature flags from these InitFeatures.
let res = NodeFeatures::with_known_relevant_init_flags(&init_features);
peer.their_node_id = Some(their_node_id);
insert_node_id!();
let mut features = InitFeatures::supported();
- if self.message_handler.route_handler.should_request_full_sync(&peer.their_node_id.unwrap()) {
- features.set_initial_routing_sync();
+ if !self.message_handler.route_handler.should_request_full_sync(&peer.their_node_id.unwrap()) {
+ features.clear_initial_routing_sync();
}
let resp = msgs::Init { features };
if !peer.outbound {
let mut features = InitFeatures::supported();
- if self.message_handler.route_handler.should_request_full_sync(&peer.their_node_id.unwrap()) {
- features.set_initial_routing_sync();
+ if !self.message_handler.route_handler.should_request_full_sync(&peer.their_node_id.unwrap()) {
+ features.clear_initial_routing_sync();
}
let resp = msgs::Init { features };
(fd_a.clone(), fd_b.clone())
}
+ fn establish_connection_and_read_events<'a>(peer_a: &PeerManager<FileDescriptor, &'a test_utils::TestChannelMessageHandler>, peer_b: &PeerManager<FileDescriptor, &'a test_utils::TestChannelMessageHandler>) -> (FileDescriptor, FileDescriptor) {
+ let (mut fd_a, mut fd_b) = establish_connection(peer_a, peer_b);
+ assert_eq!(peer_b.read_event(&mut fd_b, &fd_a.outbound_data.lock().unwrap().split_off(0)).unwrap(), false);
+ assert_eq!(peer_a.read_event(&mut fd_a, &fd_b.outbound_data.lock().unwrap().split_off(0)).unwrap(), false);
+ (fd_a.clone(), fd_b.clone())
+ }
+
#[test]
fn test_disconnect_peer() {
// Simple test which builds a network of PeerManager, connects and brings them to NoiseState::Finished and
assert_eq!(routing_handlers_concrete[1].clone().chan_upds_recvd.load(Ordering::Acquire), 100);
assert_eq!(routing_handlers_concrete[1].clone().chan_anns_recvd.load(Ordering::Acquire), 50);
}
+
+ #[test]
+ fn limit_initial_routing_sync_requests() {
+ // Inbound peer 0 requests initial_routing_sync, but outbound peer 1 does not.
+ {
+ let chan_handlers = create_chan_handlers(2);
+ let routing_handlers: Vec<Arc<msgs::RoutingMessageHandler>> = vec![
+ Arc::new(test_utils::TestRoutingMessageHandler::new().set_request_full_sync()),
+ Arc::new(test_utils::TestRoutingMessageHandler::new()),
+ ];
+ let peers = create_network(2, &chan_handlers, Some(&routing_handlers));
+ let (fd_0_to_1, fd_1_to_0) = establish_connection_and_read_events(&peers[0], &peers[1]);
+
+ let peer_0 = peers[0].peers.lock().unwrap();
+ let peer_1 = peers[1].peers.lock().unwrap();
+
+ let peer_0_features = peer_1.peers.get(&fd_1_to_0).unwrap().their_features.as_ref();
+ let peer_1_features = peer_0.peers.get(&fd_0_to_1).unwrap().their_features.as_ref();
+
+ assert!(peer_0_features.unwrap().initial_routing_sync());
+ assert!(!peer_1_features.unwrap().initial_routing_sync());
+ }
+
+ // Outbound peer 1 requests initial_routing_sync, but inbound peer 0 does not.
+ {
+ let chan_handlers = create_chan_handlers(2);
+ let routing_handlers: Vec<Arc<msgs::RoutingMessageHandler>> = vec![
+ Arc::new(test_utils::TestRoutingMessageHandler::new()),
+ Arc::new(test_utils::TestRoutingMessageHandler::new().set_request_full_sync()),
+ ];
+ let peers = create_network(2, &chan_handlers, Some(&routing_handlers));
+ let (fd_0_to_1, fd_1_to_0) = establish_connection_and_read_events(&peers[0], &peers[1]);
+
+ let peer_0 = peers[0].peers.lock().unwrap();
+ let peer_1 = peers[1].peers.lock().unwrap();
+
+ let peer_0_features = peer_1.peers.get(&fd_1_to_0).unwrap().their_features.as_ref();
+ let peer_1_features = peer_0.peers.get(&fd_0_to_1).unwrap().their_features.as_ref();
+
+ assert!(!peer_0_features.unwrap().initial_routing_sync());
+ assert!(peer_1_features.unwrap().initial_routing_sync());
+ }
+ }
}