Add Iroh peer ping
This commit is contained in:
parent
8ab3ef004e
commit
679eeb48a3
15 changed files with 619 additions and 18 deletions
|
|
@ -26,4 +26,5 @@ geth-ssh-identity = { path = "../geth-ssh-identity" }
|
|||
geth-store = { path = "../geth-store" }
|
||||
geth-types = { path = "../geth-types" }
|
||||
rusqlite.workspace = true
|
||||
serde_json.workspace = true
|
||||
tempfile.workspace = true
|
||||
|
|
|
|||
|
|
@ -103,6 +103,87 @@ fn geth_status_against_running_daemon() {
|
|||
assert!(stdout.contains("iroh discovery: local-network disabled"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn peer_ping_uses_daemon_owned_iroh_endpoint() {
|
||||
let left_home = tempfile::tempdir().expect("left tempdir");
|
||||
let right_home = tempfile::tempdir().expect("right tempdir");
|
||||
if !unix_sockets_available(left_home.path()) || !unix_sockets_available(right_home.path()) {
|
||||
return;
|
||||
}
|
||||
assert!(run_geth(left_home.path(), &["init"]).status.success());
|
||||
assert!(run_geth(right_home.path(), &["init"]).status.success());
|
||||
for home in [left_home.path(), right_home.path()] {
|
||||
std::fs::write(
|
||||
home.join("config.toml"),
|
||||
"[iroh]\nrelay_mode = \"disabled\"\nlocal_discovery = false\n",
|
||||
)
|
||||
.expect("write config");
|
||||
}
|
||||
|
||||
let mut left_daemon = spawn_daemon(left_home.path());
|
||||
let mut right_daemon = spawn_daemon(right_home.path());
|
||||
wait_for_socket(&left_home.path().join("run/geth.sock"));
|
||||
wait_for_socket(&right_home.path().join("run/geth.sock"));
|
||||
|
||||
let left_card = left_home.path().join("left-peer-card.json");
|
||||
let right_card = right_home.path().join("right-peer-card.json");
|
||||
let left_export = run_geth(
|
||||
left_home.path(),
|
||||
&["peer", "export", "--out", left_card.to_str().unwrap()],
|
||||
);
|
||||
let right_export = run_geth(
|
||||
right_home.path(),
|
||||
&["peer", "export", "--out", right_card.to_str().unwrap()],
|
||||
);
|
||||
assert!(
|
||||
left_export.status.success(),
|
||||
"left export stderr: {}",
|
||||
String::from_utf8_lossy(&left_export.stderr)
|
||||
);
|
||||
assert!(
|
||||
right_export.status.success(),
|
||||
"right export stderr: {}",
|
||||
String::from_utf8_lossy(&right_export.stderr)
|
||||
);
|
||||
let import = run_geth(
|
||||
left_home.path(),
|
||||
&["peer", "import", right_card.to_str().unwrap()],
|
||||
);
|
||||
assert!(
|
||||
import.status.success(),
|
||||
"import stderr: {}",
|
||||
String::from_utf8_lossy(&import.stderr)
|
||||
);
|
||||
let right_card_json =
|
||||
std::fs::read_to_string(&right_card).expect("read right exported peer card");
|
||||
let right_card: geth_discovery::PeerCard =
|
||||
serde_json::from_str(&right_card_json).expect("decode right peer card");
|
||||
assert!(
|
||||
right_card.endpoints[0]
|
||||
.direct_addresses
|
||||
.iter()
|
||||
.any(|addr| addr.contains("127.0.0.1") || addr.contains("[::1]"))
|
||||
);
|
||||
|
||||
let ping = run_geth(
|
||||
left_home.path(),
|
||||
&["peer", "ping", right_card.node_id.as_str()],
|
||||
);
|
||||
let _ = left_daemon.kill();
|
||||
let _ = right_daemon.kill();
|
||||
let _ = left_daemon.wait();
|
||||
let _ = right_daemon.wait();
|
||||
|
||||
assert!(
|
||||
ping.status.success(),
|
||||
"ping stderr: {}",
|
||||
String::from_utf8_lossy(&ping.stderr)
|
||||
);
|
||||
let stdout = String::from_utf8_lossy(&ping.stdout);
|
||||
assert!(stdout.contains("peer pong:"));
|
||||
assert!(stdout.contains("candidate status does not grant resource capabilities"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn peer_card_export_import_and_list_are_candidate_only() {
|
||||
let source_home = tempfile::tempdir().expect("source tempdir");
|
||||
|
|
|
|||
Loading…
Reference in a new issue