Skip to content

Commit f864497

Browse files
authored
Merge pull request #1286 from nervosnetwork/copilot/fix-graph-nodes-rpc-onion-addresses
fix: include onion3 addresses when storing remote node announcements in graph
2 parents 9d0efb8 + 2ae3f80 commit f864497

2 files changed

Lines changed: 56 additions & 4 deletions

File tree

crates/fiber-lib/src/fiber/tests/utils.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,53 @@
1+
use std::str::FromStr;
2+
13
use tempfile::NamedTempFile;
4+
use tentacle::multiaddr::Multiaddr;
25

36
use crate::utils::encrypt_decrypt_file::decrypt_from_file;
47
use crate::utils::encrypt_decrypt_file::encrypt_to_file;
8+
use crate::utils::is_addr_reachable;
9+
10+
#[test]
11+
fn test_is_addr_reachable_with_onion3_address() {
12+
let onion3_addr = Multiaddr::from_str(
13+
"/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:8228",
14+
)
15+
.expect("valid onion3 multiaddr");
16+
assert!(
17+
is_addr_reachable(&onion3_addr),
18+
"onion3 address should be considered reachable"
19+
);
20+
}
21+
22+
#[test]
23+
fn test_is_addr_reachable_with_private_ip() {
24+
let private_addr =
25+
Multiaddr::from_str("/ip4/192.168.1.1/tcp/8228").expect("valid private ip multiaddr");
26+
assert!(
27+
!is_addr_reachable(&private_addr),
28+
"private IP address should not be considered reachable"
29+
);
30+
}
31+
32+
#[test]
33+
fn test_is_addr_reachable_with_public_ip() {
34+
let public_addr =
35+
Multiaddr::from_str("/ip4/1.1.1.1/tcp/8228").expect("valid public ip multiaddr");
36+
assert!(
37+
is_addr_reachable(&public_addr),
38+
"public IP address should be considered reachable"
39+
);
40+
}
41+
42+
#[test]
43+
fn test_is_addr_reachable_with_dns4_address() {
44+
let dns4_addr =
45+
Multiaddr::from_str("/dns4/example.com/tcp/8228").expect("valid dns4 multiaddr");
46+
assert!(
47+
is_addr_reachable(&dns4_addr),
48+
"dns4 address should be considered reachable"
49+
);
50+
}
551

652
#[test]
753
fn test_encrypt_and_decrypt_success() {

crates/fiber-lib/src/utils/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,18 @@ use tentacle::utils::{is_reachable, multiaddr_to_socketaddr};
1313
///
1414
/// For DNS-based addresses (`Dns4`/`Dns6`), we treat them as always reachable
1515
/// because a DNS name implies a publicly resolvable endpoint.
16+
///
17+
/// For Tor onion addresses (`Onion3`), we treat them as always reachable
18+
/// because they are publicly accessible via the Tor network.
1619
pub(crate) fn is_addr_reachable(addr: &Multiaddr) -> bool {
17-
let has_dns = addr
18-
.iter()
19-
.any(|proto| matches!(proto, Protocol::Dns4(_) | Protocol::Dns6(_)));
20+
let has_public_protocol = addr.iter().any(|proto| {
21+
matches!(
22+
proto,
23+
Protocol::Dns4(_) | Protocol::Dns6(_) | Protocol::Onion3(_)
24+
)
25+
});
2026

21-
if has_dns {
27+
if has_public_protocol {
2228
return true;
2329
}
2430

0 commit comments

Comments
 (0)