From 34ea612e732dfa02ddb68841f2d7c42cff11f0c9 Mon Sep 17 00:00:00 2001 From: "Franz Heinzmann (Frando)" Date: Wed, 19 Jun 2024 12:13:31 +0200 Subject: [PATCH] address PR review --- iroh-net/src/endpoint.rs | 8 ++++---- iroh/src/node.rs | 5 ++++- iroh/src/node/builder.rs | 16 ++++++++++++---- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/iroh-net/src/endpoint.rs b/iroh-net/src/endpoint.rs index b8a81342de..b741f47178 100644 --- a/iroh-net/src/endpoint.rs +++ b/iroh-net/src/endpoint.rs @@ -303,8 +303,8 @@ struct StaticConfig { } impl StaticConfig { - /// Build a [`quinn::ServerConfig`] with the specified ALPN protocols. - fn build(&self, alpn_protocols: Vec>) -> Result { + /// Create a [`quinn::ServerConfig`] with the specified ALPN protocols. + fn create_server_config(&self, alpn_protocols: Vec>) -> Result { let mut server_config = make_server_config( &self.secret_key, alpn_protocols, @@ -388,7 +388,7 @@ impl Endpoint { let msock = magicsock::MagicSock::spawn(msock_opts).await?; trace!("created magicsock"); - let server_config = static_config.build(initial_alpns)?; + let server_config = static_config.create_server_config(initial_alpns)?; let mut endpoint_config = quinn::EndpointConfig::default(); // Setting this to false means that quinn will ignore packets that have the QUIC fixed bit @@ -420,7 +420,7 @@ impl Endpoint { /// This will only affect new incoming connections. /// Note that this *overrides* the current list of ALPNs. pub fn set_alpns(&self, alpns: Vec>) -> Result<()> { - let server_config = self.static_config.build(alpns)?; + let server_config = self.static_config.create_server_config(alpns)?; self.endpoint.set_server_config(Some(server_config)); Ok(()) } diff --git a/iroh/src/node.rs b/iroh/src/node.rs index c88de2aa9e..93f45001c3 100644 --- a/iroh/src/node.rs +++ b/iroh/src/node.rs @@ -176,7 +176,10 @@ impl Node { self.inner.cancel_token.clone() } - /// Get a protocol handler. + /// Returns a protocol handler for an ALPN. + /// + /// This downcasts to the concrete type and returns `None` if the handler registered for `alpn` + /// does not match the passed type. pub fn get_protocol(&self, alpn: &[u8]) -> Option> { self.protocols.get_typed(alpn) } diff --git a/iroh/src/node/builder.rs b/iroh/src/node/builder.rs index 420d693bc0..eb0ef4f9a2 100644 --- a/iroh/src/node/builder.rs +++ b/iroh/src/node/builder.rs @@ -696,8 +696,8 @@ where /// [`Self::accept`]. It provides access to the services which are already started, the node's /// endpoint and a client to the node. /// -/// Note that the client returned from [`Self::client`] can only be used after spawning the node, -/// until then all RPC calls will time out. +/// Note that RPC calls performed with client returned from [`Self::client`] will not complete +/// until the node is spawned. #[derive(derive_more::Debug)] pub struct UnspawnedNode { inner: Arc>, @@ -766,8 +766,8 @@ impl> UnspawnedNode< /// Return a client to control this node over an in-memory channel. /// - /// Note that the client can only be used after spawning the node, - /// until then all RPC calls will time out. + /// Note that RPC calls performed with the client will not complete until the node is + /// spawned. pub fn client(&self) -> &crate::client::MemIroh { &self.client } @@ -797,6 +797,14 @@ impl> UnspawnedNode< &self.inner.gossip } + /// Returns a protocol handler for an ALPN. + /// + /// This downcasts to the concrete type and returns `None` if the handler registered for `alpn` + /// does not match the passed type. + pub fn get_protocol(&self, alpn: &[u8]) -> Option> { + self.protocols.get_typed(alpn) + } + /// Register the core iroh protocols (blobs, gossip, docs). fn register_iroh_protocols(mut self) -> Self { // Register blobs.