Skip to content

Commit

Permalink
refactor: simplify ticket structure
Browse files Browse the repository at this point in the history
- iroh: move `DocTicket` into `iroh-sync`
- iroh: remove `ticket` module
  • Loading branch information
dignifiedquire committed May 2, 2024
1 parent cdedc43 commit 3aa7697
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 56 deletions.
2 changes: 1 addition & 1 deletion iroh-cli/src/commands/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions iroh-cli/src/commands/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down
19 changes: 9 additions & 10 deletions iroh-cli/src/commands/doctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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;
Expand Down Expand Up @@ -958,17 +960,14 @@ fn create_discovery(disable_discovery: bool, secret_key: &SecretKey) -> Option<B
}

fn inspect_ticket(ticket: &str) -> 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");
Expand Down
9 changes: 5 additions & 4 deletions iroh-cli/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 9 additions & 4 deletions iroh-sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
6 changes: 4 additions & 2 deletions iroh/src/ticket/doc.rs → iroh-sync/src/ticket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down Expand Up @@ -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]
Expand Down
13 changes: 8 additions & 5 deletions iroh/examples/collection-fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?;
Expand Down
13 changes: 8 additions & 5 deletions iroh/examples/hello-world-fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?;
Expand Down
3 changes: 1 addition & 2 deletions iroh/src/client/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -30,7 +30,6 @@ use crate::{
DocSubscribeRequest, ProviderService, ShareMode,
},
sync_engine::SyncEvent,
ticket::DocTicket,
};

use super::{blobs::BlobReader, flatten};
Expand Down
6 changes: 0 additions & 6 deletions iroh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion iroh/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions iroh/src/rpc_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions iroh/src/sync_engine/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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,
};
Expand Down
5 changes: 0 additions & 5 deletions iroh/src/ticket.rs

This file was deleted.

0 comments on commit 3aa7697

Please sign in to comment.