Skip to content

Commit

Permalink
address PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
Frando committed Jun 19, 2024
1 parent 88a77fa commit 34ea612
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
8 changes: 4 additions & 4 deletions iroh-net/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ struct StaticConfig {
}

impl StaticConfig {
/// Build a [`quinn::ServerConfig`] with the specified ALPN protocols.
fn build(&self, alpn_protocols: Vec<Vec<u8>>) -> Result<quinn::ServerConfig> {
/// Create a [`quinn::ServerConfig`] with the specified ALPN protocols.
fn create_server_config(&self, alpn_protocols: Vec<Vec<u8>>) -> Result<quinn::ServerConfig> {
let mut server_config = make_server_config(
&self.secret_key,
alpn_protocols,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<Vec<u8>>) -> 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(())
}
Expand Down
5 changes: 4 additions & 1 deletion iroh/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ impl<D: BaoStore> Node<D> {
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<P: Protocol>(&self, alpn: &[u8]) -> Option<Arc<P>> {
self.protocols.get_typed(alpn)
}
Expand Down
16 changes: 12 additions & 4 deletions iroh/src/node/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<D, E> {
inner: Arc<NodeInner<D>>,
Expand Down Expand Up @@ -766,8 +766,8 @@ impl<D: iroh_blobs::store::Store, E: ServiceEndpoint<RpcService>> 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
}
Expand Down Expand Up @@ -797,6 +797,14 @@ impl<D: iroh_blobs::store::Store, E: ServiceEndpoint<RpcService>> 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<P: Protocol>(&self, alpn: &[u8]) -> Option<Arc<P>> {
self.protocols.get_typed(alpn)
}

/// Register the core iroh protocols (blobs, gossip, docs).
fn register_iroh_protocols(mut self) -> Self {
// Register blobs.
Expand Down

0 comments on commit 34ea612

Please sign in to comment.