Skip to content

Commit

Permalink
Merge branch 'main' into discovery-builder-shortcuts
Browse files Browse the repository at this point in the history
# Conflicts:
#	iroh-net/src/endpoint.rs
  • Loading branch information
rklaehn committed Oct 18, 2024
2 parents eb441f5 + 8808a36 commit a08645b
Show file tree
Hide file tree
Showing 176 changed files with 1,141 additions and 1,062 deletions.
10 changes: 3 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,12 @@ jobs:
SCCACHE_GHA_ENABLED: "on"
steps:
- uses: actions/checkout@v4

- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt

- name: Install sccache
uses: mozilla-actions/[email protected]

- name: fmt
run: cargo fmt --all -- --check
- uses: mozilla-actions/[email protected]
- uses: taiki-e/install-action@cargo-make
- run: cargo make format-check

check_docs:
timeout-minutes: 30
Expand Down
28 changes: 28 additions & 0 deletions Makefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Use cargo-make to run tasks here: https://crates.io/crates/cargo-make

[tasks.format]
workspace = false
command = "cargo"
args = [
"fmt",
"--all",
"--",
"--config",
"unstable_features=true",
"--config",
"imports_granularity=Crate,group_imports=StdExternalCrate,reorder_imports=true",
]

[tasks.format-check]
workspace = false
command = "cargo"
args = [
"fmt",
"--all",
"--check",
"--",
"--config",
"unstable_features=true",
"--config",
"imports_granularity=Crate,group_imports=StdExternalCrate,reorder_imports=true",
]
9 changes: 4 additions & 5 deletions iroh-base/src/hash.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! The blake3 hash used in Iroh.

use std::str::FromStr;
use std::{borrow::Borrow, fmt};
use std::{borrow::Borrow, fmt, str::FromStr};

use postcard::experimental::max_size::MaxSize;
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
Expand Down Expand Up @@ -233,10 +232,11 @@ pub struct HashAndFormat {
#[cfg(feature = "redb")]
#[cfg_attr(iroh_docsrs, cfg(feature = "redb"))]
mod redb_support {
use super::{Hash, HashAndFormat};
use postcard::experimental::max_size::MaxSize;
use redb::{Key as RedbKey, Value as RedbValue};

use super::{Hash, HashAndFormat};

impl RedbValue for Hash {
type SelfType<'a> = Self;

Expand Down Expand Up @@ -397,11 +397,10 @@ impl<'de> Deserialize<'de> for HashAndFormat {
mod tests {

use iroh_test::{assert_eq_hex, hexdump::parse_hexdump};
use serde_test::{assert_tokens, Configure, Token};

use super::*;

use serde_test::{assert_tokens, Configure, Token};

#[test]
fn test_display_parse_roundtrip() {
for i in 0..100 {
Expand Down
2 changes: 1 addition & 1 deletion iroh-base/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use std::{
time::Duration,
};

use crate::base32::{self, HexOrBase32ParseError};
pub use ed25519_dalek::{Signature, PUBLIC_KEY_LENGTH};
use ed25519_dalek::{SignatureError, SigningKey, VerifyingKey};
use once_cell::sync::OnceCell;
Expand All @@ -21,6 +20,7 @@ use ttl_cache::TtlCache;

pub use self::encryption::SharedSecret;
use self::encryption::{public_ed_box, secret_ed_box};
use crate::base32::{self, HexOrBase32ParseError};

#[derive(Debug)]
struct CryptoKeys {
Expand Down
15 changes: 8 additions & 7 deletions iroh-base/src/ticket/blob.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//! Tickets for blobs.
use std::str::FromStr;

use anyhow::Result;
use serde::{Deserialize, Serialize};

use crate::{
hash::{BlobFormat, Hash},
node_addr::NodeAddr,
ticket::{self, Ticket},
};
use anyhow::Result;
use serde::{Deserialize, Serialize};

use crate::node_addr::NodeAddr;

/// A token containing everything to get a file from the provider.
///
Expand Down Expand Up @@ -119,10 +119,11 @@ mod tests {

use iroh_test::{assert_eq_hex, hexdump::parse_hexdump};

use crate::base32;
use crate::key::{PublicKey, SecretKey};

use super::*;
use crate::{
base32,
key::{PublicKey, SecretKey},
};

fn make_ticket() -> BlobTicket {
let hash = Hash::new(b"hi there");
Expand Down
7 changes: 4 additions & 3 deletions iroh-base/src/ticket/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,11 @@ mod tests {

use iroh_test::{assert_eq_hex, hexdump::parse_hexdump};

use crate::base32;
use crate::key::{PublicKey, SecretKey};

use super::*;
use crate::{
base32,
key::{PublicKey, SecretKey},
};

fn make_ticket() -> NodeTicket {
let peer = SecretKey::generate().public();
Expand Down
3 changes: 2 additions & 1 deletion iroh-blobs/examples/connect/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! Common code used to created quinn connections in the examples
use std::{path::PathBuf, sync::Arc};

use anyhow::{bail, Context, Result};
use quinn::crypto::rustls::{QuicClientConfig, QuicServerConfig};
use std::{path::PathBuf, sync::Arc};
use tokio::fs;

pub const EXAMPLE_ALPN: &[u8] = b"n0/iroh/examples/bytes/0";
Expand Down
5 changes: 2 additions & 3 deletions iroh-blobs/examples/fetch-fsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
use std::net::SocketAddr;

use anyhow::{Context, Result};
use iroh_io::ConcatenateSliceWriter;
use tracing_subscriber::{prelude::*, EnvFilter};

use iroh_blobs::{
get::fsm::{AtInitial, ConnectedNext, EndBlobNext},
hashseq::HashSeq,
protocol::GetRequest,
Hash,
};
use iroh_io::ConcatenateSliceWriter;
use tracing_subscriber::{prelude::*, EnvFilter};

mod connect;
use connect::{load_certs, make_client_endpoint};
Expand Down
13 changes: 4 additions & 9 deletions iroh-blobs/examples/fetch-stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,21 @@
//! Since this example does not use [`iroh-net::Endpoint`], it does not do any holepunching, and so will only work locally or between two processes that have public IP addresses.
//!
//! Run the provide-bytes example first. It will give instructions on how to run this example properly.
use std::net::SocketAddr;
use std::{io, net::SocketAddr};

use anyhow::{Context, Result};
use tracing_subscriber::{prelude::*, EnvFilter};

use std::io;

use bao_tree::io::fsm::BaoContentItem;
use bytes::Bytes;
use futures_lite::{Stream, StreamExt};
use genawaiter::sync::Co;
use genawaiter::sync::Gen;
use tokio::io::AsyncWriteExt;

use genawaiter::sync::{Co, Gen};
use iroh_blobs::{
get::fsm::{AtInitial, BlobContentNext, ConnectedNext, EndBlobNext},
hashseq::HashSeq,
protocol::GetRequest,
Hash,
};
use tokio::io::AsyncWriteExt;
use tracing_subscriber::{prelude::*, EnvFilter};

mod connect;
use connect::{load_certs, make_client_endpoint};
Expand Down
3 changes: 1 addition & 2 deletions iroh-blobs/examples/provide-bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
//! cargo run --example provide-bytes collection
//! To provide a collection (multiple blobs)
use anyhow::Result;
use iroh_blobs::{format::collection::Collection, util::local_pool::LocalPool, Hash};
use tracing::warn;
use tracing_subscriber::{prelude::*, EnvFilter};

use iroh_blobs::{format::collection::Collection, util::local_pool::LocalPool, Hash};

mod connect;
use connect::{make_and_write_certs, make_server_endpoint, CERT_PATH};

Expand Down
11 changes: 6 additions & 5 deletions iroh-blobs/src/downloader/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
//!
//! [`Connection`]: iroh_net::endpoint::Connection

use crate::{
get::{db::get_to_db_in_steps, error::GetError},
store::Store,
};
use futures_lite::FutureExt;
use iroh_net::endpoint;

use super::{progress::BroadcastProgressSender, DownloadKind, FailureAction, GetStartFut, Getter};
use crate::{
get::{db::get_to_db_in_steps, error::GetError},
store::Store,
};

impl From<GetError> for FailureAction {
fn from(e: GetError) -> Self {
Expand Down Expand Up @@ -74,8 +74,9 @@ impl super::NeedsConn<endpoint::Connection> for crate::get::db::GetStateNeedsCon

#[cfg(feature = "metrics")]
fn track_metrics(res: &Result<crate::get::Stats, GetError>) {
use crate::metrics::Metrics;
use iroh_metrics::{inc, inc_by};

use crate::metrics::Metrics;
match res {
Ok(stats) => {
let crate::get::Stats {
Expand Down
3 changes: 1 addition & 2 deletions iroh-blobs/src/downloader/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ use std::{
use anyhow::anyhow;
use parking_lot::Mutex;

use super::DownloadKind;
use crate::{
get::{db::DownloadProgress, progress::TransferState},
util::progress::{AsyncChannelProgressSender, IdGenerator, ProgressSendError, ProgressSender},
};

use super::DownloadKind;

/// The channel that can be used to subscribe to progress updates.
pub type ProgressSubscriber = AsyncChannelProgressSender<DownloadProgress>;

Expand Down
5 changes: 2 additions & 3 deletions iroh-blobs/src/downloader/test.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#![cfg(test)]
use anyhow::anyhow;
use std::{
sync::atomic::AtomicUsize,
time::{Duration, Instant},
};

use anyhow::anyhow;
use futures_util::future::FutureExt;
use iroh_net::key::SecretKey;

use super::*;
use crate::{
get::{
db::BlobId,
Expand All @@ -19,8 +20,6 @@ use crate::{
},
};

use super::*;

mod dialer;
mod getter;

Expand Down
3 changes: 1 addition & 2 deletions iroh-blobs/src/downloader/test/getter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
use futures_lite::{future::Boxed as BoxFuture, FutureExt};
use parking_lot::RwLock;

use crate::downloader;

use super::*;
use crate::downloader;

#[derive(Default, Clone, derive_more::Debug)]
#[debug("TestingGetter")]
Expand Down
33 changes: 17 additions & 16 deletions iroh-blobs/src/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,23 @@
//! or you can choose to finish early.
//!
//! [iroh-net]: https://docs.rs/iroh-net
use std::error::Error;
use std::fmt::{self, Debug};
use std::time::{Duration, Instant};
use std::{
error::Error,
fmt::{self, Debug},
time::{Duration, Instant},
};

use crate::Hash;
use anyhow::Result;
use bao_tree::io::fsm::BaoContentItem;
use bao_tree::ChunkNum;
use bao_tree::{io::fsm::BaoContentItem, ChunkNum};
use iroh_net::endpoint::{self, RecvStream, SendStream};
use serde::{Deserialize, Serialize};
use tracing::{debug, error};

use crate::protocol::RangeSpecSeq;
use crate::util::io::{TrackingReader, TrackingWriter};
use crate::IROH_BLOCK_SIZE;
use crate::{
protocol::RangeSpecSeq,
util::io::{TrackingReader, TrackingWriter},
Hash, IROH_BLOCK_SIZE,
};

pub mod db;
pub mod error;
Expand Down Expand Up @@ -59,13 +61,6 @@ impl Stats {
pub mod fsm {
use std::{io, result};

use crate::{
protocol::{GetRequest, NonEmptyRequestRangeSpecIter, Request, MAX_MESSAGE_SIZE},
store::BaoBatchWriter,
};

use super::*;

use bao_tree::{
io::fsm::{OutboardMut, ResponseDecoder, ResponseDecoderNext},
BaoTree, ChunkRanges, TreeNode,
Expand All @@ -75,6 +70,12 @@ pub mod fsm {
use iroh_net::endpoint::Connection;
use tokio::io::AsyncWriteExt;

use super::*;
use crate::{
protocol::{GetRequest, NonEmptyRequestRangeSpecIter, Request, MAX_MESSAGE_SIZE},
store::BaoBatchWriter,
};

type WrappedRecvStream = TrackingReader<TokioStreamReader<RecvStream>>;

self_cell::self_cell! {
Expand Down
Loading

0 comments on commit a08645b

Please sign in to comment.