Skip to content

Commit

Permalink
chore: upgrade to iroh, iroh-gossip, and iroh-blobs v0.32.0
Browse files Browse the repository at this point in the history
  • Loading branch information
“ramfox” committed Feb 4, 2025
1 parent 7c4c871 commit 8486c0c
Show file tree
Hide file tree
Showing 8 changed files with 291 additions and 172 deletions.
353 changes: 227 additions & 126 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ futures-buffered = "0.2.4"
futures-lite = "2.3.0"
futures-util = { version = "0.3.25" }
hex = "0.4"
iroh-base = { version = "0.31", features = ["ticket"] }
iroh-base = { version = "0.32", features = ["ticket"] }
iroh-blobs = { version = "0.31" }
iroh-gossip = { version = "0.31", optional = true, features = ["net"] }
iroh-gossip = { version = "0.32", optional = true, features = ["net"] }
iroh-metrics = { version = "0.31", default-features = false }
iroh = { version = "0.31", optional = true }
iroh = { version = "0.32", optional = true }
num_enum = "0.7"
postcard = { version = "1", default-features = false, features = ["alloc", "use-std", "experimental-derive"] }
rand = "0.8.5"
Expand All @@ -58,8 +58,8 @@ tracing = "0.1"

# rpc
nested_enum_utils = { version = "0.1.0", optional = true }
quic-rpc = { version = "0.17", optional = true }
quic-rpc-derive = { version = "0.17", optional = true }
quic-rpc = { version = "0.18", optional = true }
quic-rpc-derive = { version = "0.18", optional = true }
serde-error = { version = "0.1.3", optional = true }
portable-atomic = { version = "1.9.0", optional = true }

Expand All @@ -73,11 +73,11 @@ colored = { version = "2.1", optional = true }
shellexpand = { version = "3.1", optional = true }

[dev-dependencies]
iroh-test = "0.31"
rand_chacha = "0.3.1"
tokio = { version = "1", features = ["sync", "macros"] }
proptest = "1.2.0"
tempfile = "3.4"
tracing-test = "0.2.5"
test-strategy = "0.4"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
parking_lot = "0.12.3"
Expand Down Expand Up @@ -117,3 +117,6 @@ rpc = [
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "iroh_docsrs"]

[patch.crates-io]
iroh-blobs = { git = "https://github.com/n0-computer/iroh-blobs.git", branch = "iroh-0-32-0" }
4 changes: 2 additions & 2 deletions src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
time::{Duration, Instant},
};

use iroh::{endpoint::get_remote_node_id, Endpoint, NodeAddr, PublicKey};
use iroh::{Endpoint, NodeAddr, PublicKey};
#[cfg(feature = "metrics")]
use iroh_metrics::inc;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -115,7 +115,7 @@ where
{
let t_start = Instant::now();
let connection = connecting.await.map_err(AcceptError::connect)?;
let peer = get_remote_node_id(&connection).map_err(AcceptError::connect)?;
let peer = connection.remote_node_id().map_err(AcceptError::connect)?;
let (mut send_stream, mut recv_stream) = connection
.accept_bi()
.await
Expand Down
9 changes: 5 additions & 4 deletions src/net/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ mod tests {
use iroh::SecretKey;
use iroh_blobs::Hash;
use rand_core::{CryptoRngCore, SeedableRng};
use tracing_test::traced_test;

use super::*;
use crate::{
Expand Down Expand Up @@ -419,16 +420,16 @@ mod tests {
}

#[tokio::test]
#[traced_test]
async fn test_sync_many_authors_memory() -> Result<()> {
let _guard = iroh_test::logging::setup();
let alice_store = store::Store::memory();
let bob_store = store::Store::memory();
test_sync_many_authors(alice_store, bob_store).await
}

#[tokio::test]
#[traced_test]
async fn test_sync_many_authors_fs() -> Result<()> {
let _guard = iroh_test::logging::setup();
let tmpdir = tempfile::tempdir()?;
let alice_store = store::fs::Store::persistent(tmpdir.path().join("a.db"))?;
let bob_store = store::fs::Store::persistent(tmpdir.path().join("b.db"))?;
Expand Down Expand Up @@ -612,16 +613,16 @@ mod tests {
}

#[tokio::test]
#[traced_test]
async fn test_sync_timestamps_memory() -> Result<()> {
let _guard = iroh_test::logging::setup();
let alice_store = store::Store::memory();
let bob_store = store::Store::memory();
test_sync_timestamps(alice_store, bob_store).await
}

#[tokio::test]
#[traced_test]
async fn test_sync_timestamps_fs() -> Result<()> {
let _guard = iroh_test::logging::setup();
let tmpdir = tempfile::tempdir()?;
let alice_store = store::fs::Store::persistent(tmpdir.path().join("a.db"))?;
let bob_store = store::fs::Store::persistent(tmpdir.path().join("b.db"))?;
Expand Down
32 changes: 30 additions & 2 deletions src/ticket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ impl std::str::FromStr for DocTicket {
mod tests {
use std::str::FromStr;

use anyhow::{ensure, Context, Result};
use iroh::PublicKey;
use iroh_test::{assert_eq_hex, hexdump::parse_hexdump};

use super::*;
use crate::NamespaceId;
Expand Down Expand Up @@ -106,6 +106,34 @@ mod tests {
00 # no relay url
00 # no direct addresses
").unwrap();
assert_eq_hex!(base32, expected);
assert_eq!(base32, expected);
}

/// Parses a commented multi line hexdump into a vector of bytes.
///
/// This is useful to write wire level protocol tests.
pub fn parse_hexdump(s: &str) -> Result<Vec<u8>> {
let mut result = Vec::new();

for (line_number, line) in s.lines().enumerate() {
let data_part = line.split('#').next().unwrap_or("");
let cleaned: String = data_part.chars().filter(|c| !c.is_whitespace()).collect();

ensure!(
cleaned.len() % 2 == 0,
"Non-even number of hex chars detected on line {}.",
line_number + 1
);

for i in (0..cleaned.len()).step_by(2) {
let byte_str = &cleaned[i..i + 2];
let byte = u8::from_str_radix(byte_str, 16)
.with_context(|| format!("Invalid hex data on line {}.", line_number + 1))?;

result.push(byte);
}
}

Ok(result)
}
}
10 changes: 4 additions & 6 deletions tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ use iroh_docs::store::Query;
use rand::RngCore;
use testresult::TestResult;
use tokio::io::AsyncWriteExt;
use tracing_test::traced_test;
use util::Node;

mod util;

/// Test that closing a doc does not close other instances.
#[tokio::test]
#[traced_test]
async fn test_doc_close() -> Result<()> {
let _guard = iroh_test::logging::setup();

let node = Node::memory().spawn().await?;
let author = node.authors().default().await?;
// open doc two times
Expand All @@ -38,9 +38,8 @@ async fn test_doc_close() -> Result<()> {
}

#[tokio::test]
#[traced_test]
async fn test_doc_import_export() -> TestResult<()> {
let _guard = iroh_test::logging::setup();

let node = Node::memory().spawn().await?;

// create temp file
Expand Down Expand Up @@ -156,9 +155,8 @@ async fn test_default_author_memory() -> Result<()> {
}

#[tokio::test]
#[traced_test]
async fn test_default_author_persist() -> TestResult<()> {
let _guard = iroh_test::logging::setup();

let iroh_root_dir = tempfile::TempDir::new()?;
let iroh_root = iroh_root_dir.path();

Expand Down
33 changes: 13 additions & 20 deletions tests/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use iroh_docs::{
};
use rand::{CryptoRng, Rng, SeedableRng};
use tracing::{debug, error_span, info, Instrument};
use tracing_subscriber::{prelude::*, EnvFilter};
use tracing_test::traced_test;
mod util;
use util::{Builder, Node};

Expand Down Expand Up @@ -73,8 +73,8 @@ macro_rules! match_event {

/// This tests the simplest scenario: A node connects to another node, and performs sync.
#[tokio::test]
#[traced_test]
async fn sync_simple() -> Result<()> {
setup_logging();
let mut rng = test_rng(b"sync_simple");
let nodes = spawn_nodes(2, &mut rng).await?;
let clients = nodes.iter().map(|node| node.client()).collect::<Vec<_>>();
Expand Down Expand Up @@ -133,9 +133,9 @@ async fn sync_simple() -> Result<()> {

/// Test subscribing to replica events (without sync)
#[tokio::test]
#[traced_test]
async fn sync_subscribe_no_sync() -> Result<()> {
let mut rng = test_rng(b"sync_subscribe");
setup_logging();
let node = spawn_node(0, &mut rng).await?;
let client = node.client();
let doc = client.docs().create().await?;
Expand All @@ -152,12 +152,12 @@ async fn sync_subscribe_no_sync() -> Result<()> {
}

#[tokio::test]
#[traced_test]
async fn sync_gossip_bulk() -> Result<()> {
let n_entries: usize = std::env::var("N_ENTRIES")
.map(|x| x.parse().expect("N_ENTRIES must be a number"))
.unwrap_or(100);
let mut rng = test_rng(b"sync_gossip_bulk");
setup_logging();

let nodes = spawn_nodes(2, &mut rng).await?;
let clients = nodes.iter().map(|node| node.client()).collect::<Vec<_>>();
Expand Down Expand Up @@ -242,10 +242,10 @@ async fn sync_gossip_bulk() -> Result<()> {

/// This tests basic sync and gossip with 3 peers.
#[tokio::test]
#[traced_test]
#[ignore = "flaky"]
async fn sync_full_basic() -> testresult::TestResult<()> {
let mut rng = test_rng(b"sync_full_basic");
setup_logging();
let mut nodes = spawn_nodes(2, &mut rng).await?;
let mut clients = nodes
.iter()
Expand Down Expand Up @@ -424,9 +424,9 @@ async fn sync_full_basic() -> testresult::TestResult<()> {
}

#[tokio::test]
#[traced_test]
async fn sync_open_close() -> Result<()> {
let mut rng = test_rng(b"sync_subscribe_stop_close");
setup_logging();
let node = spawn_node(0, &mut rng).await?;
let client = node.client();

Expand All @@ -448,9 +448,9 @@ async fn sync_open_close() -> Result<()> {
}

#[tokio::test]
#[traced_test]
async fn sync_subscribe_stop_close() -> Result<()> {
let mut rng = test_rng(b"sync_subscribe_stop_close");
setup_logging();
let node = spawn_node(0, &mut rng).await?;
let client = node.client();

Expand Down Expand Up @@ -487,9 +487,9 @@ async fn sync_subscribe_stop_close() -> Result<()> {
}

#[tokio::test]
#[traced_test]
#[cfg(feature = "test-utils")]
async fn test_sync_via_relay() -> Result<()> {
let _guard = iroh_test::logging::setup();
let (relay_map, _relay_url, _guard) = iroh::test_utils::run_relay_server().await?;

let node1 = Node::memory()
Expand Down Expand Up @@ -581,11 +581,11 @@ async fn test_sync_via_relay() -> Result<()> {
}

#[tokio::test]
#[traced_test]
#[cfg(feature = "test-utils")]
#[ignore = "flaky"]
async fn sync_restart_node() -> Result<()> {
let mut rng = test_rng(b"sync_restart_node");
setup_logging();
let (relay_map, _relay_url, _guard) = iroh::test_utils::run_relay_server().await?;

let discovery_server = iroh::test_utils::DnsPkarrServer::run().await?;
Expand Down Expand Up @@ -752,7 +752,6 @@ async fn test_download_policies() -> Result<()> {
const EXPECTED_B_DOWNLOADED: usize = 3;

let mut rng = test_rng(b"sync_download_policies");
setup_logging();
let nodes = spawn_nodes(2, &mut rng).await?;
let clients = nodes.iter().map(|node| node.client()).collect::<Vec<_>>();

Expand Down Expand Up @@ -860,9 +859,9 @@ async fn test_download_policies() -> Result<()> {

/// Test sync between many nodes with propagation through sync reports.
#[tokio::test(flavor = "multi_thread")]
#[traced_test]
#[ignore = "flaky"]
async fn sync_big() -> Result<()> {
setup_logging();
let mut rng = test_rng(b"sync_big");
let n_nodes = std::env::var("NODES")
.map(|v| v.parse().expect("NODES must be a number"))
Expand Down Expand Up @@ -982,6 +981,7 @@ async fn sync_big() -> Result<()> {
}

#[tokio::test]
#[traced_test]
#[cfg(feature = "test-utils")]
async fn test_list_docs_stream() -> testresult::TestResult<()> {
let node = Node::memory()
Expand Down Expand Up @@ -1156,6 +1156,7 @@ impl PartialEq<ExpectedEntry> for (Entry, Bytes) {
}

#[tokio::test]
#[traced_test]
async fn doc_delete() -> Result<()> {
let node = Node::memory()
.gc_interval(Some(Duration::from_millis(100)))
Expand Down Expand Up @@ -1185,9 +1186,9 @@ async fn doc_delete() -> Result<()> {
}

#[tokio::test]
#[traced_test]
async fn sync_drop_doc() -> Result<()> {
let mut rng = test_rng(b"sync_drop_doc");
setup_logging();
let node = spawn_node(0, &mut rng).await?;
let client = node.client();

Expand Down Expand Up @@ -1241,14 +1242,6 @@ async fn get_latest(
Ok(content.to_vec())
}

fn setup_logging() {
tracing_subscriber::registry()
.with(tracing_subscriber::fmt::layer().with_writer(std::io::stderr))
.with(EnvFilter::from_default_env())
.try_init()
.ok();
}

async fn next<T: std::fmt::Debug>(mut stream: impl Stream<Item = Result<T>> + Unpin) -> T {
let event = stream
.next()
Expand Down
Loading

0 comments on commit 8486c0c

Please # to comment.