diff --git a/Cargo.lock b/Cargo.lock index b40c7dff..ac919057 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2548,6 +2548,7 @@ dependencies = [ "flume 0.11.0", "fnv", "futures", + "hickory-resolver", "homestar-invocation", "homestar-runtime-tests-proc-macro", "homestar-wasm", @@ -3690,6 +3691,7 @@ dependencies = [ "multihash 0.19.1", "quick-protobuf", "rand", + "ring 0.17.7", "serde", "sha2 0.10.8", "thiserror", diff --git a/homestar-runtime/Cargo.toml b/homestar-runtime/Cargo.toml index abc672b9..ceceb697 100644 --- a/homestar-runtime/Cargo.toml +++ b/homestar-runtime/Cargo.toml @@ -67,6 +67,7 @@ faststr = { workspace = true } flume = { version = "0.11", default-features = false, features = ["async"] } fnv = { version = "1.0", default-features = false } futures = { workspace = true } +hickory-resolver = { version = "0.24", default-features = false } homestar-invocation = { version = "0.1", path = "../homestar-invocation", features = [ "diesel", ] } @@ -88,6 +89,7 @@ jsonrpsee = { version = "0.21", default-features = false, features = [ ] } libipld = { workspace = true } libp2p = { version = "0.53", default-features = false, features = [ + "dns", "kad", "request-response", "rendezvous", @@ -97,6 +99,7 @@ libp2p = { version = "0.53", default-features = false, features = [ "mdns", "gossipsub", "request-response", + "rsa", "tokio", "tcp", "noise", diff --git a/homestar-runtime/src/network/swarm.rs b/homestar-runtime/src/network/swarm.rs index 195038e1..4b81c313 100644 --- a/homestar-runtime/src/network/swarm.rs +++ b/homestar-runtime/src/network/swarm.rs @@ -13,6 +13,7 @@ use enum_assoc::Assoc; use faststr::FastStr; use libp2p::{ core::upgrade, + dns, gossipsub::{self, MessageId, TopicHash}, identify, kad::{ @@ -50,7 +51,25 @@ pub(crate) async fn new(settings: &settings::Network) -> Result Result<()> { Ok(()) } + +// +#[test] +#[serial_test::parallel] +fn test_libp2p_configured_with_known_dns_multiaddr_integration() -> Result<()> { + let proc_info = ProcInfo::new().unwrap(); + let rpc_port = proc_info.rpc_port; + let metrics_port = proc_info.metrics_port; + let ws_port = proc_info.ws_port; + let listen_addr = listen_addr(proc_info.listen_port); + + let known_peer_id = "QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN"; + // from ipfs bootstrap list + let dns_node_addr = format!("/dnsaddr/bootstrap.libp2p.io/p2p/{}", known_peer_id); + let toml = format!( + r#" + [node] + [node.network.keypair_config] + existing = {{ key_type = "ed25519", path = "./fixtures/__testkey_ed25519_2.pem" }} + [node.network.libp2p] + listen_address = "{listen_addr}" + node_addresses = ["{dns_node_addr}"] + [node.network.libp2p.mdns] + enable = false + [node.network.libp2p.rendezvous] + enable_client = false + enable_server = false + [node.network.metrics] + port = {metrics_port} + [node.network.rpc] + port = {rpc_port} + [node.network.webserver] + port = {ws_port} + "# + ); + + let config = make_config!(toml); + + let homestar_proc = Command::new(BIN.as_os_str()) + .arg("start") + .arg("-c") + .arg(config.filename()) + .arg("--db") + .arg(&proc_info.db_path) + .stdout(Stdio::piped()) + .spawn() + .unwrap(); + let proc_guard = ChildGuard::new(homestar_proc); + + if wait_for_socket_connection_v6(rpc_port, 1000).is_err() { + panic!("Homestar server/runtime failed to start in time"); + } + + let dead_proc = kill_homestar(proc_guard.take(), None); + let stdout = retrieve_output(dead_proc); + + let multiaddr_not_supported = + check_for_line_with(stdout.clone(), vec!["MultiaddrNotSupported"]); + + // This can connect to known dns multiaddrs, but won't over GHA. + // let connected_to_known_peer = + // check_for_line_with(stdout, vec!["peer connection established", known_peer_id]); + // assert!(connected_to_known_peer); + + // Check that we don't receive a MultiaddrNotSupported error. + assert!(!multiaddr_not_supported); + + Ok(()) +}