feat: upgrade multihash (#1792)

* feat: upgrade to multihash 0.13

`multihash` changes a lot internally, it is using stack allocation instead
of heap allocation. This leads to a few limitations in regards on how
`Multihash` can be used.

Therefore `PeerId` is now using a `Bytes` internally so that only minimal
changes are needed.

* Update versions and changelogs.

Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
Co-authored-by: Roman S. Borschel <roman@parity.io>
This commit is contained in:
Volker Mische
2020-11-17 11:15:20 +01:00
committed by GitHub
parent 650812abc3
commit 3f38c1c8bb
55 changed files with 207 additions and 120 deletions

View File

@ -1,3 +1,7 @@
# 0.25.0 [unreleased]
- Update `libp2p-core`.
# 0.24.0 [2020-11-09]
- Update dependencies.

View File

@ -2,7 +2,7 @@
name = "libp2p-deflate"
edition = "2018"
description = "Deflate encryption protocol for libp2p"
version = "0.24.0"
version = "0.25.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -11,7 +11,7 @@ categories = ["network-programming", "asynchronous"]
[dependencies]
futures = "0.3.1"
libp2p-core = { version = "0.24.0", path = "../../core" }
libp2p-core = { version = "0.25.0", path = "../../core" }
flate2 = "1.0"
[dev-dependencies]

View File

@ -1,3 +1,7 @@
# 0.25.0 [unreleased]
- Update `libp2p-swarm` and `libp2p-core`.
# 0.24.0 [2020-11-09]
- Update dependencies.

View File

@ -2,7 +2,7 @@
name = "libp2p-floodsub"
edition = "2018"
description = "Floodsub protocol for libp2p"
version = "0.24.0"
version = "0.25.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -13,8 +13,8 @@ categories = ["network-programming", "asynchronous"]
cuckoofilter = "0.5.0"
fnv = "1.0"
futures = "0.3.1"
libp2p-core = { version = "0.24.0", path = "../../core" }
libp2p-swarm = { version = "0.24.0", path = "../../swarm" }
libp2p-core = { version = "0.25.0", path = "../../core" }
libp2p-swarm = { version = "0.25.0", path = "../../swarm" }
log = "0.4"
prost = "0.6.1"
rand = "0.7"

View File

@ -1,3 +1,7 @@
# 0.25.0 [unreleased]
- Update `libp2p-swarm` and `libp2p-core`.
# 0.24.0 [2020-11-09]
- Update dependencies.

View File

@ -2,7 +2,7 @@
name = "libp2p-gossipsub"
edition = "2018"
description = "Gossipsub protocol for libp2p"
version = "0.24.0"
version = "0.25.0"
authors = ["Age Manning <Age@AgeManning.com>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -10,8 +10,8 @@ keywords = ["peer-to-peer", "libp2p", "networking"]
categories = ["network-programming", "asynchronous"]
[dependencies]
libp2p-swarm = { version = "0.24.0", path = "../../swarm" }
libp2p-core = { version = "0.24.0", path = "../../core" }
libp2p-swarm = { version = "0.25.0", path = "../../swarm" }
libp2p-core = { version = "0.25.0", path = "../../core" }
bytes = "0.5.4"
byteorder = "1.3.2"
fnv = "1.0.6"

View File

@ -1,3 +1,7 @@
# 0.25.0 [unreleased]
- Update `libp2p-swarm` and `libp2p-core`.
# 0.24.0 [2020-11-09]
- Update dependencies.

View File

@ -2,7 +2,7 @@
name = "libp2p-identify"
edition = "2018"
description = "Nodes identifcation protocol for libp2p"
version = "0.24.0"
version = "0.25.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -11,8 +11,8 @@ categories = ["network-programming", "asynchronous"]
[dependencies]
futures = "0.3.1"
libp2p-core = { version = "0.24.0", path = "../../core" }
libp2p-swarm = { version = "0.24.0", path = "../../swarm" }
libp2p-core = { version = "0.25.0", path = "../../core" }
libp2p-swarm = { version = "0.25.0", path = "../../swarm" }
log = "0.4.1"
prost = "0.6.1"
smallvec = "1.0"

View File

@ -1,3 +1,7 @@
# 0.26.0 [unreleased]
- Update `libp2p-core` and `libp2p-swarm`.
# 0.25.0 [2020-11-09]
- Upon newly established connections, delay routing table

View File

@ -2,7 +2,7 @@
name = "libp2p-kad"
edition = "2018"
description = "Kademlia protocol for libp2p"
version = "0.25.0"
version = "0.26.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -17,9 +17,8 @@ fnv = "1.0"
futures_codec = "0.4"
futures = "0.3.1"
log = "0.4"
libp2p-core = { version = "0.24.0", path = "../../core" }
libp2p-swarm = { version = "0.24.0", path = "../../swarm" }
multihash = "0.11.3"
libp2p-core = { version = "0.25.0", path = "../../core" }
libp2p-swarm = { version = "0.25.0", path = "../../swarm" }
prost = "0.6.1"
rand = "0.7.2"
sha2 = "0.9.1"

View File

@ -38,7 +38,8 @@ use libp2p_core::{
identity,
transport::MemoryTransport,
multiaddr::{Protocol, Multiaddr, multiaddr},
upgrade
upgrade,
multihash::{Code, Multihash, MultihashDigest},
};
use libp2p_noise as noise;
use libp2p_swarm::Swarm;
@ -46,7 +47,6 @@ use libp2p_yamux as yamux;
use quickcheck::*;
use rand::{Rng, random, thread_rng, rngs::StdRng, SeedableRng};
use std::{collections::{HashSet, HashMap}, time::Duration, num::NonZeroUsize, u64};
use multihash::{wrap, Code, Multihash};
type TestSwarm = Swarm<Kademlia<MemoryStore>>;
@ -129,7 +129,7 @@ fn build_fully_connected_nodes_with_config(total: usize, cfg: KademliaConfig)
}
fn random_multihash() -> Multihash {
wrap(Code::Sha2_256, &thread_rng().gen::<[u8; 32]>())
Multihash::wrap(Code::Sha2_256.into(), &thread_rng().gen::<[u8; 32]>()).unwrap()
}
#[derive(Clone, Debug)]
@ -934,7 +934,7 @@ fn disjoint_query_does_not_finish_before_all_paths_did() {
let mut trudy = build_node(); // Trudy the intrudor, an adversary.
let mut bob = build_node();
let key = Key::new(&multihash::Sha2_256::digest(&thread_rng().gen::<[u8; 32]>()));
let key = Key::from(Code::Sha2_256.digest(&thread_rng().gen::<[u8; 32]>()));
let record_bob = Record::new(key.clone(), b"bob".to_vec());
let record_trudy = Record::new(key.clone(), b"trudy".to_vec());

View File

@ -19,8 +19,7 @@
// DEALINGS IN THE SOFTWARE.
use uint::*;
use libp2p_core::PeerId;
use multihash::Multihash;
use libp2p_core::{PeerId, multihash::Multihash};
use sha2::{Digest, Sha256};
use sha2::digest::generic_array::{GenericArray, typenum::U32};
use std::borrow::Borrow;
@ -93,9 +92,13 @@ impl<T> Into<KeyBytes> for Key<T> {
}
impl From<Multihash> for Key<Multihash> {
fn from(m: Multihash) -> Self {
Key::new(m)
}
fn from(m: Multihash) -> Self {
let bytes = KeyBytes(Sha256::digest(&m.to_bytes()));
Key {
preimage: m,
bytes
}
}
}
impl From<PeerId> for Key<PeerId> {
@ -182,7 +185,7 @@ impl Distance {
mod tests {
use super::*;
use quickcheck::*;
use multihash::{wrap, Code};
use libp2p_core::multihash::Code;
use rand::Rng;
impl Arbitrary for Key<PeerId> {
@ -194,7 +197,7 @@ mod tests {
impl Arbitrary for Key<Multihash> {
fn arbitrary<G: Gen>(_: &mut G) -> Key<Multihash> {
let hash = rand::thread_rng().gen::<[u8; 32]>();
Key::from(wrap(Code::Sha2_256, &hash))
Key::from(Multihash::wrap(Code::Sha2_256.into(), &hash).unwrap())
}
}

View File

@ -466,15 +466,14 @@ enum PeerState {
#[cfg(test)]
mod tests {
use super::*;
use libp2p_core::PeerId;
use libp2p_core::{PeerId, multihash::{Code, Multihash}};
use quickcheck::*;
use multihash::Multihash;
use rand::{Rng, rngs::StdRng, SeedableRng};
use std::{iter, time::Duration};
fn random_peers<R: Rng>(n: usize, g: &mut R) -> Vec<PeerId> {
(0 .. n).map(|_| PeerId::from_multihash(
multihash::wrap(multihash::Code::Sha2_256, &g.gen::<[u8; 32]>())
Multihash::wrap(Code::Sha2_256.into(), &g.gen::<[u8; 32]>()).unwrap()
).unwrap()).collect()
}

View File

@ -432,6 +432,7 @@ mod tests {
use super::*;
use crate::K_VALUE;
use libp2p_core::multihash::{Code, Multihash};
use quickcheck::*;
use rand::{Rng, seq::SliceRandom};
use std::collections::HashSet;
@ -526,7 +527,7 @@ mod tests {
fn random_peers<R: Rng>(n: usize, g: &mut R) -> Vec<PeerId> {
(0 .. n).map(|_| PeerId::from_multihash(
multihash::wrap(multihash::Code::Sha2_256, &g.gen::<[u8; 32]>())
Multihash::wrap(Code::Sha2_256.into(), &g.gen::<[u8; 32]>()).unwrap()
).unwrap()).collect()
}

View File

@ -23,8 +23,7 @@
pub mod store;
use bytes::Bytes;
use libp2p_core::{PeerId, Multiaddr};
use multihash::Multihash;
use libp2p_core::{PeerId, Multiaddr, multihash::Multihash};
use std::borrow::Borrow;
use std::hash::{Hash, Hasher};
use wasm_timer::Instant;
@ -65,7 +64,7 @@ impl From<Vec<u8>> for Key {
impl From<Multihash> for Key {
fn from(m: Multihash) -> Key {
Key::from(m.into_bytes())
Key::from(m.to_bytes())
}
}
@ -147,14 +146,14 @@ impl ProviderRecord {
mod tests {
use super::*;
use quickcheck::*;
use multihash::{wrap, Code};
use libp2p_core::multihash::Code;
use rand::Rng;
use std::time::Duration;
impl Arbitrary for Key {
fn arbitrary<G: Gen>(_: &mut G) -> Key {
let hash = rand::thread_rng().gen::<[u8; 32]>();
Key::from(wrap(Code::Sha2_256, &hash))
Key::from(Multihash::wrap(Code::Sha2_256.into(), &hash).unwrap())
}
}

View File

@ -215,12 +215,12 @@ impl<'a> RecordStore<'a> for MemoryStore {
#[cfg(test)]
mod tests {
use super::*;
use multihash::{wrap, Code};
use libp2p_core::multihash::{Code, Multihash};
use quickcheck::*;
use rand::Rng;
fn random_multihash() -> Multihash {
wrap(Code::Sha2_256, &rand::thread_rng().gen::<[u8; 32]>())
Multihash::wrap(Code::Sha2_256.into(), &rand::thread_rng().gen::<[u8; 32]>()).unwrap()
}
fn distance(r: &ProviderRecord) -> kbucket::Distance {

View File

@ -1,3 +1,7 @@
# 0.25.0 [unreleased]
- Update `libp2p-swarm` and `libp2p-core`.
# 0.24.0 [2020-11-09]
- Update dependencies.

View File

@ -1,7 +1,7 @@
[package]
name = "libp2p-mdns"
edition = "2018"
version = "0.24.0"
version = "0.25.0"
description = "Implementation of the libp2p mDNS discovery method"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
@ -16,8 +16,8 @@ dns-parser = "0.8"
either = "1.5.3"
futures = "0.3.1"
lazy_static = "1.2"
libp2p-core = { version = "0.24.0", path = "../../core" }
libp2p-swarm = { version = "0.24.0", path = "../../swarm" }
libp2p-core = { version = "0.25.0", path = "../../core" }
libp2p-swarm = { version = "0.25.0", path = "../../swarm" }
log = "0.4"
net2 = "0.2"
rand = "0.7"

View File

@ -589,7 +589,7 @@ mod tests {
macro_rules! testgen {
($runtime_name:ident, $service_name:ty, $block_on_fn:tt) => {
mod $runtime_name {
use libp2p_core::{PeerId, multiaddr::multihash};
use libp2p_core::{PeerId, multihash::{Code, MultihashDigest}};
use std::time::Duration;
use crate::service::MdnsPacket;
@ -683,7 +683,7 @@ mod tests {
#[test]
fn discover_long_peer_id() {
let max_value = String::from_utf8(vec![b'f'; 42]).unwrap();
let hash = multihash::Identity::digest(max_value.as_ref());
let hash = Code::Identity.digest(max_value.as_ref());
discover(PeerId::from_multihash(hash).unwrap())
}
}

View File

@ -1,3 +1,7 @@
# 0.27.0 [unreleased]
- Update `libp2p-core`.
# 0.26.0 [2020-11-09]
- Update dependencies.

View File

@ -1,7 +1,7 @@
[package]
name = "libp2p-noise"
description = "Cryptographic handshake protocol using the noise framework."
version = "0.26.0"
version = "0.27.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -12,7 +12,7 @@ bytes = "0.5"
curve25519-dalek = "3.0.0"
futures = "0.3.1"
lazy_static = "1.2"
libp2p-core = { version = "0.24.0", path = "../../core" }
libp2p-core = { version = "0.25.0", path = "../../core" }
log = "0.4"
prost = "0.6.1"
rand = "0.7.2"

View File

@ -1,3 +1,7 @@
# 0.25.0 [unreleased]
- Update `libp2p-swarm` and `libp2p-core`.
# 0.24.0 [2020-11-09]
- Update dependencies.

View File

@ -2,7 +2,7 @@
name = "libp2p-ping"
edition = "2018"
description = "Ping protocol for libp2p"
version = "0.24.0"
version = "0.25.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -11,8 +11,8 @@ categories = ["network-programming", "asynchronous"]
[dependencies]
futures = "0.3.1"
libp2p-core = { version = "0.24.0", path = "../../core" }
libp2p-swarm = { version = "0.24.0", path = "../../swarm" }
libp2p-core = { version = "0.25.0", path = "../../core" }
libp2p-swarm = { version = "0.25.0", path = "../../swarm" }
log = "0.4.1"
rand = "0.7.2"
void = "1.0"

View File

@ -1,3 +1,7 @@
# 0.25.0 [unreleased]
- Update `libp2p-core`.
# 0.24.1 [2020-11-11]
- Ensure that no follow-up protocol data is dropped at the end of the

View File

@ -2,7 +2,7 @@
name = "libp2p-plaintext"
edition = "2018"
description = "Plaintext encryption dummy protocol for libp2p"
version = "0.24.1"
version = "0.25.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -13,7 +13,7 @@ categories = ["network-programming", "asynchronous"]
bytes = "0.5"
futures = "0.3.1"
futures_codec = "0.4.0"
libp2p-core = { version = "0.24.0", path = "../../core" }
libp2p-core = { version = "0.25.0", path = "../../core" }
log = "0.4.8"
prost = "0.6.1"
unsigned-varint = { version = "0.5.1", features = ["futures-codec"] }

View File

@ -1,3 +1,7 @@
# 0.6.0 [unreleased]
- Update `libp2p-swarm` and `libp2p-core`.
# 0.5.0 [2020-11-09]
- Update dependencies.

View File

@ -2,7 +2,7 @@
name = "libp2p-request-response"
edition = "2018"
description = "Generic Request/Response Protocols"
version = "0.5.0"
version = "0.6.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -13,8 +13,8 @@ categories = ["network-programming", "asynchronous"]
async-trait = "0.1"
bytes = "0.5.6"
futures = "0.3.1"
libp2p-core = { version = "0.24.0", path = "../../core" }
libp2p-swarm = { version = "0.24.0", path = "../../swarm" }
libp2p-core = { version = "0.25.0", path = "../../core" }
libp2p-swarm = { version = "0.25.0", path = "../../swarm" }
log = "0.4.11"
lru = "0.6"
minicbor = { version = "0.7", features = ["std", "derive"] }

View File

@ -1,3 +1,7 @@
# 0.25.0 [unreleased]
- Update `libp2p-core`.
# 0.24.0 [2020-11-09]
- Update dependencies.

View File

@ -2,7 +2,7 @@
name = "libp2p-secio"
edition = "2018"
description = "Secio encryption protocol for libp2p"
version = "0.24.0"
version = "0.25.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -19,7 +19,7 @@ ctr = "0.3"
futures = "0.3.1"
hmac = "0.9.0"
lazy_static = "1.2.0"
libp2p-core = { version = "0.24.0", path = "../../core" }
libp2p-core = { version = "0.25.0", path = "../../core" }
log = "0.4.6"
prost = "0.6.1"
pin-project = "1.0.0"