Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(iroh-router)!: change accept to take an AsRef<[u8]> #2963

Merged
merged 3 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion iroh-router/examples/custom-protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ async fn main() -> Result<()> {
let builder = Router::builder(endpoint);

// Add our protocol, identified by our ALPN, to the node, and spawn the node.
let router = builder.accept(ALPN.to_vec(), proto.clone()).spawn().await?;
let router = builder.accept(ALPN, proto.clone()).spawn().await?;

match args.command {
Command::Listen { text } => {
Expand Down
4 changes: 2 additions & 2 deletions iroh-router/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ impl RouterBuilder {
}
}

pub fn accept(mut self, alpn: Vec<u8>, handler: Arc<dyn ProtocolHandler>) -> Self {
self.protocols.insert(alpn, handler);
pub fn accept(mut self, alpn: impl AsRef<[u8]>, handler: Arc<dyn ProtocolHandler>) -> Self {
self.protocols.insert(alpn.as_ref().to_vec(), handler);
self
}

Expand Down
2 changes: 1 addition & 1 deletion iroh/examples/custom-protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ async fn main() -> Result<()> {
let proto = BlobSearch::new(builder.client().blobs().clone(), builder.endpoint().clone());

// Add our protocol, identified by our ALPN, to the node, and spawn the node.
let node = builder.accept(ALPN.to_vec(), proto.clone()).spawn().await?;
let node = builder.accept(ALPN, proto.clone()).spawn().await?;

match args.command {
Command::Listen { text } => {
Expand Down
10 changes: 5 additions & 5 deletions iroh/src/node/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,14 +791,14 @@ impl<D: iroh_blobs::store::Store> ProtocolBuilder<D> {
/// let handler = MyProtocol { client };
///
/// let node = unspawned_node
/// .accept(MY_ALPN.to_vec(), Arc::new(handler))
/// .accept(MY_ALPN, Arc::new(handler))
/// .spawn()
/// .await?;
/// # node.shutdown().await?;
/// # Ok(())
/// # }
/// ```
pub fn accept(mut self, alpn: Vec<u8>, handler: Arc<dyn ProtocolHandler>) -> Self {
pub fn accept(mut self, alpn: impl AsRef<[u8]>, handler: Arc<dyn ProtocolHandler>) -> Self {
self.router = self.router.accept(alpn, handler);
self
}
Expand Down Expand Up @@ -846,14 +846,14 @@ impl<D: iroh_blobs::store::Store> ProtocolBuilder<D> {
downloader,
self.endpoint().clone(),
);
self = self.accept(iroh_blobs::protocol::ALPN.to_vec(), Arc::new(blobs_proto));
self = self.accept(iroh_blobs::protocol::ALPN, Arc::new(blobs_proto));

// Register gossip.
self = self.accept(GOSSIP_ALPN.to_vec(), Arc::new(gossip));
self = self.accept(GOSSIP_ALPN, Arc::new(gossip));

// Register docs, if enabled.
if let Some(docs) = docs {
self = self.accept(DOCS_ALPN.to_vec(), Arc::new(docs));
self = self.accept(DOCS_ALPN, Arc::new(docs));
}

self
Expand Down
Loading