Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into refactor-futures
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Apr 22, 2024
2 parents a3e894b + 93290e3 commit 1713a16
Show file tree
Hide file tree
Showing 28 changed files with 2,194 additions and 902 deletions.
16 changes: 14 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 25 additions & 3 deletions iroh-base/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use bao_tree::blake3;
use postcard::experimental::max_size::MaxSize;
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};

use crate::base32::{parse_array_hex_or_base32, HexOrBase32ParseError};
use crate::base32::{self, parse_array_hex_or_base32, HexOrBase32ParseError};

/// Hash type used throughout.
#[derive(PartialEq, Eq, Copy, Clone, Hash)]
Expand Down Expand Up @@ -54,6 +54,12 @@ impl Hash {
pub fn to_hex(&self) -> String {
self.0.to_hex().to_string()
}

/// Convert to a base32 string limited to the first 10 bytes for a friendly string
/// representation of the hash.
pub fn fmt_short(&self) -> String {
base32::fmt_short(self.as_bytes())
}
}

impl AsRef<[u8]> for Hash {
Expand Down Expand Up @@ -173,7 +179,18 @@ impl MaxSize for Hash {

/// A format identifier
#[derive(
Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Default, Debug, MaxSize,
Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord,
Serialize,
Deserialize,
Default,
Debug,
MaxSize,
Hash,
)]
pub enum BlobFormat {
/// Raw blob
Expand Down Expand Up @@ -205,7 +222,7 @@ impl BlobFormat {
}

/// A hash and format pair
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, MaxSize)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, MaxSize, Hash)]
pub struct HashAndFormat {
/// The hash
pub hash: Hash,
Expand Down Expand Up @@ -289,6 +306,11 @@ mod redb_support {
}

impl HashAndFormat {
/// Create a new hash and format pair.
pub fn new(hash: Hash, format: BlobFormat) -> Self {
Self { hash, format }
}

/// Create a new hash and format pair, using the default (raw) format.
pub fn raw(hash: Hash) -> Self {
Self {
Expand Down
7 changes: 5 additions & 2 deletions iroh-bytes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ flume = "0.11"
futures-buffered = "0.2.4"
futures-lite = "2.3"
genawaiter = { version = "0.99.1", features = ["futures03"] }
hashlink = { version = "0.9.0", optional = true }
hex = "0.4.3"
iroh-base = { version = "0.14.0", features = ["redb"], path = "../iroh-base" }
iroh-io = { version = "0.6.0", features = ["stats"] }
Expand All @@ -51,6 +52,7 @@ tracing-futures = "0.2.5"

[dev-dependencies]
http-body = "0.4.5"
iroh-bytes = { path = ".", features = ["downloader"] }
iroh-test = { path = "../iroh-test" }
futures-buffered = "0.2.4"
proptest = "1.0.0"
Expand All @@ -59,13 +61,14 @@ serde_test = "1.0.176"
tokio = { version = "1", features = ["macros", "test-util"] }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
rcgen = "0.12.0"
rustls = { version = "0.21.0", default-features = false, features = ["quic"] }
rustls = { version = "0.21.11", default-features = false, features = ["quic"] }
tempfile = "3.10.0"
futures-util = "0.3.30"

[features]
default = ["fs-store"]
downloader = ["dep:iroh-net", "dep:parking_lot", "tokio-util/time", "dep:hashlink"]
fs-store = ["dep:reflink-copy", "redb", "dep:redb_v1", "dep:tempfile"]
downloader = ["dep:iroh-net", "dep:parking_lot", "tokio-util/time"]
metrics = ["dep:iroh-metrics"]
redb = ["dep:redb"]

Expand Down
Loading

0 comments on commit 1713a16

Please sign in to comment.