Skip to content

Commit

Permalink
feat: update to latest iroh
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Nov 28, 2024
1 parent d4ab8db commit 2d5be06
Show file tree
Hide file tree
Showing 14 changed files with 457 additions and 303 deletions.
677 changes: 420 additions & 257 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 6 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ iroh-base = "0.28.0"
iroh-blobs = { version = "0.28.0", optional = true, features = ["downloader"] }
iroh-gossip = { version = "0.28.0", optional = true }
iroh-metrics = { version = "0.28.0", default-features = false }
iroh-net = { version = "0.28.0", optional = true }
iroh-router = { version = "0.28.0", optional = true }
iroh = { version = "0.28", optional = true }
num_enum = "0.7"
postcard = { version = "1", default-features = false, features = ["alloc", "use-std", "experimental-derive"] }
rand = "0.8.5"
Expand Down Expand Up @@ -88,10 +87,10 @@ testdir = "0.9.1"

[features]
default = ["net", "metrics", "engine", "rpc", "test-utils"]
net = ["dep:iroh-net", "tokio/io-util", "dep:tokio-stream", "dep:tokio-util"]
metrics = ["iroh-metrics/metrics"]
engine = ["net", "dep:iroh-gossip", "dep:iroh-blobs", "dep:iroh-router"]
test-utils = ["iroh-net/test-utils"]
net = ["dep:iroh", "tokio/io-util", "dep:tokio-stream", "dep:tokio-util"]
metrics = ["iroh-metrics/metrics", "iroh/metrics"]
engine = ["net", "dep:iroh-gossip", "dep:iroh-blobs"]
test-utils = ["iroh/test-utils"]
cli = ["rpc", "dep:clap", "dep:indicatif", "dep:console", "dep:colored", "dep:dialoguer", "dep:shellexpand", "iroh-blobs/rpc"]
rpc = [
"engine",
Expand All @@ -107,9 +106,8 @@ all-features = true
rustdoc-args = ["--cfg", "iroh_docsrs"]

[patch.crates-io]
iroh-router = { git = "https://github.com/n0-computer/iroh", branch = "main" }
iroh-net = { git = "https://github.com/n0-computer/iroh", branch = "main" }
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-blobs = { git = "https://github.com/n0-computer/iroh-blobs", branch = "main" }
iroh-gossip = { git = "https://github.com/n0-computer/iroh-gossip", branch = "main" }
7 changes: 2 additions & 5 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use std::{

use anyhow::{bail, Context, Result};
use futures_lite::{Stream, StreamExt};
use iroh::{key::PublicKey, Endpoint, NodeAddr};
use iroh_blobs::{
downloader::Downloader, store::EntryStatus, util::local_pool::LocalPoolHandle, Hash,
};
use iroh_gossip::net::Gossip;
use iroh_net::{key::PublicKey, Endpoint, NodeAddr};
use serde::{Deserialize, Serialize};
use tokio::sync::{mpsc, oneshot};
use tokio_util::task::AbortOnDropHandle;
Expand Down Expand Up @@ -202,10 +202,7 @@ impl<D: iroh_blobs::store::Store> Engine<D> {
}

/// Handle an incoming iroh-docs connection.
pub async fn handle_connection(
&self,
conn: iroh_net::endpoint::Connecting,
) -> anyhow::Result<()> {
pub async fn handle_connection(&self, conn: iroh::endpoint::Connecting) -> anyhow::Result<()> {
self.to_live_actor
.send(ToLiveActor::HandleConnection { conn })
.await?;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use anyhow::{Context, Result};
use bytes::Bytes;
use futures_lite::StreamExt;
use futures_util::FutureExt;
use iroh::NodeId;
use iroh_gossip::net::{Event, Gossip, GossipEvent, GossipReceiver, GossipSender, JoinOptions};
use iroh_net::NodeId;
use tokio::{
sync::mpsc,
task::{AbortHandle, JoinSet},
Expand Down
6 changes: 3 additions & 3 deletions src/engine/live.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{

use anyhow::{Context, Result};
use futures_lite::FutureExt;
use iroh::{key::PublicKey, Endpoint, NodeAddr, NodeId};
use iroh_blobs::{
downloader::{DownloadError, DownloadRequest, Downloader},
get::Stats,
Expand All @@ -15,7 +16,6 @@ use iroh_blobs::{
};
use iroh_gossip::net::Gossip;
use iroh_metrics::inc;
use iroh_net::{key::PublicKey, Endpoint, NodeAddr, NodeId};
use serde::{Deserialize, Serialize};
use tokio::{
sync::{self, mpsc, oneshot},
Expand Down Expand Up @@ -86,7 +86,7 @@ pub enum ToLiveActor {
reply: sync::oneshot::Sender<Result<()>>,
},
HandleConnection {
conn: iroh_net::endpoint::Connecting,
conn: iroh::endpoint::Connecting,
},
AcceptSyncRequest {
namespace: NamespaceId,
Expand Down Expand Up @@ -759,7 +759,7 @@ impl<B: iroh_blobs::store::Store> LiveActor<B> {
}

#[instrument("accept", skip_all)]
pub async fn handle_connection(&mut self, conn: iroh_net::endpoint::Connecting) {
pub async fn handle_connection(&mut self, conn: iroh::endpoint::Connecting) {
let to_actor_tx = self.sync_actor_tx.clone();
let accept_request_cb = move |namespace, peer| {
let to_actor_tx = to_actor_tx.clone();
Expand Down
2 changes: 1 addition & 1 deletion src/engine/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
};

use anyhow::Result;
use iroh_net::NodeId;
use iroh::NodeId;
use serde::{Deserialize, Serialize};
use tracing::{debug, warn};

Expand Down
4 changes: 2 additions & 2 deletions src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use std::{
time::{Duration, Instant},
};

use iroh::{endpoint::get_remote_node_id, key::PublicKey, Endpoint, NodeAddr};
#[cfg(feature = "metrics")]
use iroh_metrics::inc;
use iroh_net::{endpoint::get_remote_node_id, key::PublicKey, Endpoint, NodeAddr};
use serde::{Deserialize, Serialize};
use tracing::{debug, error_span, trace, Instrument};

Expand Down Expand Up @@ -106,7 +106,7 @@ pub enum AcceptOutcome {
/// Handle an iroh-docs connection and sync all shared documents in the replica store.
pub async fn handle_connection<F, Fut>(
sync: SyncHandle,
connecting: iroh_net::endpoint::Connecting,
connecting: iroh::endpoint::Connecting,
accept_cb: F,
) -> Result<SyncFinished, AcceptError>
where
Expand Down
4 changes: 2 additions & 2 deletions src/net/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::future::Future;
use anyhow::{anyhow, ensure};
use bytes::{Buf, BufMut, BytesMut};
use futures_util::SinkExt;
use iroh_net::key::PublicKey;
use iroh::key::PublicKey;
use serde::{Deserialize, Serialize};
use tokio::io::{AsyncRead, AsyncWrite};
use tokio_stream::StreamExt;
Expand Down Expand Up @@ -294,8 +294,8 @@ impl BobState {
#[cfg(test)]
mod tests {
use anyhow::Result;
use iroh::key::SecretKey;
use iroh_base::hash::Hash;
use iroh_net::key::SecretKey;
use rand_core::{CryptoRngCore, SeedableRng};

use super::*;
Expand Down
3 changes: 1 addition & 2 deletions src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use std::sync::Arc;

use anyhow::Result;
use futures_lite::future::Boxed as BoxedFuture;
use iroh_net::endpoint::Connecting;
use iroh_router::ProtocolHandler;
use iroh::{endpoint::Connecting, protocol::ProtocolHandler};

use crate::engine::Engine;

Expand Down
2 changes: 1 addition & 1 deletion src/rpc/client/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use anyhow::{anyhow, Context as _, Result};
use bytes::Bytes;
use derive_more::{Display, FromStr};
use futures_lite::{Stream, StreamExt};
use iroh::NodeAddr;
use iroh_base::node_addr::AddrInfoOptions;
use iroh_blobs::{export::ExportProgress, store::ExportMode, Hash};
use iroh_net::NodeAddr;
use portable_atomic::{AtomicBool, Ordering};
use quic_rpc::{
client::BoxedConnector, message::RpcMsg, transport::flume::FlumeConnector, Connector,
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
use std::path::PathBuf;

use bytes::Bytes;
use iroh::NodeAddr;
use iroh_base::node_addr::AddrInfoOptions;
use iroh_blobs::{export::ExportProgress, store::ExportMode, Hash};
use iroh_net::NodeAddr;
use nested_enum_utils::enum_conversions;
use quic_rpc::pattern::try_server_streaming::StreamCreated;
use quic_rpc_derive::rpc_requests;
Expand Down
4 changes: 2 additions & 2 deletions src/ticket.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Tickets for [`iroh-docs`] documents.
use iroh::NodeAddr;
use iroh_base::ticket;
use iroh_net::NodeAddr;
use serde::{Deserialize, Serialize};

use crate::Capability;
Expand Down Expand Up @@ -65,8 +65,8 @@ impl std::str::FromStr for DocTicket {
mod tests {
use std::str::FromStr;

use iroh::key::PublicKey;
use iroh_base::base32;
use iroh_net::key::PublicKey;
use iroh_test::{assert_eq_hex, hexdump::parse_hexdump};

use super::*;
Expand Down
14 changes: 7 additions & 7 deletions tests/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ use anyhow::{anyhow, bail, Context, Result};
use bytes::Bytes;
use futures_lite::Stream;
use futures_util::{FutureExt, StreamExt, TryStreamExt};
use iroh::{
key::{PublicKey, SecretKey},
RelayMode,
};
use iroh_base::node_addr::AddrInfoOptions;
use iroh_blobs::Hash;
use iroh_docs::{
rpc::client::docs::{Doc, Entry, LiveEvent, ShareMode},
store::{DownloadPolicy, FilterKind, Query},
AuthorId, ContentStatus,
};
use iroh_net::{
key::{PublicKey, SecretKey},
RelayMode,
};
use rand::{CryptoRng, Rng, SeedableRng};
use tracing::{debug, error_span, info, Instrument};
use tracing_subscriber::{prelude::*, EnvFilter};
Expand Down Expand Up @@ -491,7 +491,7 @@ async fn sync_subscribe_stop_close() -> Result<()> {
#[cfg(feature = "test-utils")]
async fn test_sync_via_relay() -> Result<()> {
let _guard = iroh_test::logging::setup();
let (relay_map, _relay_url, _guard) = iroh_net::test_utils::run_relay_server().await?;
let (relay_map, _relay_url, _guard) = iroh::test_utils::run_relay_server().await?;

let node1 = Node::memory()
.relay_mode(RelayMode::Custom(relay_map.clone()))
Expand Down Expand Up @@ -587,9 +587,9 @@ async fn test_sync_via_relay() -> Result<()> {
async fn sync_restart_node() -> Result<()> {
let mut rng = test_rng(b"sync_restart_node");
setup_logging();
let (relay_map, _relay_url, _guard) = iroh_net::test_utils::run_relay_server().await?;
let (relay_map, _relay_url, _guard) = iroh::test_utils::run_relay_server().await?;

let discovery_server = iroh_net::test_utils::DnsPkarrServer::run().await?;
let discovery_server = iroh::test_utils::DnsPkarrServer::run().await?;

let node1_dir = tempfile::TempDir::with_prefix("test-sync_restart_node-node1")?;
let secret_key_1 = SecretKey::generate_with_rng(&mut rng);
Expand Down
19 changes: 8 additions & 11 deletions tests/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use std::{
sync::Arc,
};

use iroh::{discovery::Discovery, dns::DnsResolver, key::SecretKey, NodeId, RelayMode};
use iroh_blobs::{
store::{GcConfig, Store as BlobStore},
util::local_pool::{LocalPool, Run},
};
use iroh_net::{discovery::Discovery, dns::DnsResolver, key::SecretKey, NodeId, RelayMode};
use nested_enum_utils::enum_conversions;
use quic_rpc::transport::{Connector, Listener};
use serde::{Deserialize, Serialize};
Expand All @@ -34,7 +34,7 @@ pub const DEFAULT_BIND_ADDR_V6: SocketAddrV6 =
/// An iroh node that just has the blobs transport
#[derive(Debug)]
pub struct Node<S> {
router: iroh_router::Router,
router: iroh::protocol::Router,
client: Client,
store: S,
local_pool: LocalPool,
Expand Down Expand Up @@ -126,7 +126,7 @@ impl<S: BlobStore> Builder<S> {
addr_v4.set_port(0);
addr_v6.set_port(0);
}
let mut builder = iroh_net::Endpoint::builder()
let mut builder = iroh::Endpoint::builder()
.bind_addr_v4(addr_v4)
.bind_addr_v6(addr_v6)
.discovery_n0()
Expand All @@ -138,15 +138,15 @@ impl<S: BlobStore> Builder<S> {
let endpoint = builder.bind().await?;
let addr = endpoint.node_addr().await?;
let local_pool = LocalPool::single();
let mut router = iroh_router::Router::builder(endpoint.clone());
let mut router = iroh::protocol::Router::builder(endpoint.clone());

// Setup blobs
let downloader = iroh_blobs::downloader::Downloader::new(
store.clone(),
endpoint.clone(),
local_pool.handle().clone(),
);
let blobs = Arc::new(iroh_blobs::net_protocol::Blobs::new_with_events(
let blobs = Arc::new(iroh_blobs::net_protocol::Blobs::new(
store.clone(),
local_pool.handle().clone(),
Default::default(),
Expand Down Expand Up @@ -185,12 +185,9 @@ impl<S: BlobStore> Builder<S> {
return Err(err);
}
};
router = router.accept(iroh_blobs::protocol::ALPN.to_vec(), blobs.clone());
router = router.accept(iroh_docs::net::DOCS_ALPN.to_vec(), Arc::new(docs.clone()));
router = router.accept(
iroh_gossip::net::GOSSIP_ALPN.to_vec(),
Arc::new(gossip.clone()),
);
router = router.accept(iroh_blobs::protocol::ALPN, blobs.clone());
router = router.accept(iroh_docs::net::DOCS_ALPN, Arc::new(docs.clone()));
router = router.accept(iroh_gossip::net::GOSSIP_ALPN, Arc::new(gossip.clone()));

// Build the router
let router = router.spawn().await?;
Expand Down

0 comments on commit 2d5be06

Please sign in to comment.