From 6b094d32885687f82c453fc4b86540226e5f836e Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Thu, 5 Dec 2024 14:28:42 +0100 Subject: [PATCH 1/5] feat: update to new protocolhandler --- Cargo.lock | 145 ++++++++++++++++------------------------ Cargo.toml | 7 +- src/net_protocol.rs | 84 ++++------------------- src/rpc.rs | 8 +-- src/rpc/client/blobs.rs | 6 +- tests/gc.rs | 3 +- 6 files changed, 81 insertions(+), 172 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a13cfb97f..75af50fe5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -129,9 +129,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.93" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775" +checksum = "c1fd03a028ef38ba2276dce7e33fcd6369c158a1bca17946c4b1b701891c1ff7" [[package]] name = "arrayref" @@ -251,7 +251,7 @@ dependencies = [ "axum-core", "bytes", "futures-util", - "http 1.1.0", + "http 1.2.0", "http-body", "http-body-util", "hyper", @@ -284,7 +284,7 @@ dependencies = [ "async-trait", "bytes", "futures-util", - "http 1.1.0", + "http 1.2.0", "http-body", "http-body-util", "mime", @@ -523,9 +523,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.21" +version = "4.5.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb3b4b9e5a7c7514dfa52869339ee98b3156b0bfb4e8a77c4ff4babb64b1604f" +checksum = "69371e34337c4c984bbe322360c2547210bf632eb2814bbe78a6e87a2935bd2b" dependencies = [ "clap_builder", "clap_derive", @@ -533,9 +533,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.21" +version = "4.5.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b17a95aa67cc7b5ebd32aa5370189aa0d79069ef1c64ce893bd30fb24bff20ec" +checksum = "6e24c1b4099818523236a8ca881d2b45db98dadfb4625cf6608c12069fcbbde1" dependencies = [ "anstream", "anstyle", @@ -1418,7 +1418,7 @@ dependencies = [ "fnv", "futures-core", "futures-sink", - "http 1.1.0", + "http 1.2.0", "indexmap", "slab", "tokio", @@ -1605,9 +1605,9 @@ dependencies = [ [[package]] name = "http" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +checksum = "f16ca2af56261c99fba8bac40a10251ce8188205a4c448fbb745a2e4daa76fea" dependencies = [ "bytes", "fnv", @@ -1621,7 +1621,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ "bytes", - "http 1.1.0", + "http 1.2.0", ] [[package]] @@ -1632,7 +1632,7 @@ checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" dependencies = [ "bytes", "futures-util", - "http 1.1.0", + "http 1.2.0", "http-body", "pin-project-lite", ] @@ -1659,7 +1659,7 @@ dependencies = [ "futures-channel", "futures-util", "h2", - "http 1.1.0", + "http 1.2.0", "http-body", "httparse", "httpdate", @@ -1677,7 +1677,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ "futures-util", - "http 1.1.0", + "http 1.2.0", "hyper", "hyper-util", "rustls", @@ -1697,7 +1697,7 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "http 1.1.0", + "http 1.2.0", "http-body", "hyper", "pin-project-lite", @@ -1899,7 +1899,7 @@ dependencies = [ "attohttpc", "bytes", "futures", - "http 1.1.0", + "http 1.2.0", "http-body-util", "hyper", "hyper-util", @@ -1981,14 +1981,14 @@ checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" [[package]] name = "iroh" version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80b15215aea8d0367fefb9264521e4a251dc4e113896a3d765f530378518188f" +source = "git+https://github.com/n0-computer/iroh#321d8ffd3d2bde2f1a80e78eab1ad83687484fc2" dependencies = [ "anyhow", "axum", "backoff", "base64", "bytes", + "concurrent-queue", "der", "derive_more", "futures-buffered", @@ -2002,7 +2002,7 @@ dependencies = [ "hickory-proto 0.25.0-alpha.2", "hickory-resolver", "hostname 0.4.0", - "http 1.1.0", + "http 1.2.0", "http-body-util", "hyper", "hyper-util", @@ -2043,12 +2043,12 @@ dependencies = [ "stun-rs", "surge-ping", "swarm-discovery", - "thiserror 2.0.3", + "thiserror 2.0.4", "time", "tokio", "tokio-rustls", "tokio-stream", - "tokio-tungstenite 0.24.0", + "tokio-tungstenite", "tokio-tungstenite-wasm", "tokio-util", "tracing", @@ -2064,8 +2064,7 @@ dependencies = [ [[package]] name = "iroh-base" version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fd98293ce8e85e6b4f0ce09af7c6bb860f2fece8fcf9238d6e628f1e163e27a" +source = "git+https://github.com/n0-computer/iroh#321d8ffd3d2bde2f1a80e78eab1ad83687484fc2" dependencies = [ "aead", "anyhow", @@ -2083,7 +2082,7 @@ dependencies = [ "redb 2.2.0", "serde", "ssh-key", - "thiserror 2.0.3", + "thiserror 2.0.4", "ttl_cache", "url", "zeroize", @@ -2155,7 +2154,7 @@ dependencies = [ "tempfile", "testdir", "testresult", - "thiserror 2.0.3", + "thiserror 2.0.4", "tokio", "tokio-util", "tracing", @@ -2201,8 +2200,7 @@ dependencies = [ [[package]] name = "iroh-net-report" version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b82dc449d537176fc90749ae0711c6f81479053086928a2f2bb87cb52646ba74" +source = "git+https://github.com/n0-computer/iroh#321d8ffd3d2bde2f1a80e78eab1ad83687484fc2" dependencies = [ "anyhow", "bytes", @@ -2278,8 +2276,7 @@ dependencies = [ [[package]] name = "iroh-relay" version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28a0d0d7317795a01caa47ffdaeec84211d1b394530bdb31dbe15f642e58bcff" +source = "git+https://github.com/n0-computer/iroh#321d8ffd3d2bde2f1a80e78eab1ad83687484fc2" dependencies = [ "anyhow", "base64", @@ -2295,7 +2292,7 @@ dependencies = [ "hickory-proto 0.25.0-alpha.2", "hickory-resolver", "hostname 0.4.0", - "http 1.1.0", + "http 1.2.0", "http-body-util", "hyper", "hyper-util", @@ -2321,12 +2318,12 @@ dependencies = [ "smallvec", "socket2", "stun-rs", - "thiserror 2.0.3", + "thiserror 2.0.4", "time", "tokio", "tokio-rustls", "tokio-rustls-acme", - "tokio-tungstenite 0.24.0", + "tokio-tungstenite", "tokio-tungstenite-wasm", "tokio-util", "toml", @@ -2720,7 +2717,7 @@ dependencies = [ "rtnetlink 0.14.1", "serde", "socket2", - "thiserror 2.0.3", + "thiserror 2.0.4", "time", "tokio", "tokio-util", @@ -3248,7 +3245,7 @@ dependencies = [ "serde", "smallvec", "socket2", - "thiserror 2.0.3", + "thiserror 2.0.4", "time", "tokio", "tokio-util", @@ -3509,7 +3506,7 @@ dependencies = [ "rustc-hash", "rustls", "socket2", - "thiserror 2.0.3", + "thiserror 2.0.4", "tokio", "tracing", ] @@ -3528,7 +3525,7 @@ dependencies = [ "rustls", "rustls-pki-types", "slab", - "thiserror 2.0.3", + "thiserror 2.0.4", "tinyvec", "tracing", "web-time", @@ -3770,7 +3767,7 @@ dependencies = [ "bytes", "futures-core", "futures-util", - "http 1.1.0", + "http 1.2.0", "http-body", "http-body-util", "hyper", @@ -4655,9 +4652,9 @@ dependencies = [ [[package]] name = "testdir" -version = "0.9.2" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67e4445e224c9c0002cbb121e36f09541e3ee8fa53e672dac62a5012542e96a9" +checksum = "c9ffa013be124f7e8e648876190de818e3a87088ed97ccd414a398b403aec8c8" dependencies = [ "anyhow", "backtrace", @@ -4685,11 +4682,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.3" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c006c85c7651b3cf2ada4584faa36773bd07bac24acfb39f3c431b36d7e667aa" +checksum = "2f49a1853cf82743e3b7950f77e0f4d622ca36cf4317cba00c767838bac8d490" dependencies = [ - "thiserror-impl 2.0.3", + "thiserror-impl 2.0.4", ] [[package]] @@ -4705,9 +4702,9 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "2.0.3" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568" +checksum = "8381894bb3efe0c4acac3ded651301ceee58a15d47c2e34885ed1908ad667061" dependencies = [ "proc-macro2", "quote", @@ -4840,7 +4837,7 @@ dependencies = [ "rustls", "serde", "serde_json", - "thiserror 2.0.3", + "thiserror 2.0.4", "time", "tokio", "tokio-rustls", @@ -4868,19 +4865,7 @@ dependencies = [ "futures-util", "log", "tokio", - "tungstenite 0.21.0", -] - -[[package]] -name = "tokio-tungstenite" -version = "0.24.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edc5f74e248dc973e0dbb7b74c7e0d6fcc301c694ff50049504004ef4d0cdcd9" -dependencies = [ - "futures-util", - "log", - "tokio", - "tungstenite 0.24.0", + "tungstenite", ] [[package]] @@ -4891,21 +4876,21 @@ checksum = "8e57a65894797a018b28345fa298a00c450a574aa9671e50b18218a6292a55ac" dependencies = [ "futures-channel", "futures-util", - "http 1.1.0", + "http 1.2.0", "httparse", "js-sys", "thiserror 1.0.69", "tokio", - "tokio-tungstenite 0.21.0", + "tokio-tungstenite", "wasm-bindgen", "web-sys", ] [[package]] name = "tokio-util" -version = "0.7.12" +version = "0.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +checksum = "d7fcaa8d55a2bdd6b83ace262b016eca0d79ee02818c5c1bcdf0305114081078" dependencies = [ "bytes", "futures-core", @@ -5075,7 +5060,7 @@ dependencies = [ "byteorder", "bytes", "data-encoding", - "http 1.1.0", + "http 1.2.0", "httparse", "log", "rand", @@ -5085,24 +5070,6 @@ dependencies = [ "utf-8", ] -[[package]] -name = "tungstenite" -version = "0.24.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18e5b8366ee7a95b16d32197d0b2604b43a0be89dc5fac9f8e96ccafbaedda8a" -dependencies = [ - "byteorder", - "bytes", - "data-encoding", - "http 1.1.0", - "httparse", - "log", - "rand", - "sha1", - "thiserror 1.0.69", - "utf-8", -] - [[package]] name = "typenum" version = "1.17.0" @@ -5187,9 +5154,9 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "ureq" -version = "2.10.1" +version = "2.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b74fc6b57825be3373f7054754755f03ac3a8f5d70015ccad699ba2029956f4a" +checksum = "02d1a66277ed75f640d608235660df48c8e3c19f3b4edb6a263315626cc3c01d" dependencies = [ "base64", "log", @@ -5723,15 +5690,15 @@ dependencies = [ [[package]] name = "wmi" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70df482bbec7017ce4132154233642de658000b24b805345572036782a66ad55" +checksum = "dc47c0776cc6c00d2f7a874a0c846d94d45535936e5a1187693a24f23b4dd701" dependencies = [ "chrono", "futures", "log", "serde", - "thiserror 1.0.69", + "thiserror 2.0.4", "windows 0.58.0", "windows-core 0.58.0", ] @@ -5767,9 +5734,9 @@ dependencies = [ [[package]] name = "xml-rs" -version = "0.8.23" +version = "0.8.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af310deaae937e48a26602b730250b4949e125f468f11e6990be3e5304ddd96f" +checksum = "ea8b391c9a790b496184c29f7f93b9ed5b16abb306c05415b68bcc16e4d06432" [[package]] name = "xmltree" diff --git a/Cargo.toml b/Cargo.toml index 5848fb275..9c38062e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -95,7 +95,7 @@ futures-util = "0.3.30" testdir = "0.9.1" [features] -default = ["fs-store", "net_protocol"] +default = ["fs-store", "net_protocol", "rpc"] downloader = ["dep:parking_lot", "tokio-util/time", "dep:hashlink"] net_protocol = ["downloader", "dep:futures-util"] fs-store = ["dep:reflink-copy", "redb", "dep:redb_v1", "dep:tempfile"] @@ -184,6 +184,5 @@ panic = 'abort' 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" } +iroh = { git = "https://github.com/n0-computer/iroh" } diff --git a/src/net_protocol.rs b/src/net_protocol.rs index 710e2f29e..ae7b23211 100644 --- a/src/net_protocol.rs +++ b/src/net_protocol.rs @@ -47,14 +47,14 @@ impl Default for GcState { } } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct Blobs { rt: LocalPoolHandle, pub(crate) store: S, events: EventSender, downloader: Downloader, #[cfg(feature = "rpc")] - batches: tokio::sync::Mutex, + batches: Arc>, endpoint: Endpoint, gc_state: Arc>, #[cfg(feature = "rpc")] @@ -131,15 +131,15 @@ impl Builder { /// Build the Blobs protocol handler. /// You need to provide a local pool handle and an endpoint. - pub fn build(self, rt: &LocalPoolHandle, endpoint: &Endpoint) -> Arc> { + pub fn build(self, rt: &LocalPoolHandle, endpoint: &Endpoint) -> Blobs { let downloader = Downloader::new(self.store.clone(), endpoint.clone(), rt.clone()); - Arc::new(Blobs::new( + Blobs::new( self.store, rt.clone(), self.events.unwrap_or_default(), downloader, endpoint.clone(), - )) + ) } } @@ -391,82 +391,26 @@ impl Blobs { } } -// trait BlobsInner: Debug + Send + Sync + 'static { -// fn shutdown(self: Arc) -> BoxedFuture<()>; -// fn accept(self: Arc, conn: Connecting) -> BoxedFuture>; -// fn client(self: Arc) -> MemClient; -// fn local_pool_handle(&self) -> &LocalPoolHandle; -// fn downloader(&self) -> &Downloader; -// } - -// #[derive(Debug)] -// struct Blobs2 { -// inner: Arc, -// } - -// impl Blobs2 { -// fn client(&self) -> MemClient { -// self.inner.clone().client() -// } - -// fn local_pool_handle(&self) -> &LocalPoolHandle { -// self.inner.local_pool_handle() -// } - -// fn downloader(&self) -> &Downloader { -// self.inner.downloader() -// } -// } - -// impl BlobsInner for Blobs { -// fn shutdown(self: Arc) -> BoxedFuture<()> { -// ProtocolHandler::shutdown(self) -// } - -// fn accept(self: Arc, conn: Connecting) -> BoxedFuture> { -// ProtocolHandler::accept(self, conn) -// } - -// fn client(self: Arc) -> MemClient { -// Blobs::client(self) -// } - -// fn local_pool_handle(&self) -> &LocalPoolHandle { -// self.rt() -// } - -// fn downloader(&self) -> &Downloader { -// self.downloader() -// } -// } - -// impl ProtocolHandler for Blobs2 { -// fn accept(self: Arc, conn: Connecting) -> BoxedFuture> { -// self.inner.clone().accept(conn) -// } - -// fn shutdown(self: Arc) -> BoxedFuture<()> { -// self.inner.clone().shutdown() -// } -// } - impl ProtocolHandler for Blobs { - fn accept(self: Arc, conn: Connecting) -> BoxedFuture> { + fn accept(&self, conn: Connecting) -> BoxedFuture> { + let this = self.clone(); + Box::pin(async move { crate::provider::handle_connection( conn.await?, - self.store.clone(), - self.events.clone(), - self.rt.clone(), + this.store.clone(), + this.events.clone(), + this.rt.clone(), ) .await; Ok(()) }) } - fn shutdown(self: Arc) -> BoxedFuture<()> { + fn shutdown(&self) -> BoxedFuture<()> { + let this = self.clone(); Box::pin(async move { - self.store.shutdown().await; + this.store.shutdown().await; }) } } diff --git a/src/rpc.rs b/src/rpc.rs index ff8d13fa7..944a2a7de 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -63,7 +63,7 @@ const RPC_BLOB_GET_CHANNEL_CAP: usize = 2; impl Blobs { /// Get a client for the blobs protocol - pub fn client(self: Arc) -> blobs::MemClient { + pub fn client(&self) -> blobs::MemClient { let client = self .rpc_handler .get_or_init(|| RpcHandler::new(&self)) @@ -74,7 +74,7 @@ impl Blobs { /// Handle an RPC request pub async fn handle_rpc_request( - self: Arc, + self, msg: Request, chan: RpcChannel, ) -> std::result::Result<(), RpcServerError> @@ -91,7 +91,7 @@ impl Blobs { } #[derive(Clone)] -struct Handler(Arc>); +struct Handler(Blobs); impl Deref for Handler { type Target = Blobs; @@ -903,7 +903,7 @@ pub(crate) struct RpcHandler { } impl RpcHandler { - fn new(blobs: &Arc>) -> Self { + fn new(blobs: &Blobs) -> Self { let blobs = blobs.clone(); let (listener, connector) = quic_rpc::transport::flume::channel(1); let listener = RpcServer::new(listener); diff --git a/src/rpc/client/blobs.rs b/src/rpc/client/blobs.rs index 3d8e1e182..4183ffb15 100644 --- a/src/rpc/client/blobs.rs +++ b/src/rpc/client/blobs.rs @@ -1003,7 +1003,7 @@ mod tests { mod node { //! An iroh node that just has the blobs transport - use std::{path::Path, sync::Arc}; + use std::path::Path; use iroh::{protocol::Router, Endpoint, NodeAddr, NodeId}; use tokio_util::task::AbortOnDropHandle; @@ -1068,13 +1068,13 @@ mod tests { // Setup blobs let downloader = Downloader::new(store.clone(), endpoint.clone(), local_pool.handle().clone()); - let blobs = Arc::new(Blobs::new( + let blobs = Blobs::new( store.clone(), local_pool.handle().clone(), events, downloader, endpoint.clone(), - )); + ); router = router.accept(crate::ALPN, blobs.clone()); // Build the router diff --git a/tests/gc.rs b/tests/gc.rs index 10cc74e6e..a703ce5d2 100644 --- a/tests/gc.rs +++ b/tests/gc.rs @@ -3,7 +3,6 @@ use std::{ io, io::{Cursor, Write}, path::PathBuf, - sync::Arc, time::Duration, }; @@ -41,7 +40,7 @@ use tokio::io::AsyncReadExt; #[derive(Debug)] pub struct Node { pub router: iroh::protocol::Router, - pub blobs: Arc>, + pub blobs: Blobs, pub store: S, pub _local_pool: LocalPool, } From f24e27da0f2e68d591c8ce89bc96a72c62862e8d Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Thu, 5 Dec 2024 15:39:28 +0200 Subject: [PATCH 2/5] - fix custom protocol example - remove Handler helper struct in rpc - add iroh to allowed git deps --- deny.toml | 2 +- examples/custom-protocol.rs | 5 +++-- src/rpc.rs | 20 +------------------- 3 files changed, 5 insertions(+), 22 deletions(-) diff --git a/deny.toml b/deny.toml index f505ef3f6..c903f9260 100644 --- a/deny.toml +++ b/deny.toml @@ -38,5 +38,5 @@ ignore = [ [sources] allow-git = [ - # "https://github.com/n0-computer/iroh.git", + "https://github.com/n0-computer/iroh.git", ] diff --git a/examples/custom-protocol.rs b/examples/custom-protocol.rs index 5d92c687c..a5127e2dd 100644 --- a/examples/custom-protocol.rs +++ b/examples/custom-protocol.rs @@ -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, connecting: Connecting) -> BoxedFuture> { + fn accept(&self, connecting: Connecting) -> BoxedFuture> { + 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. @@ -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 diff --git a/src/rpc.rs b/src/rpc.rs index 944a2a7de..98b50163d 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -2,7 +2,6 @@ use std::{ io, - ops::Deref, sync::{Arc, Mutex}, }; @@ -82,29 +81,12 @@ impl Blobs { C: ChannelTypes, { use Request::*; - let handler = Handler(self); + let handler = self; match msg { Blobs(msg) => handler.handle_blobs_request(msg, chan).await, Tags(msg) => handler.handle_tags_request(msg, chan).await, } } -} - -#[derive(Clone)] -struct Handler(Blobs); - -impl Deref for Handler { - type Target = Blobs; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl Handler { - fn store(&self) -> &D { - &self.0.store - } /// Handle a tags request pub async fn handle_tags_request( From bdc9e23ea5f186012540b6d21ef277f1396eb300 Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Thu, 5 Dec 2024 15:46:15 +0200 Subject: [PATCH 3/5] clippy --- src/rpc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc.rs b/src/rpc.rs index 98b50163d..e8364a300 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -65,7 +65,7 @@ impl Blobs { pub fn client(&self) -> blobs::MemClient { let client = self .rpc_handler - .get_or_init(|| RpcHandler::new(&self)) + .get_or_init(|| RpcHandler::new(self)) .client .clone(); blobs::Client::new(client) From 8966132211c9aa5a1180cba1df55f92243d364b9 Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Thu, 5 Dec 2024 16:00:25 +0200 Subject: [PATCH 4/5] clone as little as possible into closures --- src/net_protocol.rs | 16 ++++++---------- src/rpc.rs | 6 ++---- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/net_protocol.rs b/src/net_protocol.rs index ae7b23211..c02a19acc 100644 --- a/src/net_protocol.rs +++ b/src/net_protocol.rs @@ -393,24 +393,20 @@ impl Blobs { impl ProtocolHandler for Blobs { fn accept(&self, conn: Connecting) -> BoxedFuture> { - let this = self.clone(); + 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?, - this.store.clone(), - this.events.clone(), - this.rt.clone(), - ) - .await; + crate::provider::handle_connection(conn.await?, db, events, rt).await; Ok(()) }) } fn shutdown(&self) -> BoxedFuture<()> { - let this = self.clone(); + let store = self.store.clone(); Box::pin(async move { - this.store.shutdown().await; + store.shutdown().await; }) } } diff --git a/src/rpc.rs b/src/rpc.rs index e8364a300..6f5ee8ba3 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -80,11 +80,9 @@ impl Blobs { where C: ChannelTypes, { - use Request::*; - let handler = self; match msg { - Blobs(msg) => handler.handle_blobs_request(msg, chan).await, - Tags(msg) => handler.handle_tags_request(msg, chan).await, + Request::Blobs(msg) => self.handle_blobs_request(msg, chan).await, + Request::Tags(msg) => self.handle_tags_request(msg, chan).await, } } From 7bad90929803b7427f11cbd050ad5fb9c54c2e94 Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Thu, 5 Dec 2024 16:12:03 +0200 Subject: [PATCH 5/5] remove rpc from default --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 9c38062e3..d92f1e042 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -95,7 +95,7 @@ futures-util = "0.3.30" testdir = "0.9.1" [features] -default = ["fs-store", "net_protocol", "rpc"] +default = ["fs-store", "net_protocol"] downloader = ["dep:parking_lot", "tokio-util/time", "dep:hashlink"] net_protocol = ["downloader", "dep:futures-util"] fs-store = ["dep:reflink-copy", "redb", "dep:redb_v1", "dep:tempfile"]