diff --git a/iroh-cli/src/commands/blob.rs b/iroh-cli/src/commands/blob.rs index 875b703cbbf..ce579eda870 100644 --- a/iroh-cli/src/commands/blob.rs +++ b/iroh-cli/src/commands/blob.rs @@ -26,12 +26,12 @@ use iroh::{ }, }; use iroh::{ + base::ticket::BlobTicket, client::{BlobStatus, Iroh}, rpc_protocol::{ BlobDownloadRequest, BlobListCollectionsResponse, BlobListIncompleteResponse, BlobListResponse, DownloadMode, ProviderService, SetTagOption, WrapOption, }, - ticket::BlobTicket, }; use quic_rpc::ServiceConnection; use tokio::io::AsyncWriteExt; diff --git a/iroh-cli/src/commands/doc.rs b/iroh-cli/src/commands/doc.rs index 59bcbb2940f..acb03c282f4 100644 --- a/iroh-cli/src/commands/doc.rs +++ b/iroh-cli/src/commands/doc.rs @@ -13,19 +13,19 @@ use dialoguer::Confirm; use futures_buffered::BufferedStreamExt; use futures_lite::{Stream, StreamExt}; use indicatif::{HumanBytes, HumanDuration, MultiProgress, ProgressBar, ProgressStyle}; -use iroh::base::{base32::fmt_short, node_addr::AddrInfoOptions}; use quic_rpc::ServiceConnection; use serde::{Deserialize, Serialize}; use tokio::io::AsyncReadExt; -use iroh::bytes::{provider::AddProgress, Hash, Tag}; -use iroh::sync::{ - store::{DownloadPolicy, FilterKind, Query, SortDirection}, - AuthorId, NamespaceId, -}; use iroh::{ + base::{base32::fmt_short, node_addr::AddrInfoOptions}, + bytes::{provider::AddProgress, Hash, Tag}, client::{Doc, Entry, Iroh, LiveEvent}, - rpc_protocol::{DocTicket, ProviderService, SetTagOption, WrapOption}, + rpc_protocol::{ProviderService, SetTagOption, WrapOption}, + sync::{ + store::{DownloadPolicy, FilterKind, Query, SortDirection}, + AuthorId, DocTicket, NamespaceId, + }, sync_engine::Origin, util::fs::{path_content_info, path_to_key, PathContent}, }; diff --git a/iroh-cli/src/commands/doctor.rs b/iroh-cli/src/commands/doctor.rs index f0ee736542c..bf54d573782 100644 --- a/iroh-cli/src/commands/doctor.rs +++ b/iroh-cli/src/commands/doctor.rs @@ -17,7 +17,7 @@ use clap::Subcommand; use futures_lite::StreamExt; use indicatif::{HumanBytes, MultiProgress, ProgressBar}; use iroh::{ - base::ticket::Ticket, + base::ticket::{BlobTicket, Ticket}, bytes::{ store::{ReadableStore, Store as _}, util::progress::{FlumeProgressSender, ProgressSender}, @@ -31,9 +31,11 @@ use iroh::{ key::{PublicKey, SecretKey}, magic_endpoint, netcheck, portmapper, relay::{RelayMap, RelayMode, RelayUrl}, + ticket::NodeTicket, util::AbortingJoinHandle, MagicEndpoint, NodeAddr, NodeId, }, + sync::DocTicket, util::{path::IrohPaths, progress::ProgressWriter}, }; use portable_atomic::AtomicU64; @@ -958,17 +960,14 @@ fn create_discovery(disable_discovery: bool, secret_key: &SecretKey) -> Option anyhow::Result<()> { - if ticket.starts_with(iroh::ticket::BlobTicket::KIND) { - let ticket = - iroh::ticket::BlobTicket::from_str(ticket).context("failed parsing blob ticket")?; + if ticket.starts_with(BlobTicket::KIND) { + let ticket = BlobTicket::from_str(ticket).context("failed parsing blob ticket")?; println!("Blob ticket:\n{ticket:#?}"); - } else if ticket.starts_with(iroh::ticket::DocTicket::KIND) { - let ticket = - iroh::ticket::DocTicket::from_str(ticket).context("failed parsing doc ticket")?; + } else if ticket.starts_with(DocTicket::KIND) { + let ticket = DocTicket::from_str(ticket).context("failed parsing doc ticket")?; println!("Document ticket:\n{ticket:#?}"); - } else if ticket.starts_with(iroh::ticket::NodeTicket::KIND) { - let ticket = - iroh::ticket::NodeTicket::from_str(ticket).context("failed parsing node ticket")?; + } else if ticket.starts_with(NodeTicket::KIND) { + let ticket = NodeTicket::from_str(ticket).context("failed parsing node ticket")?; println!("Node ticket:\n{ticket:#?}"); } else { println!("Unknown ticket type"); diff --git a/iroh-cli/tests/cli.rs b/iroh-cli/tests/cli.rs index 0663459a3e8..e08e349abca 100644 --- a/iroh-cli/tests/cli.rs +++ b/iroh-cli/tests/cli.rs @@ -10,10 +10,11 @@ use std::str::FromStr; use anyhow::{Context, Result}; use bao_tree::blake3; use duct::{cmd, ReaderHandle}; -use iroh::bytes::Hash; -use iroh::bytes::HashAndFormat; -use iroh::ticket::BlobTicket; -use iroh::util::path::IrohPaths; +use iroh::{ + base::ticket::BlobTicket, + bytes::{Hash, HashAndFormat}, + util::path::IrohPaths, +}; use rand::distributions::{Alphanumeric, DistString}; use rand::SeedableRng; use regex::Regex; diff --git a/iroh-sync/src/lib.rs b/iroh-sync/src/lib.rs index edca63a39be..b88d186a27a 100644 --- a/iroh-sync/src/lib.rs +++ b/iroh-sync/src/lib.rs @@ -33,17 +33,22 @@ //! [paper]: https://arxiv.org/abs/2212.13567 #![deny(missing_docs, rustdoc::broken_intra_doc_links)] -pub mod actor; -mod heads; -mod keys; #[cfg(feature = "metrics")] pub mod metrics; #[cfg(feature = "net")] pub mod net; -mod ranger; +#[cfg(feature = "net")] +mod ticket; + +pub mod actor; pub mod store; pub mod sync; +mod heads; +mod keys; +mod ranger; + pub use self::heads::*; pub use self::keys::*; pub use self::sync::*; +pub use self::ticket::DocTicket; diff --git a/iroh/src/ticket/doc.rs b/iroh-sync/src/ticket.rs similarity index 98% rename from iroh/src/ticket/doc.rs rename to iroh-sync/src/ticket.rs index f0f66679181..b9cdad2c7c0 100644 --- a/iroh/src/ticket/doc.rs +++ b/iroh-sync/src/ticket.rs @@ -2,9 +2,10 @@ use iroh_base::ticket; use iroh_net::NodeAddr; -use iroh_sync::Capability; use serde::{Deserialize, Serialize}; +use crate::Capability; + /// Contains both a key (either secret or public) to a document, and a list of peers to join. #[derive(Serialize, Deserialize, Clone, Debug, derive_more::Display)] #[display("{}", ticket::Ticket::serialize(self))] @@ -64,10 +65,11 @@ impl std::str::FromStr for DocTicket { mod tests { use std::str::FromStr; + use crate::NamespaceId; + use super::*; use iroh_base::base32; use iroh_net::key::PublicKey; - use iroh_sync::NamespaceId; use iroh_test::{assert_eq_hex, hexdump::parse_hexdump}; #[test] diff --git a/iroh/examples/collection-fetch.rs b/iroh/examples/collection-fetch.rs index 53fac68f52f..64932e25a42 100644 --- a/iroh/examples/collection-fetch.rs +++ b/iroh/examples/collection-fetch.rs @@ -3,11 +3,14 @@ //! //! This is using an in memory database and a random node id. //! Run the `collection-provide` example, which will give you instructions on how to run this example. +use std::{env, str::FromStr}; + use anyhow::{bail, ensure, Context, Result}; -use iroh::rpc_protocol::{BlobDownloadRequest, DownloadMode}; -use iroh_bytes::BlobFormat; -use std::env; -use std::str::FromStr; +use iroh::{ + base::ticket::BlobTicket, + bytes::BlobFormat, + rpc_protocol::{BlobDownloadRequest, DownloadMode}, +}; use tracing_subscriber::{prelude::*, EnvFilter}; // set the RUST_LOG env var to one of {debug,info,warn} to see logging info @@ -32,7 +35,7 @@ async fn main() -> Result<()> { // deserialize ticket string into a ticket let ticket = - iroh::ticket::BlobTicket::from_str(&args[1]).context("failed parsing blob ticket\n\nGet a ticket by running the follow command in a separate terminal:\n\n`cargo run --example collection-provide`")?; + BlobTicket::from_str(&args[1]).context("failed parsing blob ticket\n\nGet a ticket by running the follow command in a separate terminal:\n\n`cargo run --example collection-provide`")?; // create a new node let node = iroh::node::Node::memory().spawn().await?; diff --git a/iroh/examples/hello-world-fetch.rs b/iroh/examples/hello-world-fetch.rs index fcc75cdbcaf..4d1f5f4b93e 100644 --- a/iroh/examples/hello-world-fetch.rs +++ b/iroh/examples/hello-world-fetch.rs @@ -3,11 +3,14 @@ //! //! This is using an in memory database and a random node id. //! Run the `provide` example, which will give you instructions on how to run this example. +use std::{env, str::FromStr}; + use anyhow::{bail, ensure, Context, Result}; -use iroh::rpc_protocol::{BlobDownloadRequest, DownloadMode}; -use iroh_bytes::BlobFormat; -use std::env; -use std::str::FromStr; +use iroh::{ + base::ticket::BlobTicket, + bytes::BlobFormat, + rpc_protocol::{BlobDownloadRequest, DownloadMode}, +}; use tracing_subscriber::{prelude::*, EnvFilter}; // set the RUST_LOG env var to one of {debug,info,warn} to see logging info @@ -32,7 +35,7 @@ async fn main() -> Result<()> { // deserialize ticket string into a ticket let ticket = - iroh::ticket::BlobTicket::from_str(&args[1]).context("failed parsing blob ticket\n\nGet a ticket by running the follow command in a separate terminal:\n\n`cargo run --example hello-world-provide`")?; + BlobTicket::from_str(&args[1]).context("failed parsing blob ticket\n\nGet a ticket by running the follow command in a separate terminal:\n\n`cargo run --example hello-world-provide`")?; // create a new node let node = iroh::node::Node::memory().spawn().await?; diff --git a/iroh/src/client/docs.rs b/iroh/src/client/docs.rs index 83bb9d002d7..2b744b04101 100644 --- a/iroh/src/client/docs.rs +++ b/iroh/src/client/docs.rs @@ -14,7 +14,7 @@ use iroh_net::NodeAddr; use iroh_sync::{ actor::OpenState, store::{DownloadPolicy, Query}, - AuthorId, CapabilityKind, ContentStatus, NamespaceId, PeerIdBytes, RecordIdentifier, + AuthorId, CapabilityKind, ContentStatus, DocTicket, NamespaceId, PeerIdBytes, RecordIdentifier, }; use portable_atomic::{AtomicBool, Ordering}; use quic_rpc::{message::RpcMsg, RpcClient, ServiceConnection}; @@ -30,7 +30,6 @@ use crate::{ DocSubscribeRequest, ProviderService, ShareMode, }, sync_engine::SyncEvent, - ticket::DocTicket, }; use super::{blobs::BlobReader, flatten}; diff --git a/iroh/src/lib.rs b/iroh/src/lib.rs index 69ce9b98bb6..dbc697a5747 100644 --- a/iroh/src/lib.rs +++ b/iroh/src/lib.rs @@ -7,17 +7,11 @@ pub use iroh_bytes as bytes; pub use iroh_net as net; pub use iroh_sync as sync; -// reexport types from the iroh_base crate -// iroh_base::hash::* is exported from iroh_bytes as bytes -// iroh_base::rpc::* is exported from mod rpc_protocol -pub use iroh_base::base32; - pub mod client; pub mod dial; pub mod node; pub mod rpc_protocol; pub mod sync_engine; -pub mod ticket; pub mod util; /// Expose metrics module diff --git a/iroh/src/node.rs b/iroh/src/node.rs index 9866a652a8c..3b0e978f703 100644 --- a/iroh/src/node.rs +++ b/iroh/src/node.rs @@ -12,6 +12,7 @@ use std::sync::Arc; use anyhow::{anyhow, Result}; use futures_lite::{future::Boxed as BoxFuture, FutureExt, StreamExt}; +use iroh_base::ticket::BlobTicket; use iroh_bytes::downloader::Downloader; use iroh_bytes::store::Store as BaoStore; use iroh_bytes::BlobFormat; @@ -33,7 +34,6 @@ use tracing::debug; use crate::rpc_protocol::{ProviderRequest, ProviderResponse}; use crate::sync_engine::SyncEngine; -use crate::ticket::BlobTicket; mod builder; mod rpc; diff --git a/iroh/src/rpc_protocol.rs b/iroh/src/rpc_protocol.rs index 14ab8109464..3c955198ba3 100644 --- a/iroh/src/rpc_protocol.rs +++ b/iroh/src/rpc_protocol.rs @@ -26,7 +26,7 @@ use iroh_net::{ use iroh_sync::{ actor::OpenState, store::{DownloadPolicy, Query}, - Author, PeerIdBytes, {AuthorId, CapabilityKind, Entry, NamespaceId, SignedEntry}, + Author, AuthorId, CapabilityKind, DocTicket, Entry, NamespaceId, PeerIdBytes, SignedEntry, }; use quic_rpc::{ message::{BidiStreaming, BidiStreamingMsg, Msg, RpcMsg, ServerStreaming, ServerStreamingMsg}, @@ -40,7 +40,6 @@ use iroh_bytes::store::{ExportFormat, ExportMode}; pub use iroh_bytes::{provider::AddProgress, store::ValidateProgress}; use crate::sync_engine::LiveEvent; -pub use crate::ticket::DocTicket; pub use iroh_bytes::util::SetTagOption; /// A 32-byte key or token diff --git a/iroh/src/sync_engine/rpc.rs b/iroh/src/sync_engine/rpc.rs index 605f875f2bd..88f1ba9a5ed 100644 --- a/iroh/src/sync_engine/rpc.rs +++ b/iroh/src/sync_engine/rpc.rs @@ -3,7 +3,7 @@ use anyhow::anyhow; use futures_lite::Stream; use iroh_bytes::{store::Store as BaoStore, BlobFormat}; -use iroh_sync::{Author, NamespaceSecret}; +use iroh_sync::{Author, DocTicket, NamespaceSecret}; use tokio_stream::StreamExt; use crate::rpc_protocol::{ @@ -21,7 +21,7 @@ use crate::{ DocSetDownloadPolicyRequest, DocSetDownloadPolicyResponse, DocSetHashRequest, DocSetHashResponse, DocSetRequest, DocSetResponse, DocShareRequest, DocShareResponse, DocStartSyncRequest, DocStartSyncResponse, DocStatusRequest, DocStatusResponse, - DocSubscribeRequest, DocSubscribeResponse, DocTicket, RpcResult, ShareMode, + DocSubscribeRequest, DocSubscribeResponse, RpcResult, ShareMode, }, sync_engine::SyncEngine, }; diff --git a/iroh/src/ticket.rs b/iroh/src/ticket.rs deleted file mode 100644 index cbc5b6a6958..00000000000 --- a/iroh/src/ticket.rs +++ /dev/null @@ -1,5 +0,0 @@ -//! Tickets that iroh supports -mod doc; - -pub use doc::DocTicket; -pub use iroh_base::ticket::{BlobTicket, NodeTicket};