Skip to content

Commit

Permalink
write test that ensures we launch discovery if we do not have address…
Browse files Browse the repository at this point in the history
… info for a given node_id
  • Loading branch information
ramfox committed Apr 25, 2024
1 parent 8b483b8 commit 209789e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 34 deletions.
28 changes: 28 additions & 0 deletions iroh-net/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,34 @@ mod test_dns_pkarr {
Ok(())
}

#[tokio::test]
async fn pkarr_publish_dns_discover_empty_node_addr() -> Result<()> {
let _logging_guard = iroh_test::logging::setup();

let origin = "testdns.example".to_string();
let timeout = Duration::from_secs(2);

let (nameserver, pkarr_url, state, _dns_drop_guard, _pkarr_drop_guard) =
run_dns_and_pkarr_servers(&origin).await?;
let (relay_map, _relay_url, _relay_guard) = run_relay_server().await?;

let ep1 = ep_with_discovery(relay_map.clone(), nameserver, &origin, &pkarr_url).await?;
let ep2 = ep_with_discovery(relay_map, nameserver, &origin, &pkarr_url).await?;

// wait until our shared state received the update from pkarr publishing
state.on_node(&ep1.node_id(), timeout).await?;

let node_addr = NodeAddr::new(ep1.node_id());

// add empty node address. We *should* launch discovery before attempting to dial.
ep2.add_node_addr(node_addr)?;

// we connect only by node id!
let res = ep2.connect(ep1.node_id().into(), TEST_ALPN).await;
assert!(res.is_ok(), "connection established");
Ok(())
}

async fn ep_with_discovery(
relay_map: RelayMap,
nameserver: SocketAddr,
Expand Down
34 changes: 0 additions & 34 deletions iroh-net/src/magic_endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1094,38 +1094,4 @@ mod tests {
res_ep1.await.unwrap().unwrap();
res_ep2.await.unwrap().unwrap();
}

#[tokio::test]
async fn test_dial_via_node_id_only() -> Result<()> {
// set up pkarr dns server
// start two magic endpoints w/ discovery
// dial one

// let _logging_guard = iroh_test::logging::setup();
// let (relay_map, relay_url, _relay_guard) = run_relay_server().await.unwrap();

// pkarr dns server
// let (nameserver, pkarr_url, state, pkarr_task) = iroh::net::discovery::test::run_dns_and_pkarr_servers();

// let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(42);
// let ep1_secret_key = SecretKey::generate_with_rng(&mut rng);
// let ep2_secret_key = SecretKey::generate_with_rng(&mut rng);
// let ep1 = MagicEndpoint::builder()
// .secret_key(ep1_secret_key)
// .insecure_skip_relay_cert_verify(true)
// .alpns(vec![TEST_ALPN.to_vec()])
// .relay_mode(RelayMode::Custom(relay_map.clone()))
// .bind(0)
// .await
// .unwrap();
// let ep2 = MagicEndpoint::builder()
// .secret_key(ep2_secret_key)
// .insecure_skip_relay_cert_verify(true)
// .alpns(vec![TEST_ALPN.to_vec()])
// .relay_mode(RelayMode::Custom(relay_map))
// .bind(0)
// .await
// .unwrap();
todo!();
}
}

0 comments on commit 209789e

Please sign in to comment.