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
706 changes: 383 additions & 323 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ futures-buffered = "0.2.4"
futures-lite = "2.3.0"
futures-util = { version = "0.3.25" }
hex = "0.4"
iroh = { version = "0.96.1", default-features = false }
iroh-tickets = { version = "0.2" }
iroh-blobs = { version = "0.98", default-features = false }
iroh-gossip = { version = "0.96", features = ["net"], default-features = false }
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-metrics = { version = "0.38", default-features = false }
irpc = { version = "0.12.0", default-features = false }
irpc = { version = "0.13", default-features = false }
n0-error = "0.1.0"
n0-future = { version = "0.3.1", features = ["serde"] }
num_enum = "0.7"
Expand All @@ -45,7 +45,7 @@ postcard = { version = "1", default-features = false, features = [
"use-std",
"experimental-derive",
] }
quinn = { package = "iroh-quinn", version = "0.16.0", optional = true }
noq = { version = "0.17.0", optional = true }
rand = "0.9.2"
redb = { version = "2.6.3" }
self_cell = "1.0.3"
Expand All @@ -61,7 +61,7 @@ tracing = "0.1"

[dev-dependencies]
data-encoding = "2.6.0"
iroh = { version = "0.96.1", features = ["test-utils"] }
iroh = { version = "0.97", features = ["test-utils"] }
nested_enum_utils = "0.2"
parking_lot = "0.12.3"
proptest = "1.2.0"
Expand All @@ -77,7 +77,7 @@ tracing-subscriber = { version = "0.3.20", features = ["env-filter"] }
[features]
default = ["metrics", "rpc", "fs-store"]
metrics = ["iroh-metrics/metrics", "iroh/metrics"]
rpc = ["dep:quinn", "irpc/rpc", "iroh-blobs/rpc"]
rpc = ["dep:noq", "irpc/rpc", "iroh-blobs/rpc"]
fs-store = ["iroh-blobs/fs-store"]

[package.metadata.docs.rs]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Iroh provides a [`Router`](https://docs.rs/iroh/latest/iroh/protocol/struct.Rout
Here is a basic example of how to set up `iroh-docs` with `iroh`:

```rust
use iroh::{protocol::Router, Endpoint};
use iroh::{endpoint::presets, protocol::Router, Endpoint};
use iroh_blobs::{BlobsProtocol, store::mem::MemStore, ALPN as BLOBS_ALPN};
use iroh_docs::{protocol::Docs, ALPN as DOCS_ALPN};
use iroh_gossip::{net::Gossip, ALPN as GOSSIP_ALPN};
Expand All @@ -51,7 +51,7 @@ use iroh_gossip::{net::Gossip, ALPN as GOSSIP_ALPN};
async fn main() -> anyhow::Result<()> {
// create an iroh endpoint that includes the standard discovery mechanisms
// we've built at number0
let endpoint = Endpoint::builder().bind().await?;
let endpoint = Endpoint::bind(presets::N0).await?;

// build the blobs protocol
let blobs = MemStore::default();
Expand Down
4 changes: 2 additions & 2 deletions examples/setup.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use iroh::{protocol::Router, Endpoint};
use iroh::{endpoint::presets, protocol::Router, Endpoint};
use iroh_blobs::{store::mem::MemStore, BlobsProtocol, ALPN as BLOBS_ALPN};
use iroh_docs::{protocol::Docs, ALPN as DOCS_ALPN};
use iroh_gossip::{net::Gossip, ALPN as GOSSIP_ALPN};
Expand All @@ -7,7 +7,7 @@ use iroh_gossip::{net::Gossip, ALPN as GOSSIP_ALPN};
async fn main() -> anyhow::Result<()> {
// create an iroh endpoint that includes the standard address lookup mechanisms
// we've built at number0
let endpoint = Endpoint::builder().bind().await?;
let endpoint = Endpoint::bind(presets::N0).await?;

// build the blobs protocol
let blobs = MemStore::default();
Expand Down
8 changes: 4 additions & 4 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ impl DocsApi {

/// Connect to a remote docs service
#[cfg(feature = "rpc")]
pub fn connect(endpoint: quinn::Endpoint, addr: std::net::SocketAddr) -> Result<DocsApi> {
pub fn connect(endpoint: noq::Endpoint, addr: std::net::SocketAddr) -> Result<DocsApi> {
Ok(DocsApi {
inner: Client::quinn(endpoint, addr),
inner: Client::noq(endpoint, addr),
})
}

/// Listen for incoming RPC connections
#[cfg(feature = "rpc")]
pub fn listen(
&self,
endpoint: quinn::Endpoint,
endpoint: noq::Endpoint,
) -> Result<n0_future::task::AbortOnDropHandle<()>> {
use anyhow::Context;
let local = self
Expand Down Expand Up @@ -677,7 +677,7 @@ impl Future for ImportFileProgress {
Poll::Ready(None) => {
return Poll::Ready(Err(anyhow::anyhow!(
"ImportFileProgress polled after completion"
)))
)));
}
Poll::Pending => return Poll::Pending,
}
Expand Down
15 changes: 11 additions & 4 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl Engine {
to_live_actor_recv,
live_actor_tx.clone(),
sync.metrics().clone(),
);
)?;
let actor_handle = n0_future::task::spawn(
async move {
if let Err(err) = actor.run().await {
Expand Down Expand Up @@ -389,7 +389,10 @@ impl DefaultAuthorStorage {
)
})?;
if docs_store.export_author(author_id).await?.is_none() {
bail!("The default author is missing from the docs store. To recover, delete the file `{}`. Then iroh will create a new default author.", path.to_string_lossy())
bail!(
"The default author is missing from the docs store. To recover, delete the file `{}`. Then iroh will create a new default author.",
path.to_string_lossy()
)
}
Ok(author_id)
} else {
Expand Down Expand Up @@ -503,13 +506,17 @@ impl ProtectCallbackSender {
Box::pin(async move {
let (tx, rx) = oneshot::channel();
if let Err(_err) = start_tx.send(tx).await {
tracing::warn!("Failed to get protected hashes from docs: ProtectCallback receiver dropped");
tracing::warn!(
"Failed to get protected hashes from docs: ProtectCallback receiver dropped"
);
return ProtectOutcome::Abort;
}
let mut rx = match rx.await {
Ok(rx) => rx,
Err(_err) => {
tracing::warn!("Failed to get protected hashes from docs: ProtectCallback sender dropped");
tracing::warn!(
"Failed to get protected hashes from docs: ProtectCallback sender dropped"
);
return ProtectOutcome::Abort;
}
};
Expand Down
8 changes: 4 additions & 4 deletions src/engine/live.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,12 @@ impl LiveActor {
inbox: mpsc::Receiver<ToLiveActor>,
sync_actor_tx: mpsc::Sender<ToLiveActor>,
metrics: Arc<Metrics>,
) -> Self {
) -> Result<Self> {
let (replica_events_tx, replica_events_rx) = async_channel::bounded(1024);
let gossip_state = GossipState::new(gossip, sync.clone(), sync_actor_tx.clone());
let memory_lookup = MemoryLookup::new();
endpoint.address_lookup().add(memory_lookup.clone());
Self {
endpoint.address_lookup()?.add(memory_lookup.clone());
Ok(Self {
inbox,
sync,
replica_events_rx,
Expand All @@ -218,7 +218,7 @@ impl LiveActor {
queued_hashes: Default::default(),
hash_providers: Default::default(),
metrics,
}
})
}

/// Run the actor loop.
Expand Down
37 changes: 26 additions & 11 deletions tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ use self::util::{
path::{key_to_path, path_to_key},
Node,
};
use crate::util::empty_endpoint;

mod util;

/// Test that closing a doc does not close other instances.
#[tokio::test]
#[traced_test]
async fn test_doc_close() -> Result<()> {
let node = Node::memory().spawn().await?;
let node = Node::memory(empty_endpoint().await?).spawn().await?;
// let author = node.authors().default().await?;
let author = node.docs().author_default().await?;
// open doc two times
Expand All @@ -41,7 +42,7 @@ async fn test_doc_close() -> Result<()> {
#[tokio::test]
#[traced_test]
async fn test_doc_import_export() -> TestResult<()> {
let node = Node::memory().spawn().await?;
let node = Node::memory(empty_endpoint().await?).spawn().await?;

// create temp file
let temp_dir = tempfile::tempdir().context("tempdir")?;
Expand Down Expand Up @@ -122,7 +123,7 @@ async fn test_doc_import_export() -> TestResult<()> {

#[tokio::test]
async fn test_authors() -> Result<()> {
let node = Node::memory().spawn().await?;
let node = Node::memory(empty_endpoint().await?).spawn().await?;

// default author always exists
let authors: Vec<_> = node.docs().author_list().await?.try_collect().await?;
Expand Down Expand Up @@ -158,7 +159,7 @@ async fn test_authors() -> Result<()> {

#[tokio::test]
async fn test_default_author_memory() -> Result<()> {
let iroh = Node::memory().spawn().await?;
let iroh = Node::memory(empty_endpoint().await?).spawn().await?;
let author = iroh.docs().author_default().await?;
assert!(iroh.docs().author_export(author).await?.is_some());
assert!(iroh.docs().author_delete(author).await.is_err());
Expand All @@ -174,7 +175,9 @@ async fn test_default_author_persist() -> TestResult<()> {

// check that the default author exists and cannot be deleted.
let default_author = {
let iroh = Node::persistent(iroh_root).spawn().await?;
let iroh = Node::persistent(iroh_root, empty_endpoint().await?)
.spawn()
.await?;
let author = iroh.docs().author_default().await?;
assert!(iroh.docs().author_export(author).await?.is_some());
assert!(iroh.docs().author_delete(author).await.is_err());
Expand All @@ -184,7 +187,9 @@ async fn test_default_author_persist() -> TestResult<()> {

// check that the default author is persisted across restarts.
{
let iroh = Node::persistent(iroh_root).spawn().await?;
let iroh = Node::persistent(iroh_root, empty_endpoint().await?)
.spawn()
.await?;
let author = iroh.docs().author_default().await?;
assert_eq!(author, default_author);
assert!(iroh.docs().author_export(author).await?.is_some());
Expand All @@ -196,7 +201,9 @@ async fn test_default_author_persist() -> TestResult<()> {
// manually.
let default_author = {
tokio::fs::remove_file(iroh_root.join("default-author")).await?;
let iroh = Node::persistent(iroh_root).spawn().await?;
let iroh = Node::persistent(iroh_root, empty_endpoint().await?)
.spawn()
.await?;
let author = iroh.docs().author_default().await?;
assert!(author != default_author);
assert!(iroh.docs().author_export(author).await?.is_some());
Expand All @@ -211,7 +218,9 @@ async fn test_default_author_persist() -> TestResult<()> {
docs_store.delete_author(default_author)?;
docs_store.flush()?;
drop(docs_store);
let iroh = Node::persistent(iroh_root).spawn().await;
let iroh = Node::persistent(iroh_root, empty_endpoint().await?)
.spawn()
.await;
assert!(iroh.is_err());

// somehow the blob store is not shutdown correctly (yet?) on macos.
Expand All @@ -221,7 +230,9 @@ async fn test_default_author_persist() -> TestResult<()> {

tokio::fs::remove_file(iroh_root.join("default-author")).await?;
drop(iroh);
let iroh = Node::persistent(iroh_root).spawn().await;
let iroh = Node::persistent(iroh_root, empty_endpoint().await?)
.spawn()
.await;
if let Err(cause) = iroh.as_ref() {
panic!("failed to start node: {cause:?}");
}
Expand All @@ -230,15 +241,19 @@ async fn test_default_author_persist() -> TestResult<()> {

// check that the default author can be set manually and is persisted.
let default_author = {
let iroh = Node::persistent(iroh_root).spawn().await?;
let iroh = Node::persistent(iroh_root, empty_endpoint().await?)
.spawn()
.await?;
let author = iroh.docs().author_create().await?;
iroh.docs().author_set_default(author).await?;
assert_eq!(iroh.docs().author_default().await?, author);
iroh.shutdown().await?;
author
};
{
let iroh = Node::persistent(iroh_root).spawn().await?;
let iroh = Node::persistent(iroh_root, empty_endpoint().await?)
.spawn()
.await?;
assert_eq!(iroh.docs().author_default().await?, default_author);
iroh.shutdown().await?;
}
Expand Down
3 changes: 2 additions & 1 deletion tests/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ async fn persistent_node(
gc_period: Duration,
) -> (Node, async_channel::Receiver<()>) {
let (gc_send, gc_recv) = async_channel::unbounded();
let node = Node::persistent(path)
let ep = iroh::Endpoint::empty_builder().bind().await.unwrap();
let node = Node::persistent(path, ep)
.gc_interval(Some(gc_period))
.register_gc_done_cb(Box::new(move || {
gc_send.send_blocking(()).ok();
Expand Down
Loading
Loading