From 7a032dc4faf5a88200db9b836024eb2010d71d48 Mon Sep 17 00:00:00 2001 From: "Franz Heinzmann (Frando)" Date: Wed, 12 Jun 2024 17:49:34 +0200 Subject: [PATCH] cleanups and PR review --- iroh/examples/custom-protocol.rs | 10 +++++----- iroh/src/node/protocol.rs | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/iroh/examples/custom-protocol.rs b/iroh/examples/custom-protocol.rs index f898b75ed3a..5507e3b0987 100644 --- a/iroh/examples/custom-protocol.rs +++ b/iroh/examples/custom-protocol.rs @@ -2,11 +2,11 @@ use std::{any::Any, fmt, sync::Arc}; use anyhow::Result; use clap::Parser; -use futures_lite::future::Boxed; +use futures_lite::future::Boxed as BoxedFuture; use iroh::{ blobs::store::Store, net::{ - endpoint::{get_remote_node_id, Connection}, + endpoint::{get_remote_node_id, Connecting, Connection}, NodeId, }, node::{Node, Protocol}, @@ -54,7 +54,7 @@ async fn main() -> Result<()> { Ok(()) } -const EXAMPLE_ALPN: &'static [u8] = b"example-proto/0"; +const EXAMPLE_ALPN: &[u8] = b"example-proto/0"; #[derive(Debug)] struct ExampleProto { @@ -66,8 +66,8 @@ impl Protocol for ExampleProto { self } - fn accept(self: Arc, conn: quinn::Connection) -> Boxed> { - Box::pin(async move { self.handle_connection(conn).await }) + fn handle_connection(self: Arc, conn: Connecting) -> BoxedFuture> { + Box::pin(async move { self.handle_connection(conn.await?).await }) } } diff --git a/iroh/src/node/protocol.rs b/iroh/src/node/protocol.rs index 55046952e60..dd9db9d84c4 100644 --- a/iroh/src/node/protocol.rs +++ b/iroh/src/node/protocol.rs @@ -1,8 +1,8 @@ use std::{any::Any, fmt, sync::Arc}; use anyhow::Result; -use futures_lite::future::Boxed; -use iroh_net::endpoint::Connection; +use futures_lite::future::Boxed as BoxedFuture; +use iroh_net::endpoint::Connecting; /// Trait for iroh protocol handlers. pub trait Protocol: Send + Sync + Any + fmt::Debug + 'static { @@ -11,8 +11,8 @@ pub trait Protocol: Send + Sync + Any + fmt::Debug + 'static { /// Implementations can simply return `self` here. fn as_arc_any(self: Arc) -> Arc; - /// Accept an incoming connection. + /// Handle an incoming connection. /// /// This runs on a freshly spawned tokio task so this can be long-running. - fn accept(self: Arc, conn: Connection) -> Boxed>; + fn handle_connection(self: Arc, conn: Connecting) -> BoxedFuture>; }