Skip to content

Commit

Permalink
cleanups and PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
Frando committed Jun 12, 2024
1 parent 85e40de commit 7a032dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions iroh/examples/custom-protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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<S> {
Expand All @@ -66,8 +66,8 @@ impl<S: Store + fmt::Debug> Protocol for ExampleProto<S> {
self
}

fn accept(self: Arc<Self>, conn: quinn::Connection) -> Boxed<Result<()>> {
Box::pin(async move { self.handle_connection(conn).await })
fn handle_connection(self: Arc<Self>, conn: Connecting) -> BoxedFuture<Result<()>> {
Box::pin(async move { self.handle_connection(conn.await?).await })
}
}

Expand Down
8 changes: 4 additions & 4 deletions iroh/src/node/protocol.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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<Self>) -> Arc<dyn Any + Send + Sync>;

/// 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<Self>, conn: Connection) -> Boxed<Result<()>>;
fn handle_connection(self: Arc<Self>, conn: Connecting) -> BoxedFuture<Result<()>>;
}

0 comments on commit 7a032dc

Please sign in to comment.