From 4e0719ac268f514a21d3c907bf781d414e014011 Mon Sep 17 00:00:00 2001
From: Ruediger Klaehn <rklaehn@protonmail.com>
Date: Thu, 5 Dec 2024 15:14:25 +0200
Subject: [PATCH 1/3] refactor: adapt to iroh on main

new way to do protocol accept
---
 Cargo.lock              | 51 ++++++++---------------------------------
 Cargo.toml              |  4 ++--
 examples/transfer.rs    |  3 +--
 src/net_protocol.rs     | 18 +++++++--------
 src/rpc/client/blobs.rs |  6 +++--
 5 files changed, 24 insertions(+), 58 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index a13cfb97f..c90c6b338 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -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?branch=main#8dfbc35d1bd5ad1ad47e1be54d4f63b62ea26108"
 dependencies = [
  "anyhow",
  "axum",
  "backoff",
  "base64",
  "bytes",
+ "concurrent-queue",
  "der",
  "derive_more",
  "futures-buffered",
@@ -2048,7 +2048,7 @@ dependencies = [
  "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?branch=main#8dfbc35d1bd5ad1ad47e1be54d4f63b62ea26108"
 dependencies = [
  "aead",
  "anyhow",
@@ -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?branch=main#8dfbc35d1bd5ad1ad47e1be54d4f63b62ea26108"
 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?branch=main#8dfbc35d1bd5ad1ad47e1be54d4f63b62ea26108"
 dependencies = [
  "anyhow",
  "base64",
@@ -2326,7 +2323,7 @@ dependencies = [
  "tokio",
  "tokio-rustls",
  "tokio-rustls-acme",
- "tokio-tungstenite 0.24.0",
+ "tokio-tungstenite",
  "tokio-tungstenite-wasm",
  "tokio-util",
  "toml",
@@ -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]]
@@ -4896,7 +4881,7 @@ dependencies = [
  "js-sys",
  "thiserror 1.0.69",
  "tokio",
- "tokio-tungstenite 0.21.0",
+ "tokio-tungstenite",
  "wasm-bindgen",
  "web-sys",
 ]
@@ -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"
diff --git a/Cargo.toml b/Cargo.toml
index 5848fb275..6651ecf4e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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" }
diff --git a/examples/transfer.rs b/examples/transfer.rs
index 4e73909ea..a9e66f5c8 100644
--- a/examples/transfer.rs
+++ b/examples/transfer.rs
@@ -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},
diff --git a/src/net_protocol.rs b/src/net_protocol.rs
index 710e2f29e..f1fc8e186 100644
--- a/src/net_protocol.rs
+++ b/src/net_protocol.rs
@@ -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;
         })
     }
 }
diff --git a/src/rpc/client/blobs.rs b/src/rpc/client/blobs.rs
index 3d8e1e182..a33f38fcf 100644
--- a/src/rpc/client/blobs.rs
+++ b/src/rpc/client/blobs.rs
@@ -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;

From 95a5e0b0c8d7f8fd6d51538e5167285eb7c9897a Mon Sep 17 00:00:00 2001
From: Ruediger Klaehn <rklaehn@protonmail.com>
Date: Thu, 5 Dec 2024 15:27:00 +0200
Subject: [PATCH 2/3] allow iroh git dep again

---
 deny.toml | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/deny.toml b/deny.toml
index f505ef3f6..364f35af7 100644
--- a/deny.toml
+++ b/deny.toml
@@ -37,6 +37,4 @@ ignore = [
 ]
 
 [sources]
-allow-git = [
-    # "https://github.com/n0-computer/iroh.git",
-]
+allow-git = ["https://github.com/n0-computer/iroh.git"]

From 64bb5500cfdd871a77955a2e80ec650b5a87fc8c Mon Sep 17 00:00:00 2001
From: Ruediger Klaehn <rklaehn@protonmail.com>
Date: Thu, 5 Dec 2024 15:32:49 +0200
Subject: [PATCH 3/3] fix example

---
 examples/custom-protocol.rs | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

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<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.
@@ -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