Skip to content

refactor: adapt ProtocolHandler impl #28

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
51 changes: 9 additions & 42 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,5 @@ incremental = false

[patch.crates-io]
# iroh-metrics = { git = "https://github.com/n0-computer/iroh", branch = "main" }
# iroh-base = { git = "https://github.com/n0-computer/iroh", branch = "main" }
# iroh = { git = "https://github.com/n0-computer/iroh", branch = "main" }
iroh-base = { git = "https://github.com/n0-computer/iroh", branch = "main" }
iroh = { git = "https://github.com/n0-computer/iroh", branch = "main" }
4 changes: 1 addition & 3 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,4 @@ ignore = [
]

[sources]
allow-git = [
# "https://github.com/n0-computer/iroh.git",
]
allow-git = ["https://github.com/n0-computer/iroh.git"]
5 changes: 3 additions & 2 deletions examples/custom-protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ impl ProtocolHandler for BlobSearch {
///
/// The returned future runs on a newly spawned tokio task, so it can run as long as
/// the connection lasts.
fn accept(self: Arc<Self>, connecting: Connecting) -> BoxedFuture<Result<()>> {
fn accept(&self, connecting: Connecting) -> BoxedFuture<Result<()>> {
let this = self.clone();
// We have to return a boxed future from the handler.
Box::pin(async move {
// Wait for the connection to be fully established.
Expand All @@ -162,7 +163,7 @@ impl ProtocolHandler for BlobSearch {

// Now, we can perform the actual query on our local database.
let query = String::from_utf8(query_bytes)?;
let hashes = self.query_local(&query);
let hashes = this.query_local(&query);

// We want to return a list of hashes. We do the simplest thing possible, and just send
// one hash after the other. Because the hashes have a fixed size of 32 bytes, this is
Expand Down
3 changes: 1 addition & 2 deletions examples/transfer.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::{path::PathBuf, str::FromStr};

use anyhow::Result;
use iroh::{protocol::Router, Endpoint};
use iroh_base::ticket::BlobTicket;
use iroh::{protocol::Router, ticket::BlobTicket, Endpoint};
use iroh_blobs::{
net_protocol::Blobs,
rpc::client::blobs::{ReadAtLen, WrapOption},
Expand Down
18 changes: 8 additions & 10 deletions src/net_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,22 +451,20 @@ impl<S: crate::store::Store> Blobs<S> {
// }

impl<S: crate::store::Store> ProtocolHandler for Blobs<S> {
fn accept(self: Arc<Self>, conn: Connecting) -> BoxedFuture<Result<()>> {
fn accept(&self, conn: Connecting) -> BoxedFuture<Result<()>> {
let db = self.store.clone();
let events = self.events.clone();
let rt = self.rt.clone();
Box::pin(async move {
crate::provider::handle_connection(
conn.await?,
self.store.clone(),
self.events.clone(),
self.rt.clone(),
)
.await;
crate::provider::handle_connection(conn.await?, db, events, rt).await;
Ok(())
})
}

fn shutdown(self: Arc<Self>) -> BoxedFuture<()> {
fn shutdown(&self) -> BoxedFuture<()> {
let store = self.store.clone();
Box::pin(async move {
self.store.shutdown().await;
store.shutdown().await;
})
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/rpc/client/blobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -991,8 +991,10 @@ pub struct DownloadOptions {
mod tests {
use std::{path::Path, time::Duration};

use iroh::{key::SecretKey, test_utils::DnsPkarrServer, NodeId, RelayMode};
use iroh_base::{node_addr::AddrInfoOptions, ticket::BlobTicket};
use iroh::{
key::SecretKey, test_utils::DnsPkarrServer, ticket::BlobTicket, AddrInfoOptions, NodeId,
RelayMode,
};
use node::Node;
use rand::RngCore;
use testresult::TestResult;
Expand Down
Loading