diff --git a/src/iroh.rs b/src/iroh.rs index 0ce9c2d..21217f3 100644 --- a/src/iroh.rs +++ b/src/iroh.rs @@ -418,28 +418,31 @@ impl NodeHost { } async fn connect_to_peer(&self, peer_address: EndpointAddr) -> anyhow::Result { - let connection = tokio::time::timeout( - CONTROL_REQUEST_TIMEOUT, - self.endpoint.connect(peer_address.clone(), APPA_ALPN), - ) - .await - .map_err(|_| anyhow::anyhow!("Appa peer connection timed out"))??; - verify_connected_peer(&connection, &peer_address)?; - Ok(connection) + self.connect_with_alpn(peer_address, APPA_ALPN, "Appa peer") + .await } async fn connect_to_blob_provider( &self, provider_address: EndpointAddr, + ) -> anyhow::Result { + self.connect_with_alpn(provider_address, iroh_blobs::ALPN, "Appa blob provider") + .await + } + + async fn connect_with_alpn( + &self, + peer_address: EndpointAddr, + alpn: &[u8], + connection_name: &str, ) -> anyhow::Result { let connection = tokio::time::timeout( CONTROL_REQUEST_TIMEOUT, - self.endpoint - .connect(provider_address.clone(), iroh_blobs::ALPN), + self.endpoint.connect(peer_address.clone(), alpn), ) .await - .map_err(|_| anyhow::anyhow!("Appa blob provider connection timed out"))??; - verify_connected_peer(&connection, &provider_address)?; + .map_err(|_| anyhow::anyhow!("{connection_name} connection timed out"))??; + verify_connected_peer(&connection, &peer_address)?; Ok(connection) }