Skip to content

Commit

Permalink
docs: fix spelling in new protocol handler docs (#2385)
Browse files Browse the repository at this point in the history
## Description

Addresses review by @flub on #2358 (which is already merged).

## Breaking Changes

<!-- Optional, if there are any breaking changes document them,
including how to migrate older code. -->

## Notes & open questions

<!-- Any notes, remarks or open questions you have to make about the PR.
-->

## Change checklist

- [x] Self-review.
- [x] Documentation updates if relevant.
- [ ] ~~Tests if relevant.~~
- [x] All breaking changes documented.
  • Loading branch information
Frando committed Jun 19, 2024
1 parent 08f1fe0 commit f73c506
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion iroh-net/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ impl Endpoint {
})
}

/// Set the list of accepted ALPN protocols.
/// Sets the list of accepted ALPN protocols.
///
/// This will only affect new incoming connections.
/// Note that this *overrides* the current list of ALPNs.
Expand Down
12 changes: 6 additions & 6 deletions iroh/src/node/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,9 @@ where
unspawned_node.spawn().await
}

/// Build a node without spawning it.
/// Builds a node without spawning it.
///
/// Returns an `ProtocolBuilder`, on which custom protocols can be registered with
/// Returns an [`ProtocolBuilder`], on which custom protocols can be registered with
/// [`ProtocolBuilder::accept`]. To spawn the node, call [`ProtocolBuilder::spawn`].
pub async fn build(self) -> Result<ProtocolBuilder<D, E>> {
// Clone the blob store to shutdown in case of error.
Expand Down Expand Up @@ -532,7 +532,7 @@ pub struct ProtocolBuilder<D, E> {
}

impl<D: iroh_blobs::store::Store, E: ServiceEndpoint<RpcService>> ProtocolBuilder<D, E> {
/// Register a protocol handler for incoming connections.
/// Registers a protocol handler for incoming connections.
///
/// Use this to register custom protocols onto the iroh node. Whenever a new connection for
/// `alpn` comes in, it is passed to this protocol handler.
Expand Down Expand Up @@ -585,7 +585,7 @@ impl<D: iroh_blobs::store::Store, E: ServiceEndpoint<RpcService>> ProtocolBuilde
self
}

/// Return a client to control this node over an in-memory channel.
/// Returns a client to control this node over an in-memory channel.
///
/// Note that RPC calls performed with the client will not complete until the node is
/// spawned.
Expand Down Expand Up @@ -626,7 +626,7 @@ impl<D: iroh_blobs::store::Store, E: ServiceEndpoint<RpcService>> ProtocolBuilde
self.protocols.get_typed(alpn)
}

/// Register the core iroh protocols (blobs, gossip, docs).
/// Registers the core iroh protocols (blobs, gossip, docs).
fn register_iroh_protocols(mut self) -> Self {
// Register blobs.
let blobs_proto =
Expand All @@ -644,7 +644,7 @@ impl<D: iroh_blobs::store::Store, E: ServiceEndpoint<RpcService>> ProtocolBuilde
self
}

/// Spawn the node and start accepting connections.
/// Spawns the node and starts accepting connections.
pub async fn spawn(self) -> Result<Node<D>> {
let Self {
inner,
Expand Down
14 changes: 7 additions & 7 deletions iroh/src/node/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,32 @@ pub(super) struct ProtocolMap(BTreeMap<&'static [u8], Arc<dyn ProtocolHandler>>)

impl ProtocolMap {
/// Returns the registered protocol handler for an ALPN as a concrete type.
pub fn get_typed<P: ProtocolHandler>(&self, alpn: &[u8]) -> Option<Arc<P>> {
pub(super) fn get_typed<P: ProtocolHandler>(&self, alpn: &[u8]) -> Option<Arc<P>> {
let protocol: Arc<dyn ProtocolHandler> = self.0.get(alpn)?.clone();
let protocol_any: Arc<dyn Any + Send + Sync> = protocol.into_arc_any();
let protocol_ref = Arc::downcast(protocol_any).ok()?;
Some(protocol_ref)
}

/// Returns the registered protocol handler for an ALPN as a [`Arc<dyn ProtocolHandler>`].
pub fn get(&self, alpn: &[u8]) -> Option<Arc<dyn ProtocolHandler>> {
pub(super) fn get(&self, alpn: &[u8]) -> Option<Arc<dyn ProtocolHandler>> {
self.0.get(alpn).cloned()
}

/// Insert a protocol handler.
pub fn insert(&mut self, alpn: &'static [u8], handler: Arc<dyn ProtocolHandler>) {
/// Inserts a protocol handler.
pub(super) fn insert(&mut self, alpn: &'static [u8], handler: Arc<dyn ProtocolHandler>) {
self.0.insert(alpn, handler);
}

/// Returns an iterator of all registered ALPN protocol identifiers.
pub fn alpns(&self) -> impl Iterator<Item = &&[u8]> {
pub(super) fn alpns(&self) -> impl Iterator<Item = &&[u8]> {
self.0.keys()
}

/// Shutdown all protocol handlers.
/// Shuts down all protocol handlers.
///
/// Calls and awaits [`ProtocolHandler::shutdown`] for all registered handlers concurrently.
pub async fn shutdown(&self) {
pub(super) async fn shutdown(&self) {
let handlers = self.0.values().cloned().map(ProtocolHandler::shutdown);
join_all(handlers).await;
}
Expand Down

0 comments on commit f73c506

Please sign in to comment.