Skip to content
Merged
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
1,070 changes: 591 additions & 479 deletions Cargo.lock

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ derive_more = { version = "2.0.1", features = [
"into",
"as_ref",
] }
ed25519-dalek = { version = "3.0.0-pre.1", features = ["serde", "rand_core"] }
ed25519-dalek = { version = "=3.0.0-pre.6", features = ["serde", "rand_core"] }
futures-buffered = "0.2.4"
futures-lite = "2.3.0"
futures-util = { version = "0.3.25" }
hex = "0.4"
iroh = { version = "0.97", default-features = false }
iroh-tickets = { version = "0.4" }
iroh-blobs = { version = "0.99", default-features = false }
iroh-gossip = { version = "0.97", features = ["net"], default-features = false }
iroh = { version = "0.98", default-features = false }
iroh-tickets = { version = "0.5" }
iroh-blobs = { version = "0.100", default-features = false }
iroh-gossip = { version = "0.98", features = ["net"], default-features = false }
iroh-metrics = { version = "0.38", default-features = false }
irpc = { version = "0.13", default-features = false }
irpc = { version = "0.14", default-features = false }
n0-error = "0.1.0"
n0-future = { version = "0.3.1", features = ["serde"] }
num_enum = "0.7"
Expand All @@ -45,13 +45,13 @@ postcard = { version = "1", default-features = false, features = [
"use-std",
"experimental-derive",
] }
noq = { version = "0.17.0", optional = true }
rand = "0.9.2"
noq = { version = "0.18", optional = true }
rand = "0.10"
redb = { version = "2.6.3" }
self_cell = "1.0.3"
serde = { version = "1.0.164", features = ["derive"] }
serde-error = "0.1.3"
strum = { version = "0.26", features = ["derive"] }
strum = { version = "0.28", features = ["derive"] }
tempfile = { version = "3.4" }
thiserror = "2"
tokio = { version = "1", features = ["sync", "rt", "time", "io-util"] }
Expand All @@ -61,14 +61,14 @@ tracing = "0.1"

[dev-dependencies]
data-encoding = "2.6.0"
iroh = { version = "0.97", features = ["test-utils"] }
iroh = { version = "0.98", features = ["test-utils"] }
nested_enum_utils = "0.2"
parking_lot = "0.12.3"
proptest = "1.2.0"
rand_chacha = "0.9"
rand = { version = "0.10", features = ["chacha"] }
tempfile = "3.4"
test-strategy = "0.4"
testdir = "0.7"
testdir = "0.8"
testresult = "0.4.1"
tokio = { version = "1", features = ["sync", "macros"] }
tracing-test = "0.2.5"
Expand Down
20 changes: 10 additions & 10 deletions src/net/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,13 @@ impl BobState {
.await
}
(Message::Init { .. }, Some(_)) => {
return Err(self.fail(anyhow!("double init message")))
return Err(self.fail(anyhow!("double init message")));
}
(Message::Sync(_), None) => {
return Err(self.fail(anyhow!("unexpected sync message before init")))
return Err(self.fail(anyhow!("unexpected sync message before init")));
}
(Message::Abort { .. }, _) => {
return Err(self.fail(anyhow!("unexpected sync abort message")))
return Err(self.fail(anyhow!("unexpected sync abort message")));
}
};
let (reply, progress) = next.map_err(|e| self.fail(e))?;
Expand Down Expand Up @@ -296,7 +296,7 @@ mod tests {
use anyhow::Result;
use iroh::SecretKey;
use iroh_blobs::Hash;
use rand::{CryptoRng, SeedableRng};
use rand::{CryptoRng, RngExt, SeedableRng};
use tracing_test::traced_test;

use super::*;
Expand Down Expand Up @@ -489,16 +489,16 @@ mod tests {
async fn test_sync_many_authors(mut alice_store: Store, mut bob_store: Store) -> Result<()> {
let num_messages = &[1, 2, 5, 10];
let num_authors = &[2, 3, 4, 5, 10];
let mut rng = rand_chacha::ChaCha12Rng::seed_from_u64(99);
let mut rng = rand::rngs::ChaCha12Rng::seed_from_u64(99);

for num_messages in num_messages {
for num_authors in num_authors {
println!(
"bob & alice each using {num_authors} authors and inserting {num_messages} messages per author"
);

let alice_node_pubkey = SecretKey::generate(&mut rng).public();
let bob_node_pubkey = SecretKey::generate(&mut rng).public();
let alice_node_pubkey = SecretKey::from_bytes(&rng.random()).public();
let bob_node_pubkey = SecretKey::from_bytes(&rng.random()).public();
let namespace = NamespaceSecret::new(&mut rng);

let mut all_messages = vec![];
Expand Down Expand Up @@ -639,9 +639,9 @@ mod tests {
}

async fn test_sync_timestamps(mut alice_store: Store, mut bob_store: Store) -> Result<()> {
let mut rng = rand_chacha::ChaCha12Rng::seed_from_u64(99);
let alice_node_pubkey = SecretKey::generate(&mut rng).public();
let bob_node_pubkey = SecretKey::generate(&mut rng).public();
let mut rng = rand::rngs::ChaCha12Rng::seed_from_u64(99);
let alice_node_pubkey = SecretKey::from_bytes(&rng.random()).public();
let bob_node_pubkey = SecretKey::from_bytes(&rng.random()).public();
let namespace = NamespaceSecret::new(&mut rng);

let author = alice_store.new_author(&mut rng)?;
Expand Down
12 changes: 6 additions & 6 deletions src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1550,7 +1550,7 @@ mod tests {
}

async fn test_timestamps(mut store: Store) -> Result<()> {
let mut rng = rand_chacha::ChaCha12Rng::seed_from_u64(1);
let mut rng = rand::rngs::ChaCha12Rng::seed_from_u64(1);
let namespace = NamespaceSecret::new(&mut rng);
let _replica = store.new_replica(namespace.clone())?;
let author = store.new_author(&mut rng)?;
Expand Down Expand Up @@ -2133,7 +2133,7 @@ mod tests {

#[allow(clippy::redundant_pattern_matching)]
async fn test_replica_capability(mut store: Store) -> Result<()> {
let mut rng = rand_chacha::ChaCha12Rng::seed_from_u64(1);
let mut rng = rand::rngs::ChaCha12Rng::seed_from_u64(1);
let author = store.new_author(&mut rng)?;
let namespace = NamespaceSecret::new(&mut rng);

Expand Down Expand Up @@ -2182,7 +2182,7 @@ mod tests {

async fn test_actor_capability(store: Store) -> Result<()> {
// test with actor
let mut rng = rand_chacha::ChaCha12Rng::seed_from_u64(1);
let mut rng = rand::rngs::ChaCha12Rng::seed_from_u64(1);
let author = Author::new(&mut rng);
let handle = SyncHandle::spawn(store, None, "test".into());
let author = handle.import_author(author).await?;
Expand Down Expand Up @@ -2232,7 +2232,7 @@ mod tests {
/// (too old) by the time they are actually inserted in the store.
#[tokio::test]
async fn test_replica_no_wrong_remote_insert_events() -> Result<()> {
let mut rng = rand_chacha::ChaCha12Rng::seed_from_u64(1);
let mut rng = rand::rngs::ChaCha12Rng::seed_from_u64(1);
let mut store1 = store::Store::memory();
let mut store2 = store::Store::memory();
let peer1 = [1u8; 32];
Expand Down Expand Up @@ -2307,7 +2307,7 @@ mod tests {
}

async fn test_replica_queries(mut store: Store) -> Result<()> {
let mut rng = rand_chacha::ChaCha12Rng::seed_from_u64(1);
let mut rng = rand::rngs::ChaCha12Rng::seed_from_u64(1);
let namespace = NamespaceSecret::new(&mut rng);
let namespace_id = namespace.id();

Expand Down Expand Up @@ -2494,7 +2494,7 @@ mod tests {
}

fn test_dl_policies(store: &mut Store) -> Result<()> {
let mut rng = rand_chacha::ChaCha12Rng::seed_from_u64(1);
let mut rng = rand::rngs::ChaCha12Rng::seed_from_u64(1);
let namespace = NamespaceSecret::new(&mut rng);
let id = namespace.id();

Expand Down
2 changes: 1 addition & 1 deletion tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::{Context, Result};
use iroh_blobs::api::blobs::{ExportMode, ImportMode};
use iroh_docs::store::Query;
use n0_future::StreamExt;
use rand::RngCore;
use rand::Rng;
use testresult::TestResult;
use tokio::io::AsyncWriteExt;
use tracing_test::traced_test;
Expand Down
6 changes: 4 additions & 2 deletions tests/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use bytes::Bytes;
use futures_lite::StreamExt;
use iroh_blobs::api::blobs::ImportMode;
use n0_future::time::Duration;
use rand::RngCore;
use rand::Rng;
use testdir::testdir;
use util::Node;

Expand All @@ -26,8 +26,10 @@ async fn persistent_node(
path: PathBuf,
gc_period: Duration,
) -> (Node, async_channel::Receiver<()>) {
use iroh::endpoint::presets;

let (gc_send, gc_recv) = async_channel::unbounded();
let ep = iroh::Endpoint::empty_builder().bind().await.unwrap();
let ep = iroh::Endpoint::bind(presets::Minimal).await.unwrap();
let node = Node::persistent(path, ep)
.gc_interval(Some(gc_period))
.register_gc_done_cb(Box::new(move || {
Expand Down
25 changes: 13 additions & 12 deletions tests/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anyhow::{anyhow, bail, Context, Result};
use bytes::Bytes;
use futures_lite::Stream;
use futures_util::{FutureExt, StreamExt, TryStreamExt};
use iroh::{Endpoint, PublicKey, SecretKey};
use iroh::{endpoint::presets, Endpoint, PublicKey, SecretKey};
use iroh_blobs::Hash;
use iroh_docs::{
api::{
Expand All @@ -16,7 +16,7 @@ use iroh_docs::{
AuthorId, ContentStatus, Entry,
};
use n0_future::time::{Duration, Instant};
use rand::{CryptoRng, Rng, SeedableRng};
use rand::{CryptoRng, RngExt, SeedableRng};
#[cfg(feature = "fs-store")]
use tempfile::tempdir;
use tracing::{debug, error_span, info, Instrument};
Expand All @@ -29,7 +29,7 @@ use crate::util::empty_endpoint;
const TIMEOUT: Duration = Duration::from_secs(60);

async fn test_node(secret_key: SecretKey) -> Result<Builder> {
let ep = Endpoint::empty_builder()
let ep = Endpoint::builder(presets::Minimal)
.secret_key(secret_key)
.bind()
.await?;
Expand All @@ -41,9 +41,9 @@ async fn test_node(secret_key: SecretKey) -> Result<Builder> {
// still collecting the futures before awaiting them altogether (see [`spawn_nodes`])
fn spawn_node(
i: usize,
rng: &mut (impl CryptoRng + Rng),
rng: &mut impl CryptoRng,
) -> impl Future<Output = anyhow::Result<Node>> + 'static {
let secret_key = SecretKey::generate(rng);
let secret_key = SecretKey::from_bytes(&rng.random());
async move {
let node = test_node(secret_key).await?;
let node = node.spawn().await?;
Expand All @@ -52,16 +52,16 @@ fn spawn_node(
}
}

async fn spawn_nodes(n: usize, mut rng: &mut (impl CryptoRng + Rng)) -> anyhow::Result<Vec<Node>> {
async fn spawn_nodes(n: usize, mut rng: &mut impl CryptoRng) -> anyhow::Result<Vec<Node>> {
let mut futs = vec![];
for i in 0..n {
futs.push(spawn_node(i, &mut rng));
}
futures_buffered::join_all(futs).await.into_iter().collect()
}

pub fn test_rng(seed: &[u8]) -> rand_chacha::ChaCha12Rng {
rand_chacha::ChaCha12Rng::from_seed(*Hash::new(seed).as_bytes())
pub fn test_rng(seed: &[u8]) -> rand::rngs::ChaCha12Rng {
rand::rngs::ChaCha12Rng::from_seed(*Hash::new(seed).as_bytes())
}

macro_rules! match_event {
Expand Down Expand Up @@ -489,20 +489,21 @@ async fn sync_subscribe_stop_close() -> Result<()> {
#[tokio::test]
#[traced_test]
async fn test_sync_via_relay() -> Result<()> {
let mut rng = test_rng(b"test_sync_via_relay");
let (relay_map, _relay_url, _guard) = iroh::test_utils::run_relay_server().await?;

use crate::util::endpoint;

let ep1 = endpoint(
SecretKey::generate(&mut rand::rng()),
SecretKey::from_bytes(&rng.random()),
relay_map.clone(),
None,
)
.await?;
let node1 = Node::memory(ep1).spawn().await?;
let node1_id = node1.id();
let ep2 = endpoint(
SecretKey::generate(&mut rand::rng()),
SecretKey::from_bytes(&rng.random()),
relay_map.clone(),
None,
)
Expand Down Expand Up @@ -605,7 +606,7 @@ async fn sync_restart_node() -> Result<()> {
let lookup_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(&mut rng);
let secret_key_1 = SecretKey::from_bytes(&rng.random());

let ep = endpoint(
secret_key_1.clone(),
Expand All @@ -625,7 +626,7 @@ async fn sync_restart_node() -> Result<()> {
.await?;

// create node2
let secret_key_2 = SecretKey::generate(&mut rng);
let secret_key_2 = SecretKey::from_bytes(&rng.random());
let ep = endpoint(secret_key_2, relay_map.clone(), Some(&lookup_server)).await?;
let node2 = Node::memory(ep).spawn().await?;
let id2 = node2.id();
Expand Down
10 changes: 6 additions & 4 deletions tests/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,26 @@ use std::{
};

use iroh::{
endpoint::BindError, test_utils::DnsPkarrServer, tls::CaRootsConfig, Endpoint, EndpointId,
RelayMap, RelayMode, SecretKey,
endpoint::{presets, BindError},
test_utils::DnsPkarrServer,
tls::CaRootsConfig,
Endpoint, EndpointId, RelayMap, RelayMode, SecretKey,
};
use iroh_blobs::store::GcConfig;
use iroh_docs::{engine::ProtectCallbackHandler, protocol::Docs};
use iroh_gossip::net::Gossip;
use n0_error::Result;

pub async fn empty_endpoint() -> Result<Endpoint, BindError> {
Endpoint::empty_builder().bind().await
Endpoint::bind(presets::Minimal).await
}

pub async fn endpoint(
secret_key: SecretKey,
relay_map: RelayMap,
dns_pkarr_server: Option<&DnsPkarrServer>,
) -> Result<Endpoint, BindError> {
let mut builder = Endpoint::empty_builder();
let mut builder = Endpoint::builder(presets::Minimal);
if let Some(dns_pkarr_server) = dns_pkarr_server {
builder = builder.preset(dns_pkarr_server.preset());
}
Expand Down
Loading