Skip to content

Commit

Permalink
feat: Upgrade to Iroh v0.29.0
Browse files Browse the repository at this point in the history
  • Loading branch information
emmyoh committed Dec 11, 2024
1 parent c0f8f50 commit 53f258d
Show file tree
Hide file tree
Showing 18 changed files with 872 additions and 695 deletions.
852 changes: 504 additions & 348 deletions Cargo.lock

Large diffs are not rendered by default.

26 changes: 15 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,34 @@ required-features = ["cli"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bytes = "1.8.0"
bytes = "1.9.0"
cfg-if = "1.0.0"
chrono = "0.4.38"
clap = { version = "4.5.20", features = ["derive"], optional = true }
chrono = "0.4.39"
clap = { version = "4.5.23", features = ["derive"], optional = true }
fuse_mt = { version = "0.6.1", optional = true }
fuser = { version = "0.13.0", optional = true }
futures = "0.3.31"
iroh = "0.28.1"
libc = { version = "0.2.162", optional = true }
mainline = { version = "3.0.0", features = ["async"] }
miette = { version = "7.2.0", features = ["fancy"] }
iroh = { version = "0.29.0", features = ["discovery-local-network"] }
iroh-docs = "0.29.0"
iroh-base = "0.29.0"
iroh-blobs = "0.29.0"
iroh-gossip = "0.29.0"
libc = { version = "0.2.168", optional = true }
mainline = { version = "4.1.0", features = ["async"] }
miette = { version = "7.4.0", features = ["fancy"] }
path-clean = "1.0.1"
thiserror = "2.0.3"
tokio = "1.41.1"
thiserror = "2.0.6"
tokio = "1.42.0"
env_logger = { version = "0.11.5", optional = true }
log = "0.4.22"
bs58 = "0.5.1"
anyhow = "1.0.93"
anyhow = "1.0.94"
native_db = "0.8.1"
native_model = "0.4.20"
serde = "1.0.215"
toml = "0.8.19"
rayon = "1.10.0"
url = { version = "2.5.3", features = ["serde"] }
url = { version = "2.5.4", features = ["serde"] }
tantivy = "0.22.0"

[features]
Expand Down
8 changes: 8 additions & 0 deletions precommit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
cargo clippy --fix --allow-dirty --features="cli,fuse"
# __CARGO_FIX_YOLO=1 cargo clippy --fix --broken-code --allow-dirty --features="cli,fuse"
cargo fmt
cargo check
cargo check --features="cli"
cargo check --features="fuse"
cargo check --features="cli,fuse"
25 changes: 13 additions & 12 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use bytes::Bytes;
use clap::{Parser, Subcommand};
use env_logger::Builder;
use iroh::base::ticket::Ticket;
use iroh::docs::DocTicket;
use iroh::{client::docs::ShareMode, docs::NamespaceId};
use iroh_base::ticket::Ticket;
use iroh_docs::rpc::client::docs::ShareMode;
use iroh_docs::DocTicket;
use iroh_docs::NamespaceId;
use log::{info, LevelFilter};
use miette::{miette, IntoDiagnostic};
use oku_fs::fs::OkuFs;
Expand Down Expand Up @@ -154,9 +155,9 @@ async fn main() -> miette::Result<()> {
cfg_if::cfg_if! {
if #[cfg(any(feature = "fuse"))] {
let handle = Handle::current();
let node = OkuFs::start(&handle).await?;
let node = OkuFs::start(&handle).await.map_err(|e| miette::miette!("{}", e))?;
} else {
let node = OkuFs::start().await?;
let node = OkuFs::start().await.map_err(|e| miette::miette!("{}", e))?;
}
};

Expand Down Expand Up @@ -207,7 +208,7 @@ async fn main() -> miette::Result<()> {
"Replicas: {:#?}",
replicas
.par_iter()
.map(|replica| (replica.0.to_string(), replica.1))
.map(|replica| (iroh_base::base32::fmt(replica.0), replica.1))
.collect::<Vec<_>>()
);
}
Expand All @@ -234,9 +235,9 @@ async fn main() -> miette::Result<()> {
new_path,
}) => {
node.move_file(
old_replica_id.clone(),
old_replica_id,
old_path.clone(),
new_replica_id.clone(),
new_replica_id,
new_path.clone(),
)
.await?;
Expand All @@ -252,9 +253,9 @@ async fn main() -> miette::Result<()> {
new_path,
}) => {
node.move_directory(
old_replica_id.clone(),
old_replica_id,
old_path.clone(),
new_replica_id.clone(),
new_replica_id,
new_path.clone(),
)
.await?;
Expand All @@ -274,7 +275,7 @@ async fn main() -> miette::Result<()> {
replica_ticket,
path,
}) => {
node.fetch_replica_by_ticket(&replica_ticket.clone(), path.clone())
node.fetch_replica_by_ticket(&replica_ticket.clone(), path.clone(), None)
.await
.map_err(|e| miette!("{}", e))?;
let files = node
Expand All @@ -292,7 +293,7 @@ async fn main() -> miette::Result<()> {
None => {
info!("Node will listen for incoming connections.");
tokio::signal::ctrl_c().await.into_diagnostic()?;
node.shutdown().await?;
node.shutdown().await;
}
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::fs::FS_PATH;
use iroh::docs::NamespaceId;
use iroh_docs::NamespaceId;
use log::error;
use miette::{miette, IntoDiagnostic};
use serde::{Deserialize, Serialize};
Expand Down
8 changes: 6 additions & 2 deletions src/database/posts.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use super::core::*;
use super::users::*;
use crate::fs::{path_to_entry_key, FS_PATH};
use iroh::{client::docs::Entry, docs::AuthorId};
use iroh_docs::rpc::client::docs::Entry;
use iroh_docs::AuthorId;
use miette::IntoDiagnostic;
use native_db::*;
use native_model::{native_model, Model};
Expand Down Expand Up @@ -94,7 +95,10 @@ impl From<OkuPost> for TantivyDocument {

let mut doc = TantivyDocument::default();
doc.add_bytes(POST_SCHEMA.1["id"], post_key_bytes);
doc.add_text(POST_SCHEMA.1["author_id"], value.entry.author().to_string());
doc.add_text(
POST_SCHEMA.1["author_id"],
iroh_base::base32::fmt(value.entry.author()),
);
doc.add_text(
POST_SCHEMA.1["path"],
String::from_utf8_lossy(value.entry.key()),
Expand Down
3 changes: 2 additions & 1 deletion src/database/users.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::core::*;
use super::posts::*;
use iroh::{client::docs::Entry, docs::AuthorId};
use iroh_docs::rpc::client::docs::Entry;
use iroh_docs::AuthorId;
use log::error;
use miette::IntoDiagnostic;
use native_db::*;
Expand Down
29 changes: 18 additions & 11 deletions src/discovery.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::database::core::DATABASE;
use crate::{error::OkuDiscoveryError, fs::OkuFs};
use iroh::base::ticket::Ticket;
use iroh::blobs::HashAndFormat;
use iroh::docs::CapabilityKind;
use iroh::{client::docs::ShareMode, docs::NamespaceId};
use iroh_base::hash::HashAndFormat;
use iroh_base::ticket::Ticket;
use iroh_docs::rpc::client::docs::ShareMode;
use iroh_docs::sync::CapabilityKind;
use iroh_docs::NamespaceId;
use log::{error, info};
use miette::IntoDiagnostic;
use std::{path::PathBuf, time::Duration};
Expand Down Expand Up @@ -45,11 +46,14 @@ impl OkuFs {
let mutable_item =
mainline::MutableItem::new(replica_private_key, ticket, newest_timestamp, None);
match self.dht.put_mutable(mutable_item).await {
Ok(_) => info!("Announced mutable replica {} … ", namespace_id.to_string()),
Ok(_) => info!(
"Announced mutable replica {} … ",
iroh_base::base32::fmt(namespace_id)
),
Err(e) => error!(
"{}",
OkuDiscoveryError::ProblemAnnouncingContent(
namespace_id.to_string(),
iroh_base::base32::fmt(namespace_id),
e.to_string()
)
),
Expand Down Expand Up @@ -102,12 +106,12 @@ impl OkuFs {
match self.dht.put_mutable(mutable_item).await {
Ok(_) => info!(
"Announced immutable replica {} … ",
namespace_id.to_string()
iroh_base::base32::fmt(namespace_id)
),
Err(e) => error!(
"{}",
OkuDiscoveryError::ProblemAnnouncingContent(
namespace_id.to_string(),
iroh_base::base32::fmt(namespace_id),
e.to_string()
)
),
Expand Down Expand Up @@ -157,11 +161,14 @@ impl OkuFs {
let mutable_item =
mainline::MutableItem::new(author_private_key, ticket, newest_timestamp, None);
match self.dht.put_mutable(mutable_item).await {
Ok(_) => info!("Announced home replica {} … ", home_replica.to_string()),
Ok(_) => info!(
"Announced home replica {} … ",
iroh_base::base32::fmt(home_replica)
),
Err(e) => error!(
"{}",
OkuDiscoveryError::ProblemAnnouncingContent(
home_replica.to_string(),
iroh_base::base32::fmt(home_replica),
e.to_string()
)
),
Expand Down Expand Up @@ -200,7 +207,7 @@ impl OkuFs {
}
}

/// From: https://github.com/n0-computer/iroh-experiments/blob/4e052c6b34720e26683083270706926a84e49411/content-discovery/iroh-mainline-content-discovery/src/client.rs#L53
/// From: <https://github.com/n0-computer/iroh-experiments/blob/4e052c6b34720e26683083270706926a84e49411/content-discovery/iroh-mainline-content-discovery/src/client.rs#L53>
///
/// The mapping from an iroh [HashAndFormat] to a bittorrent infohash, aka [mainline::Id].
///
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use iroh::docs::NamespaceId;
use iroh_docs::NamespaceId;
use miette::Diagnostic;
use std::path::PathBuf;
use thiserror::Error;
Expand Down
Loading

0 comments on commit 53f258d

Please sign in to comment.