diff --git a/hole-punching-tests/src/main.rs b/hole-punching-tests/src/main.rs index 5e86ecf24b8..fd4616e1629 100644 --- a/hole-punching-tests/src/main.rs +++ b/hole-punching-tests/src/main.rs @@ -20,8 +20,6 @@ use anyhow::{Context, Result}; use futures::stream::StreamExt; -use libp2p::swarm::dial_opts::DialOpts; -use libp2p::swarm::ConnectionId; use libp2p::{ core::multiaddr::{Multiaddr, Protocol}, dcutr, identify, noise, ping, relay, @@ -85,10 +83,6 @@ async fn main() -> Result<()> { .build(); client_listen_on_transport(&mut swarm, transport).await?; - let relay_conn_id = client_connect_to_relay(&mut swarm, relay_addr.clone()) - .await - .context("Failed to connect to relay")?; - client_setup(&mut swarm, &mut redis, relay_addr.clone(), mode).await?; let mut hole_punched_peer_connection = None; @@ -118,8 +112,6 @@ async fn main() -> Result<()> { ) => { log::info!("Successfully hole-punched to {remote_peer_id}"); - // Closing the connection to the relay will implicitly close the relayed connection to the other peer. - swarm.close_connection(relay_conn_id); hole_punched_peer_connection = Some(connection_id); } ( @@ -150,19 +142,6 @@ async fn main() -> Result<()> { (SwarmEvent::OutgoingConnectionError { error, .. }, _) => { anyhow::bail!(error) } - ( - SwarmEvent::ConnectionClosed { - connection_id, - cause: Some(error), - .. - }, - _, - ) if connection_id == relay_conn_id => { - log::warn!("Connection to relay failed: {error}"); - - // TODO: Re-connecting is a bit of a hack, we should figure out why the connection sometimes fails. - client_setup(&mut swarm, &mut redis, relay_addr.clone(), mode).await?; - } _ => {} } } @@ -194,40 +173,6 @@ where Ok(val) } -async fn client_connect_to_relay( - swarm: &mut Swarm, - relay_addr: Multiaddr, -) -> Result { - let opts = DialOpts::from(relay_addr); - let relay_connection_id = opts.connection_id(); - - // Connect to the relay server. - swarm.dial(opts)?; - - loop { - match swarm.next().await.unwrap() { - SwarmEvent::Behaviour(BehaviourEvent::Identify(identify::Event::Received { - info: identify::Info { observed_addr, .. }, - .. - })) => { - log::info!("Relay told us our public address: {observed_addr}"); - break; - } - SwarmEvent::ConnectionEstablished { connection_id, .. } - if connection_id == relay_connection_id => - { - log::info!("Connected to the relay"); - } - SwarmEvent::OutgoingConnectionError { error, .. } => { - anyhow::bail!(error) - } - _ => {} - } - } - - Ok(relay_connection_id) -} - async fn client_listen_on_transport( swarm: &mut Swarm, transport: TransportProtocol,