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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
55 changed files with 207 additions and 120 deletions

View File

@ -62,35 +62,34 @@ atomic = "0.5.0"
bytes = "0.5"
futures = "0.3.1"
lazy_static = "1.2"
libp2p-core = { version = "0.24.0", path = "core" }
libp2p-core = { version = "0.25.0", path = "core" }
libp2p-core-derive = { version = "0.20.2", path = "misc/core-derive" }
libp2p-floodsub = { version = "0.24.0", path = "protocols/floodsub", optional = true }
libp2p-gossipsub = { version = "0.24.0", path = "./protocols/gossipsub", optional = true }
libp2p-identify = { version = "0.24.0", path = "protocols/identify", optional = true }
libp2p-kad = { version = "0.25.0", path = "protocols/kad", optional = true }
libp2p-mplex = { version = "0.24.0", path = "muxers/mplex", optional = true }
libp2p-noise = { version = "0.26.0", path = "protocols/noise", optional = true }
libp2p-ping = { version = "0.24.0", path = "protocols/ping", optional = true }
libp2p-plaintext = { version = "0.24.1", path = "protocols/plaintext", optional = true }
libp2p-floodsub = { version = "0.25.0", path = "protocols/floodsub", optional = true }
libp2p-gossipsub = { version = "0.25.0", path = "./protocols/gossipsub", optional = true }
libp2p-identify = { version = "0.25.0", path = "protocols/identify", optional = true }
libp2p-kad = { version = "0.26.0", path = "protocols/kad", optional = true }
libp2p-mplex = { version = "0.25.0", path = "muxers/mplex", optional = true }
libp2p-noise = { version = "0.27.0", path = "protocols/noise", optional = true }
libp2p-ping = { version = "0.25.0", path = "protocols/ping", optional = true }
libp2p-plaintext = { version = "0.25.0", path = "protocols/plaintext", optional = true }
libp2p-pnet = { version = "0.19.2", path = "protocols/pnet", optional = true }
libp2p-request-response = { version = "0.5.0", path = "protocols/request-response", optional = true }
libp2p-swarm = { version = "0.24.0", path = "swarm" }
libp2p-uds = { version = "0.24.0", path = "transports/uds", optional = true }
libp2p-wasm-ext = { version = "0.24.0", path = "transports/wasm-ext", optional = true }
libp2p-yamux = { version = "0.27.0", path = "muxers/yamux", optional = true }
libp2p-request-response = { version = "0.6.0", path = "protocols/request-response", optional = true }
libp2p-swarm = { version = "0.25.0", path = "swarm" }
libp2p-uds = { version = "0.25.0", path = "transports/uds", optional = true }
libp2p-wasm-ext = { version = "0.25.0", path = "transports/wasm-ext", optional = true }
libp2p-yamux = { version = "0.28.0", path = "muxers/yamux", optional = true }
multiaddr = { package = "parity-multiaddr", version = "0.9.4", path = "misc/multiaddr" }
multihash = "0.11.3"
parking_lot = "0.11.0"
pin-project = "1.0.0"
smallvec = "1.0"
wasm-timer = "0.2.4"
[target.'cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))'.dependencies]
libp2p-deflate = { version = "0.24.0", path = "protocols/deflate", optional = true }
libp2p-dns = { version = "0.24.0", path = "transports/dns", optional = true }
libp2p-mdns = { version = "0.24.0", path = "protocols/mdns", optional = true }
libp2p-tcp = { version = "0.24.0", path = "transports/tcp", optional = true }
libp2p-websocket = { version = "0.25.0", path = "transports/websocket", optional = true }
libp2p-deflate = { version = "0.25.0", path = "protocols/deflate", optional = true }
libp2p-dns = { version = "0.25.0", path = "transports/dns", optional = true }
libp2p-mdns = { version = "0.25.0", path = "protocols/mdns", optional = true }
libp2p-tcp = { version = "0.25.0", path = "transports/tcp", optional = true }
libp2p-websocket = { version = "0.26.0", path = "transports/websocket", optional = true }
[dev-dependencies]
async-std = "1.6.2"

View File

@ -1,3 +1,7 @@
# 0.25.0 [unreleased]
- Update `multihash`.
# 0.24.0 [2020-11-09]
- Remove `ConnectionInfo` trait and replace it with `PeerId`

View File

@ -2,7 +2,7 @@
name = "libp2p-core"
edition = "2018"
description = "Core traits and structs of libp2p"
version = "0.24.0"
version = "0.25.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -12,6 +12,7 @@ categories = ["network-programming", "asynchronous"]
[dependencies]
asn1_der = "0.6.1"
bs58 = "0.4.0"
bytes = "0.5"
ed25519-dalek = "1.0.1"
either = "1.5"
fnv = "1.0"
@ -21,7 +22,7 @@ lazy_static = "1.2"
libsecp256k1 = { version = "0.3.1", optional = true }
log = "0.4"
multiaddr = { package = "parity-multiaddr", version = "0.9.4", path = "../misc/multiaddr" }
multihash = "0.11.3"
multihash = { version = "0.13", default-features = false, features = ["std", "multihash-impl", "identity", "sha2"] }
multistream-select = { version = "0.8.5", path = "../misc/multistream-select" }
parking_lot = "0.11.0"
pin-project = "1.0.0"
@ -43,6 +44,7 @@ async-std = "1.6.2"
libp2p-mplex = { path = "../muxers/mplex" }
libp2p-noise = { path = "../protocols/noise" }
libp2p-tcp = { path = "../transports/tcp", features = ["async-std"] }
multihash = { version = "0.13", default-features = false, features = ["arb"] }
quickcheck = "0.9.0"
wasm-timer = "0.2"

View File

@ -55,6 +55,7 @@ pub mod transport;
pub mod upgrade;
pub use multiaddr::Multiaddr;
pub use multihash;
pub use muxing::StreamMuxer;
pub use peer_id::PeerId;
pub use identity::PublicKey;

View File

@ -19,9 +19,10 @@
// DEALINGS IN THE SOFTWARE.
use crate::PublicKey;
use bytes::Bytes;
use bs58;
use thiserror::Error;
use multihash::{self, Code, Multihash};
use multihash::{Code, Multihash, MultihashDigest};
use rand::Rng;
use std::{convert::TryFrom, borrow::Borrow, fmt, hash, str::FromStr, cmp};
@ -35,7 +36,7 @@ const MAX_INLINE_KEY_LENGTH: usize = 42;
// TODO: maybe keep things in decoded version?
#[derive(Clone, Eq)]
pub struct PeerId {
multihash: Multihash,
multihash: Bytes,
}
impl fmt::Debug for PeerId {
@ -78,7 +79,7 @@ impl PeerId {
Code::Sha2_256
};
let multihash = hash_algorithm.digest(&key_enc);
let multihash = hash_algorithm.digest(&key_enc).to_bytes().into();
PeerId { multihash }
}
@ -86,9 +87,9 @@ impl PeerId {
/// Checks whether `data` is a valid `PeerId`. If so, returns the `PeerId`. If not, returns
/// back the data as an error.
pub fn from_bytes(data: Vec<u8>) -> Result<PeerId, Vec<u8>> {
match Multihash::from_bytes(data) {
Ok(multihash) => PeerId::from_multihash(multihash).map_err(Multihash::into_bytes),
Err(err) => Err(err.data),
match Multihash::from_bytes(&data) {
Ok(multihash) => PeerId::from_multihash(multihash).map_err(|_| data),
Err(_err) => Err(data),
}
}
@ -98,10 +99,10 @@ impl PeerId {
/// or the hash value does not satisfy the constraints for a hashed
/// peer ID, it is returned as an `Err`.
pub fn from_multihash(multihash: Multihash) -> Result<PeerId, Multihash> {
match multihash.algorithm() {
Code::Sha2_256 => Ok(PeerId { multihash }),
Code::Identity if multihash.digest().len() <= MAX_INLINE_KEY_LENGTH
=> Ok(PeerId { multihash }),
match Code::try_from(multihash.code()) {
Ok(Code::Sha2_256) => Ok(PeerId { multihash: multihash.to_bytes().into() }),
Ok(Code::Identity) if multihash.digest().len() <= MAX_INLINE_KEY_LENGTH
=> Ok(PeerId { multihash: multihash.to_bytes().into() }),
_ => Err(multihash)
}
}
@ -112,7 +113,8 @@ impl PeerId {
pub fn random() -> PeerId {
let peer_id = rand::thread_rng().gen::<[u8; 32]>();
PeerId {
multihash: multihash::wrap(Code::Identity, &peer_id),
multihash: Multihash::wrap(Code::Identity.into(), &peer_id)
.expect("The digest size is never too large").to_bytes().into()
}
}
@ -122,7 +124,7 @@ impl PeerId {
/// equality of peer IDs. That is, two peer IDs may be considered equal
/// while having a different byte representation as per `into_bytes`.
pub fn into_bytes(self) -> Vec<u8> {
self.multihash.into_bytes()
self.multihash.to_vec()
}
/// Returns a raw bytes representation of this `PeerId`.
@ -131,7 +133,7 @@ impl PeerId {
/// equality of peer IDs. That is, two peer IDs may be considered equal
/// while having a different byte representation as per `as_bytes`.
pub fn as_bytes(&self) -> &[u8] {
self.multihash.as_bytes()
&self.multihash
}
/// Returns a base-58 encoded string of this `PeerId`.
@ -144,9 +146,12 @@ impl PeerId {
/// Returns `None` if this `PeerId`s hash algorithm is not supported when encoding the
/// given public key, otherwise `Some` boolean as the result of an equality check.
pub fn is_public_key(&self, public_key: &PublicKey) -> Option<bool> {
let alg = self.multihash.algorithm();
let multihash = Multihash::from_bytes(&self.multihash)
.expect("Internal multihash is always a valid");
let alg = Code::try_from(multihash.code())
.expect("Internal multihash is always a valid `Code`");
let enc = public_key.clone().into_protobuf_encoding();
Some(alg.digest(&enc) == self.multihash)
Some(alg.digest(&enc) == multihash)
}
}
@ -192,7 +197,7 @@ impl PartialEq<PeerId> for PeerId {
impl Borrow<[u8]> for PeerId {
fn borrow(&self) -> &[u8] {
self.multihash.as_bytes()
&self.multihash
}
}
@ -207,7 +212,8 @@ impl AsRef<[u8]> for PeerId {
impl From<PeerId> for Multihash {
fn from(peer_id: PeerId) -> Self {
peer_id.multihash
Multihash::from_bytes(&peer_id.multihash)
.expect("PeerIds always contain valid Multihashes")
}
}

View File

@ -16,7 +16,7 @@ arrayref = "0.3"
bs58 = "0.4.0"
byteorder = "1.3.1"
data-encoding = "2.1"
multihash = "0.11.3"
multihash = { version = "0.13", default-features = false, features = ["std"] }
percent-encoding = "2.1.0"
serde = "1.0.70"
static_assertions = "1.1"

View File

@ -51,8 +51,8 @@ impl From<io::Error> for Error {
}
}
impl From<multihash::DecodeOwnedError> for Error {
fn from(err: multihash::DecodeOwnedError) -> Error {
impl From<multihash::Error> for Error {
fn from(err: multihash::Error) -> Error {
Error::ParsingError(err.into())
}
}

View File

@ -156,7 +156,7 @@ impl<'a> Protocol<'a> {
"p2p" => {
let s = iter.next().ok_or(Error::InvalidProtocolString)?;
let decoded = bs58::decode(s).into_vec()?;
Ok(Protocol::P2p(Multihash::from_bytes(decoded)?))
Ok(Protocol::P2p(Multihash::from_bytes(&decoded)?))
}
"http" => Ok(Protocol::Http),
"https" => Ok(Protocol::Https),
@ -280,7 +280,7 @@ impl<'a> Protocol<'a> {
P2P => {
let (n, input) = decode::usize(input)?;
let (data, rest) = split_at(n, input)?;
Ok((Protocol::P2p(Multihash::from_bytes(data.to_owned())?), rest))
Ok((Protocol::P2p(Multihash::from_bytes(data)?), rest))
}
P2P_CIRCUIT => Ok((Protocol::P2pCircuit, input)),
QUIC => Ok((Protocol::Quic, input)),
@ -388,7 +388,7 @@ impl<'a> Protocol<'a> {
}
Protocol::P2p(multihash) => {
w.write_all(encode::u32(P2P, &mut buf))?;
let bytes = multihash.as_bytes();
let bytes = multihash.to_bytes();
w.write_all(encode::usize(bytes.len(), &mut encode::usize_buffer()))?;
w.write_all(&bytes)?
}
@ -492,7 +492,7 @@ impl<'a> fmt::Display for Protocol<'a> {
let s = BASE32.encode(addr.hash());
write!(f, "/onion3/{}:{}", s.to_lowercase(), addr.port())
}
P2p(c) => write!(f, "/p2p/{}", bs58::encode(c.as_bytes()).into_string()),
P2p(c) => write!(f, "/p2p/{}", bs58::encode(c.to_bytes()).into_string()),
P2pCircuit => f.write_str("/p2p-circuit"),
Quic => f.write_str("/quic"),
Sctp(port) => write!(f, "/sctp/{}", port),
@ -584,4 +584,4 @@ read_onion_impl!(read_onion, 10, 16);
// Parse a version 3 onion address and return its binary representation.
//
// Format: <base-32 address> ":" <port number>
read_onion_impl!(read_onion3, 35, 56);
read_onion_impl!(read_onion3, 35, 56);

View File

@ -140,7 +140,7 @@ fn ma_valid(source: &str, target: &str, protocols: Vec<Protocol<'_>>) {
}
fn multihash(s: &str) -> Multihash {
Multihash::from_bytes(bs58::decode(s).into_vec().unwrap()).unwrap()
Multihash::from_bytes(&bs58::decode(s).into_vec().unwrap()).unwrap()
}
#[test]

View File

@ -1,4 +1,6 @@
# 0.24.1 [unreleased]
# 0.25.0 [unreleased]
- Update `libp2p-core`.
- Change the default `split_send_size` from 1KiB to 8KiB.
[PR 1834](https://github.com/libp2p/rust-libp2p/pull/1834).

View File

@ -2,7 +2,7 @@
name = "libp2p-mplex"
edition = "2018"
description = "Mplex multiplexing 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,7 +13,7 @@ categories = ["network-programming", "asynchronous"]
bytes = "0.5"
futures = "0.3.1"
futures_codec = "0.4.1"
libp2p-core = { version = "0.24.0", path = "../../core" }
libp2p-core = { version = "0.25.0", path = "../../core" }
log = "0.4"
nohash-hasher = "0.2"
parking_lot = "0.11"

View File

@ -1,3 +1,7 @@
# 0.28.0 [unreleased]
- Update `libp2p-core`.
# 0.27.0 [2020-11-09]
- Tweak the naming in the `MplexConfig` API for better

View File

@ -2,7 +2,7 @@
name = "libp2p-yamux"
edition = "2018"
description = "Yamux multiplexing protocol for libp2p"
version = "0.27.0"
version = "0.28.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" }
parking_lot = "0.11"
thiserror = "1.0"
yamux = "0.8.0"

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"

View File

@ -162,7 +162,7 @@ pub use futures;
#[doc(inline)]
pub use multiaddr;
#[doc(inline)]
pub use multihash;
pub use libp2p_core::multihash;
#[doc(inline)]
pub use libp2p_core as core;

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-swarm"
edition = "2018"
description = "The libp2p swarm"
version = "0.24.0"
version = "0.25.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"]
[dependencies]
either = "1.6.0"
futures = "0.3.1"
libp2p-core = { version = "0.24.0", path = "../core" }
libp2p-core = { version = "0.25.0", path = "../core" }
log = "0.4"
rand = "0.7"
smallvec = "1.0"

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-dns"
edition = "2018"
description = "DNS transport implementation 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"
@ -10,6 +10,6 @@ keywords = ["peer-to-peer", "libp2p", "networking"]
categories = ["network-programming", "asynchronous"]
[dependencies]
libp2p-core = { version = "0.24.0", path = "../../core" }
libp2p-core = { version = "0.25.0", path = "../../core" }
log = "0.4.1"
futures = "0.3.1"

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-tcp"
edition = "2018"
description = "TCP/IP transport 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"
@ -15,7 +15,7 @@ futures = "0.3.1"
futures-timer = "3.0"
if-addrs = "0.6.4"
ipnet = "2.0.0"
libp2p-core = { version = "0.24.0", path = "../../core" }
libp2p-core = { version = "0.25.0", path = "../../core" }
log = "0.4.1"
socket2 = { version = "0.3.12" }
tokio = { version = "0.3", default-features = false, features = ["net"], optional = true }

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-uds"
edition = "2018"
description = "Unix domain sockets transport 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"]
[target.'cfg(all(unix, not(target_os = "emscripten")))'.dependencies]
async-std = { version = "1.6.2", optional = true }
libp2p-core = { version = "0.24.0", path = "../../core" }
libp2p-core = { version = "0.25.0", path = "../../core" }
log = "0.4.1"
futures = "0.3.1"
tokio = { version = "0.3", default-features = false, features = ["net"], optional = true }

View File

@ -1,3 +1,7 @@
# 0.25.0 [unreleased]
- Update `libp2p-core`.
# 0.24.0 [2020-11-09]
- Fix the WebSocket implementation parsing `x-parity-ws` multiaddresses as `x-parity-wss`.

View File

@ -1,6 +1,6 @@
[package]
name = "libp2p-wasm-ext"
version = "0.24.0"
version = "0.25.0"
authors = ["Pierre Krieger <pierre.krieger1708@gmail.com>"]
edition = "2018"
description = "Allows passing in an external transport in a WASM environment"
@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"]
[dependencies]
futures = "0.3.1"
js-sys = "0.3.19"
libp2p-core = { version = "0.24.0", path = "../../core" }
libp2p-core = { version = "0.25.0", path = "../../core" }
parity-send-wrapper = "0.1.0"
wasm-bindgen = "0.2.42"
wasm-bindgen-futures = "0.4.4"

View File

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

View File

@ -2,7 +2,7 @@
name = "libp2p-websocket"
edition = "2018"
description = "WebSocket transport 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"
@ -13,7 +13,7 @@ categories = ["network-programming", "asynchronous"]
async-tls = "0.10.0"
either = "1.5.3"
futures = "0.3.1"
libp2p-core = { version = "0.24.0", path = "../../core" }
libp2p-core = { version = "0.25.0", path = "../../core" }
log = "0.4.8"
quicksink = "0.1"
rustls = "0.18.0"