diff --git a/iroh-gossip/examples/chat.rs b/iroh-gossip/examples/chat.rs index cf99a6942e..f9bf38863f 100644 --- a/iroh-gossip/examples/chat.rs +++ b/iroh-gossip/examples/chat.rs @@ -206,11 +206,11 @@ async fn handle_connection( let alpn = conn.alpn().await?; let conn = conn.await?; let peer_id = iroh_net::endpoint::get_remote_node_id(&conn)?; - match alpn.as_bytes() { - GOSSIP_ALPN => gossip - .handle_connection(conn) - .await - .context(format!("connection to {peer_id} with ALPN {alpn} failed"))?, + match alpn.as_ref() { + GOSSIP_ALPN => gossip.handle_connection(conn).await.context(format!( + "connection to {peer_id} with ALPN {} failed", + String::from_utf8_lossy(&alpn) + ))?, _ => println!("> ignoring connection from {peer_id}: unsupported ALPN protocol"), } Ok(()) diff --git a/iroh-net/examples/listen-unreliable.rs b/iroh-net/examples/listen-unreliable.rs index ded70a0f56..5850c1727a 100644 --- a/iroh-net/examples/listen-unreliable.rs +++ b/iroh-net/examples/listen-unreliable.rs @@ -67,7 +67,8 @@ async fn main() -> anyhow::Result<()> { let conn = conn.await?; let node_id = iroh_net::endpoint::get_remote_node_id(&conn)?; info!( - "new (unreliable) connection from {node_id} with ALPN {alpn} (coming from {})", + "new (unreliable) connection from {node_id} with ALPN {} (coming from {})", + String::from_utf8_lossy(&alpn), conn.remote_address() ); // spawn a task to handle reading and writing off of the connection diff --git a/iroh-net/examples/listen.rs b/iroh-net/examples/listen.rs index 9dc38ab258..a45f300254 100644 --- a/iroh-net/examples/listen.rs +++ b/iroh-net/examples/listen.rs @@ -66,7 +66,8 @@ async fn main() -> anyhow::Result<()> { let conn = conn.await?; let node_id = iroh_net::endpoint::get_remote_node_id(&conn)?; info!( - "new connection from {node_id} with ALPN {alpn} (coming from {})", + "new connection from {node_id} with ALPN {} (coming from {})", + String::from_utf8_lossy(&alpn), conn.remote_address() ); diff --git a/iroh-net/src/endpoint.rs b/iroh-net/src/endpoint.rs index 760809c1b4..cd69d67d0d 100644 --- a/iroh-net/src/endpoint.rs +++ b/iroh-net/src/endpoint.rs @@ -908,11 +908,11 @@ impl Connecting { /// Extracts the ALPN protocol from the peer's handshake data. // Note, we could totally provide this method to be on a Connection as well. But we'd // need to wrap Connection too. - pub async fn alpn(&mut self) -> Result { + pub async fn alpn(&mut self) -> Result> { let data = self.handshake_data().await?; match data.downcast::() { Ok(data) => match data.protocol { - Some(protocol) => std::string::String::from_utf8(protocol).map_err(Into::into), + Some(protocol) => Ok(protocol), None => bail!("no ALPN protocol available"), }, Err(_) => bail!("unknown handshake type"), @@ -1365,7 +1365,7 @@ mod tests { let conn = incoming.await.unwrap(); let node_id = get_remote_node_id(&conn).unwrap(); assert_eq!(node_id, src); - assert_eq!(alpn.as_bytes(), TEST_ALPN); + assert_eq!(alpn, TEST_ALPN); let (mut send, mut recv) = conn.accept_bi().await.unwrap(); let m = recv.read_to_end(100).await.unwrap(); assert_eq!(m, b"hello"); diff --git a/iroh/src/node/builder.rs b/iroh/src/node/builder.rs index 6209883388..c2cc104070 100644 --- a/iroh/src/node/builder.rs +++ b/iroh/src/node/builder.rs @@ -734,12 +734,12 @@ impl Default for GcPolicy { #[allow(clippy::too_many_arguments)] async fn handle_connection( connecting: iroh_net::endpoint::Connecting, - alpn: String, + alpn: Vec, node: Arc>, gossip: Gossip, sync: DocsEngine, ) -> Result<()> { - match alpn.as_bytes() { + match alpn.as_ref() { GOSSIP_ALPN => gossip.handle_connection(connecting.await?).await?, DOCS_ALPN => sync.handle_connection(connecting).await?, alpn if alpn == iroh_blobs::protocol::ALPN => {