Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update deps cid, multihash, and ipld #309

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
312 changes: 160 additions & 152 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 12 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async-channel = "1.7.1"
async-recursion = "1"
async-stream = "0.3"
async-trait = "0.1"
asynchronous-codec = "0.6"
asynchronous-codec = "0.7"
axum = "0.6"
backoff = "0.4"
base64 = "0.20.0"
Expand All @@ -50,21 +50,22 @@ bytesize = "1.1"
ceramic-api = { path = "./api" }
ceramic-api-server = { path = "./api-server" }
ceramic-core = { path = "./core" }
ceramic-event = { path = "./event" }
ceramic-kubo-rpc-server = { path = "./kubo-rpc-server" }
ceramic-metadata = { path = "./metadata" }
ceramic-metrics = { path = "./metrics" }
ceramic-one = { path = "./one" }
ceramic-p2p = { path = "./p2p" }
ceramic-store = { path = "./store" }
cid = { version = "0.10", features = ["serde-codec"] }
cid = { version = "0.11", features = ["serde-codec"] }
clap = { version = "4", features = ["derive", "env"] }
clap_mangen = "0.2.2"
console = { version = "0.15", default-features = false }
console-subscriber = "0.2"
criterion2 = "0.7.0"
crossterm = "0.25"
ctrlc = "3.2.2"
dag-jose = "0.1.3"
dag-jose = "0.2"
deadqueue = "0.2.3"
derivative = "2.2"
derive_more = "0.99.17"
Expand All @@ -88,6 +89,8 @@ hyper = { version = "0.14", features = ["full"] }
ignore = "0.4.18"
indicatif = "0.17.1"
integer-encoding = "3.0"
ipld-core = "0.4"
ipld-dagpb = "0.2"
iroh-bitswap = { path = "./beetle/iroh-bitswap" }
iroh-car = { path = "./beetle/iroh-car" }
iroh-p2p = { version = "0.2.0", path = "./beetle/iroh-p2p" }
Expand All @@ -96,8 +99,6 @@ iroh-rpc-types = { path = "./beetle/iroh-rpc-types" }
iroh-util = { path = "./beetle/iroh-util" }
keyed_priority_queue = "0.4.1"
lazy_static = "1.4"
libipld = "0.16"
libipld-cbor = "0.16"
libp2p = { version = "0.53", default-features = false }
libp2p-identity = { version = "0.2", features = ["peerid", "ed25519"] }
lru = "0.10"
Expand All @@ -108,7 +109,9 @@ minicbor = { version = "0.19.1", features = ["std", "derive", "half"] }
mockall = "0.11.4"
multiaddr = "0.18"
multibase = "0.9"
multihash = { version = "0.18", features = ["identity"] }
multihash = { version = "0.19" }
multihash-codetable = { version = "0.1", features = ["sha2", "sha3"] }
multihash-derive = { version = "0.9" }
names = { version = "0.14.0", default-features = false }
nix = "0.26"
num_enum = "0.5.7"
Expand Down Expand Up @@ -138,7 +141,8 @@ serde = { version = "1.0", features = ["derive"] }
serde-error = "0.1.2"
serde_bytes = "0.11"
serde_cbor = "0.11.2"
serde_ipld_dagcbor = "0.3"
serde_ipld_dagcbor = "0.6"
serde_ipld_dagjson = "0.2"
serde_json = "1.0.87"
serde_qs = "0.10.1"
serde_with = "2.1"
Expand Down Expand Up @@ -189,7 +193,7 @@ tracing-subscriber = { version = "0.3", features = [
] }
tracing-test = { version = "0.2" }
trust-dns-resolver = "0.22.0"
unsigned-varint = "0.7"
unsigned-varint = "0.8"
url = "2.2.2"
urlencoding = "2.1"
uuid = { version = "1.8.0", features = ["v4"] }
Expand Down
3 changes: 2 additions & 1 deletion beetle/iroh-bitswap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ futures.workspace = true
iroh-util.workspace = true
keyed_priority_queue.workspace = true
libp2p = { workspace = true, features = ["ping"] }
multihash.workspace = true
multihash-codetable.workspace = true
multihash-derive.workspace = true
num_enum.workspace = true
prost.workspace = true
rand.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion beetle/iroh-bitswap/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fmt::Debug;

use bytes::Bytes;
use cid::Cid;
use multihash::{Code, MultihashDigest};
use multihash_codetable::{Code, MultihashDigest};

/// A wrapper around bytes with their `Cid`.
#[derive(Clone, Eq, PartialEq, PartialOrd, Ord)]
Expand Down
2 changes: 1 addition & 1 deletion beetle/iroh-bitswap/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub enum Error {
#[error("Error while parsing cid: {0}")]
Cid(#[from] cid::Error),
#[error("Error while parsing multihash: {0}")]
Multihash(#[from] multihash::Error),
Multihash(#[from] multihash_derive::UnsupportedCode),
#[error("Invalid block presence type {0}")]
InvalidBlockPresenceType(#[from] num_enum::TryFromPrimitiveError<BlockPresenceType>),
#[error("Invalid want type {0}")]
Expand Down
2 changes: 1 addition & 1 deletion beetle/iroh-bitswap/src/prefix.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::convert::TryFrom;

use cid::{self, Cid, Version};
use multihash::{Code, MultihashDigest};
use multihash_codetable::{Code, MultihashDigest};
use unsigned_varint::{decode as varint_decode, encode as varint_encode};

use crate::error::Error;
Expand Down
4 changes: 2 additions & 2 deletions beetle/iroh-bitswap/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ impl BitswapCodec {
}

impl Encoder for BitswapCodec {
type Item = BitswapMessage;
type Item<'a> = BitswapMessage;
type Error = BitswapHandlerError;

fn encode(&mut self, item: Self::Item, dst: &mut BytesMut) -> Result<(), Self::Error> {
fn encode(&mut self, item: Self::Item<'_>, dst: &mut BytesMut) -> Result<(), Self::Error> {
tracing::trace!("sending message protocol: {:?}\n{:?}", self.protocol, item);

let message = match self.protocol {
Expand Down
6 changes: 4 additions & 2 deletions beetle/iroh-car/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@ publish = false
cid.workspace = true
futures.workspace = true
integer-encoding = { workspace = true, features = ["tokio_async"] }
libipld.workspace = true
libipld-cbor.workspace = true
serde_ipld_dagcbor.workspace = true
serde.workspace = true
thiserror.workspace = true
tokio = { workspace = true, features = ["io-util"] }

[dev-dependencies]
multihash.workspace = true
multihash-codetable.workspace = true
tokio = { workspace = true, features = [
"macros",
"sync",
"rt",
"fs",
"io-util",
] }
ipld-core.workspace = true

[features]
4 changes: 3 additions & 1 deletion beetle/iroh-car/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::TryReserveError;

use thiserror::Error;

/// Car utility error
Expand All @@ -10,7 +12,7 @@ pub enum Error {
#[error("Io error: {0}")]
Io(#[from] std::io::Error),
#[error("Cbor encoding error: {0}")]
Cbor(#[from] libipld::error::Error),
Cbor(#[from] serde_ipld_dagcbor::error::EncodeError<TryReserveError>),
#[error("ld read too large {0}")]
LdReadTooLarge(usize),
}
Expand Down
34 changes: 14 additions & 20 deletions beetle/iroh-car/src/header.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use cid::Cid;
use libipld::codec::Codec;
use libipld_cbor::DagCborCodec;
use serde::{Deserialize, Serialize};

use crate::error::Error;

Expand All @@ -17,9 +16,8 @@ impl CarHeader {
}

pub fn decode(buffer: &[u8]) -> Result<Self, Error> {
let header: CarHeaderV1 = DagCborCodec
.decode(buffer)
.map_err(|e| Error::Parsing(e.to_string()))?;
let header: CarHeaderV1 =
serde_ipld_dagcbor::from_slice(buffer).map_err(|e| Error::Parsing(e.to_string()))?;

if header.roots.is_empty() {
return Err(Error::Parsing("empty CAR file".to_owned()));
Expand All @@ -37,7 +35,7 @@ impl CarHeader {
pub fn encode(&self) -> Result<Vec<u8>, Error> {
match self {
CarHeader::V1(ref header) => {
let res = DagCborCodec.encode(header)?;
let res = serde_ipld_dagcbor::to_vec(header)?;
Ok(res)
}
}
Expand All @@ -57,11 +55,9 @@ impl CarHeader {
}

/// CAR file header version 1.
#[derive(Debug, Clone, Default, libipld::DagCbor, PartialEq, Eq)]
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct CarHeaderV1 {
#[ipld]
pub roots: Vec<Cid>,
#[ipld]
pub version: u64,
}

Expand All @@ -80,25 +76,23 @@ impl From<Vec<Cid>> for CarHeaderV1 {

#[cfg(test)]
mod tests {
use libipld::codec::{Decode, Encode};
use libipld_cbor::DagCborCodec;
use multihash::MultihashDigest;
use ipld_core::{codec::Codec, ipld::Ipld};
use multihash_codetable::{Code, MultihashDigest};
use serde_ipld_dagcbor::codec::DagCborCodec;

use super::*;

#[test]
fn symmetric_header_v1() {
let digest = multihash::Code::Blake2b256.digest(b"test");
let cid = Cid::new_v1(DagCborCodec.into(), digest);
let digest = Code::Sha2_256.digest(b"test");
let cid = Cid::new_v1(<DagCborCodec as Codec<Ipld>>::CODE, digest);

let header = CarHeaderV1::from(vec![cid]);

let mut bytes = Vec::new();
header.encode(DagCborCodec, &mut bytes).unwrap();
let bytes = serde_ipld_dagcbor::to_vec(&header).unwrap();

assert_eq!(
CarHeaderV1::decode(DagCborCodec, &mut std::io::Cursor::new(&bytes)).unwrap(),
header
);
let decoded: CarHeaderV1 = serde_ipld_dagcbor::from_slice(&bytes).unwrap();

assert_eq!(decoded, header);
}
}
13 changes: 7 additions & 6 deletions beetle/iroh-car/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,21 @@ mod tests {

use cid::Cid;
use futures::TryStreamExt;
use libipld_cbor::DagCborCodec;
use multihash::MultihashDigest;
use ipld_core::{codec::Codec, ipld::Ipld};
use multihash_codetable::{Code, MultihashDigest};
use serde_ipld_dagcbor::codec::DagCborCodec;

use crate::{header::CarHeaderV1, writer::CarWriter};

use super::*;

#[tokio::test]
async fn car_write_read() {
let digest_test = multihash::Code::Blake2b256.digest(b"test");
let cid_test = Cid::new_v1(DagCborCodec.into(), digest_test);
let digest_test = Code::Sha2_256.digest(b"test");
let cid_test = Cid::new_v1(<DagCborCodec as Codec<Ipld>>::CODE, digest_test);

let digest_foo = multihash::Code::Blake2b256.digest(b"foo");
let cid_foo = Cid::new_v1(DagCborCodec.into(), digest_foo);
let digest_foo = Code::Sha2_256.digest(b"foo");
let cid_foo = Cid::new_v1(<DagCborCodec as Codec<Ipld>>::CODE, digest_foo);

let header = CarHeader::V1(CarHeaderV1::from(vec![cid_foo]));

Expand Down
1 change: 1 addition & 0 deletions beetle/iroh-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ publish = false

[dependencies]
cid.workspace = true
multihash-codetable.workspace = true

[dev-dependencies]
temp-env.workspace = true
Expand Down
6 changes: 2 additions & 4 deletions beetle/iroh-util/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use cid::{
multihash::{Code, MultihashDigest},
Cid,
};
use cid::Cid;
use multihash_codetable::{Code, MultihashDigest};

/// Verifies that the provided bytes hash to the given multihash.
pub fn verify_hash(cid: &Cid, bytes: &[u8]) -> Option<bool> {
Expand Down
2 changes: 2 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ int-enum = "0.5.0"
libp2p-identity.workspace = true
minicbor.workspace = true
multibase.workspace = true
multihash-codetable.workspace = true
multihash-derive.workspace = true
once_cell.workspace = true
regex.workspace = true
serde.workspace = true
Expand Down
7 changes: 3 additions & 4 deletions core/src/event_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
//! hash bytes, 32 bytes
#![warn(missing_docs, missing_debug_implementations, clippy::all)]

use cid::{
multihash::{Hasher, Sha2_256},
Cid,
};
use cid::Cid;
use multihash_codetable::Sha2_256;
use multihash_derive::Hasher;
use serde::{Deserialize, Serialize};
use std::{
cmp::{Eq, Ord},
Expand Down
6 changes: 4 additions & 2 deletions core/src/interest.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! Interest is a structure that declares a range of data in which a node is interested.
use anyhow::Result;
use cid::multihash::{Hasher, Sha2_256};
use minicbor::{Decoder, Encoder};
use multibase::Base;
use multihash_codetable::Sha2_256;
use multihash_derive::Hasher;
use serde::{Deserialize, Serialize};
use std::{fmt::Display, str::FromStr};

Expand Down Expand Up @@ -200,6 +201,7 @@ impl Builder<Init> {
//
// TODO: Emperically measure performance of this size.
const INITIAL_VEC_CAPACITY: usize = 256;

let mut hasher = Sha2_256::default();
hasher.update(sort_key.as_bytes());
// sha256 is 32 bytes safe to unwrap to [u8; 32]
Expand All @@ -208,7 +210,7 @@ impl Builder<Init> {
encoder
// Encode last 8 bytes of the sort_key hash
.bytes(&hash[hash.len() - 8..])
.expect("sort_key should cbor encode");
.expect("sep_key should cbor encode");
Builder {
state: WithSortKey { encoder },
}
Expand Down
3 changes: 2 additions & 1 deletion core/src/jws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ impl Jws {
mod tests {
use super::*;
use crate::{DagCborEncoded, DidDocument, Jwk, JwkSigner};
use cid::multihash::{Code, MultihashDigest};
use cid::Cid;
use multihash_codetable::Code;
use multihash_codetable::MultihashDigest;
use ssi::did::DIDMethod;
use ssi::did::Source;
use ssi::jwk::Params;
Expand Down
7 changes: 4 additions & 3 deletions event/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ publish = false
[dependencies]
anyhow.workspace = true
ceramic-core = { path = "../core" }
multihash.workspace = true
ipld-core.workspace = true
multihash-codetable.workspace = true
once_cell.workspace = true
rand = "0.8.5"
serde.workspace = true
serde_json.workspace = true

[dev-dependencies]
serde_ipld_dagcbor.workspace = true
serde_json.workspace = true
serde_ipld_dagjson.workspace = true
tokio = { workspace = true, features = ["fs", "macros", "rt"] }
tracing.workspace = true
tracing-subscriber.workspace = true
test-log.workspace = true
libipld.workspace = true
expect-test.workspace = true
Loading
Loading