Skip to content

Commit

Permalink
fix: add handling of dns multiaddrs
Browse files Browse the repository at this point in the history
  • Loading branch information
zeeshanlakhani committed Feb 2, 2024
1 parent d420416 commit 02f07f4
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions homestar-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
] }
Expand All @@ -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",
Expand All @@ -97,6 +99,7 @@ libp2p = { version = "0.53", default-features = false, features = [
"mdns",
"gossipsub",
"request-response",
"rsa",
"tokio",
"tcp",
"noise",
Expand Down
21 changes: 20 additions & 1 deletion homestar-runtime/src/network/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use enum_assoc::Assoc;
use faststr::FastStr;
use libp2p::{
core::upgrade,
dns,
gossipsub::{self, MessageId, TopicHash},
identify,
kad::{
Expand Down Expand Up @@ -50,7 +51,25 @@ pub(crate) async fn new(settings: &settings::Network) -> Result<Swarm<ComposedBe
"local peer ID generated"
);

let transport = tcp::tokio::Transport::new(tcp::Config::default().nodelay(true))
let transport_tcp = tcp::tokio::Transport::new(tcp::Config::default().nodelay(true));
let transport_tcp_with_dns =
if let Ok((conf, opts)) = hickory_resolver::system_conf::read_system_conf() {
info!(
subject = "swarm.init",
category = "libp2p.swarm",
"using system DNS configuration from /etc/resolv.conf"
);
dns::tokio::Transport::custom(transport_tcp, conf, opts)
} else {
info!(
subject = "swarm.init",
category = "libp2p.swarm",
"using OS DNS configuration"
);
dns::tokio::Transport::system(transport_tcp)?
};

let transport = transport_tcp_with_dns
.upgrade(upgrade::Version::V1Lazy)
.authenticate(noise::Config::new(&keypair)?)
.multiplex(yamux::Config::default())
Expand Down
69 changes: 69 additions & 0 deletions homestar-runtime/tests/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,3 +571,72 @@ fn test_libp2p_disconnect_known_peers_integration() -> 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(())
}

0 comments on commit 02f07f4

Please sign in to comment.