+
+ #[test]
+ fn is_tor_only_node() {
+ let network_graph = create_network_graph();
+ let (secp_ctx, gossip_sync) = create_gossip_sync(&network_graph);
+
+ let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap();
+ let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap();
+ let node_1_id = NodeId::from_pubkey(&PublicKey::from_secret_key(&secp_ctx, node_1_privkey));
+
+ let announcement = get_signed_channel_announcement(|_| {}, node_1_privkey, node_2_privkey, &secp_ctx);
+ gossip_sync.handle_channel_announcement(&announcement).unwrap();
+
+ let tcp_ip_v4 = SocketAddress::TcpIpV4 {
+ addr: [255, 254, 253, 252],
+ port: 9735
+ };
+ let tcp_ip_v6 = SocketAddress::TcpIpV6 {
+ addr: [255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242, 241, 240],
+ port: 9735
+ };
+ let onion_v2 = SocketAddress::OnionV2([255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 38, 7]);
+ let onion_v3 = SocketAddress::OnionV3 {
+ ed25519_pubkey: [255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242, 241, 240, 239, 238, 237, 236, 235, 234, 233, 232, 231, 230, 229, 228, 227, 226, 225, 224],
+ checksum: 32,
+ version: 16,
+ port: 9735
+ };
+ let hostname = SocketAddress::Hostname {
+ hostname: Hostname::try_from(String::from("host")).unwrap(),
+ port: 9735,
+ };
+
+ assert!(!network_graph.read_only().node(&node_1_id).unwrap().is_tor_only());
+
+ let announcement = get_signed_node_announcement(|_| {}, node_1_privkey, &secp_ctx);
+ gossip_sync.handle_node_announcement(&announcement).unwrap();
+ assert!(!network_graph.read_only().node(&node_1_id).unwrap().is_tor_only());
+
+ let announcement = get_signed_node_announcement(
+ |announcement| {
+ announcement.addresses = vec![
+ tcp_ip_v4.clone(), tcp_ip_v6.clone(), onion_v2.clone(), onion_v3.clone(),
+ hostname.clone()
+ ];
+ announcement.timestamp += 1000;
+ },
+ node_1_privkey, &secp_ctx
+ );
+ gossip_sync.handle_node_announcement(&announcement).unwrap();
+ assert!(!network_graph.read_only().node(&node_1_id).unwrap().is_tor_only());
+
+ let announcement = get_signed_node_announcement(
+ |announcement| {
+ announcement.addresses = vec![
+ tcp_ip_v4.clone(), tcp_ip_v6.clone(), onion_v2.clone(), onion_v3.clone()
+ ];
+ announcement.timestamp += 2000;
+ },
+ node_1_privkey, &secp_ctx
+ );
+ gossip_sync.handle_node_announcement(&announcement).unwrap();
+ assert!(!network_graph.read_only().node(&node_1_id).unwrap().is_tor_only());
+
+ let announcement = get_signed_node_announcement(
+ |announcement| {
+ announcement.addresses = vec![
+ tcp_ip_v6.clone(), onion_v2.clone(), onion_v3.clone()
+ ];
+ announcement.timestamp += 3000;
+ },
+ node_1_privkey, &secp_ctx
+ );
+ gossip_sync.handle_node_announcement(&announcement).unwrap();
+ assert!(!network_graph.read_only().node(&node_1_id).unwrap().is_tor_only());
+
+ let announcement = get_signed_node_announcement(
+ |announcement| {
+ announcement.addresses = vec![onion_v2.clone(), onion_v3.clone()];
+ announcement.timestamp += 4000;
+ },
+ node_1_privkey, &secp_ctx
+ );
+ gossip_sync.handle_node_announcement(&announcement).unwrap();
+ assert!(network_graph.read_only().node(&node_1_id).unwrap().is_tor_only());
+
+ let announcement = get_signed_node_announcement(
+ |announcement| {
+ announcement.addresses = vec![onion_v2.clone()];
+ announcement.timestamp += 5000;
+ },
+ node_1_privkey, &secp_ctx
+ );
+ gossip_sync.handle_node_announcement(&announcement).unwrap();
+ assert!(network_graph.read_only().node(&node_1_id).unwrap().is_tor_only());
+
+ let announcement = get_signed_node_announcement(
+ |announcement| {
+ announcement.addresses = vec![tcp_ip_v4.clone()];
+ announcement.timestamp += 6000;
+ },
+ node_1_privkey, &secp_ctx
+ );
+ gossip_sync.handle_node_announcement(&announcement).unwrap();
+ assert!(!network_graph.read_only().node(&node_1_id).unwrap().is_tor_only());
+ }