From 0ed25673c288f5911c8a309dbec74b42f9fa4224 Mon Sep 17 00:00:00 2001 From: David Craven Date: Thu, 7 May 2020 15:46:17 +0200 Subject: [PATCH 1/2] Update to latest multihash. --- Cargo.toml | 2 +- core/Cargo.toml | 2 +- core/src/peer_id.rs | 11 +++++------ misc/multiaddr/Cargo.toml | 2 +- protocols/kad/Cargo.toml | 2 +- src/lib.rs | 12 +++++------- 6 files changed, 14 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c00945dde4d..fe5b101c39a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,7 +55,7 @@ secp256k1 = ["libp2p-core/secp256k1", "libp2p-secio/secp256k1"] bytes = "0.5" futures = "0.3.1" multiaddr = { package = "parity-multiaddr", version = "0.8.0", path = "misc/multiaddr" } -multihash = "0.10" +multihash = "0.11.0" lazy_static = "1.2" libp2p-mplex = { version = "0.18.0", path = "muxers/mplex", optional = true } libp2p-identify = { version = "0.18.0", path = "protocols/identify", optional = true } diff --git a/core/Cargo.toml b/core/Cargo.toml index dd7f0461685..5c64bc990b7 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -21,7 +21,7 @@ lazy_static = "1.2" libsecp256k1 = { version = "0.3.1", optional = true } log = "0.4" multiaddr = { package = "parity-multiaddr", version = "0.8.0", path = "../misc/multiaddr" } -multihash = "0.10" +multihash = "0.11.0" multistream-select = { version = "0.8.0", path = "../misc/multistream-select" } parking_lot = "0.10.0" pin-project = "0.4.6" diff --git a/core/src/peer_id.rs b/core/src/peer_id.rs index a4a900964c8..34b3ff6adc0 100644 --- a/core/src/peer_id.rs +++ b/core/src/peer_id.rs @@ -77,10 +77,9 @@ impl PeerId { }; let canonical = canonical_algorithm.map(|alg| - alg.hasher().expect("SHA2-256 hasher is always supported").digest(&key_enc)); + alg.digest(&key_enc)); - let multihash = hash_algorithm.hasher() - .expect("Identity and SHA-256 hasher are always supported").digest(&key_enc); + let multihash = hash_algorithm.digest(&key_enc); PeerId { multihash, canonical } } @@ -158,7 +157,7 @@ impl PeerId { pub fn is_public_key(&self, public_key: &PublicKey) -> Option { let alg = self.multihash.algorithm(); let enc = public_key.clone().into_protobuf_encoding(); - Some(alg.hasher()?.digest(&enc) == self.multihash) + Some(alg.digest(&enc) == self.multihash) } } @@ -321,8 +320,8 @@ mod tests { } fn property(data: Vec, algo1: HashAlgo, algo2: HashAlgo) -> bool { - let a = PeerId::try_from(algo1.0.hasher().unwrap().digest(&data)).unwrap(); - let b = PeerId::try_from(algo2.0.hasher().unwrap().digest(&data)).unwrap(); + let a = PeerId::try_from(algo1.0.digest(&data)).unwrap(); + let b = PeerId::try_from(algo2.0.digest(&data)).unwrap(); if algo1 == algo2 || algo1.0 == Code::Identity || algo2.0 == Code::Identity { a == b diff --git a/misc/multiaddr/Cargo.toml b/misc/multiaddr/Cargo.toml index 239407aeef5..56bb11e764e 100644 --- a/misc/multiaddr/Cargo.toml +++ b/misc/multiaddr/Cargo.toml @@ -13,7 +13,7 @@ arrayref = "0.3" bs58 = "0.3.0" byteorder = "1.3.1" data-encoding = "2.1" -multihash = "0.10" +multihash = "0.11.0" percent-encoding = "2.1.0" serde = "1.0.70" static_assertions = "1.1" diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index a83df53dbe0..b9734d182b6 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -19,7 +19,7 @@ futures = "0.3.1" log = "0.4" libp2p-core = { version = "0.18.0", path = "../../core" } libp2p-swarm = { version = "0.18.0", path = "../../swarm" } -multihash = "0.10" +multihash = "0.11.0" prost = "0.6.1" rand = "0.7.2" sha2 = "0.8.0" diff --git a/src/lib.rs b/src/lib.rs index c907a2a7348..ded22023059 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -262,8 +262,6 @@ pub use self::simple::SimpleProtocol; pub use self::swarm::Swarm; pub use self::transport_ext::TransportExt; -use std::{error, io, time::Duration}; - /// Builds a `Transport` that supports the most commonly-used protocols that libp2p supports. /// /// > **Note**: This `Transport` is not suitable for production usage, as its implementation @@ -271,7 +269,7 @@ use std::{error, io, time::Duration}; #[cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), feature = "tcp", feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux"))] #[cfg_attr(docsrs, doc(cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), feature = "tcp", feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux"))))] pub fn build_development_transport(keypair: identity::Keypair) - -> io::Result> + Send + Sync), Error = impl error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone> + -> std::io::Result> + Send + Sync), Error = impl std::error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone> { build_tcp_ws_secio_mplex_yamux(keypair) } @@ -285,7 +283,7 @@ pub fn build_development_transport(keypair: identity::Keypair) #[cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), feature = "tcp", feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux"))] #[cfg_attr(docsrs, doc(cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), feature = "tcp", feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux"))))] pub fn build_tcp_ws_secio_mplex_yamux(keypair: identity::Keypair) - -> io::Result> + Send + Sync), Error = impl error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone> + -> std::io::Result> + Send + Sync), Error = impl std::error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone> { let transport = { let tcp = tcp::TcpConfig::new().nodelay(true); @@ -299,7 +297,7 @@ pub fn build_tcp_ws_secio_mplex_yamux(keypair: identity::Keypair) .authenticate(secio::SecioConfig::new(keypair)) .multiplex(core::upgrade::SelectUpgrade::new(yamux::Config::default(), mplex::MplexConfig::new())) .map(|(peer, muxer), _| (peer, core::muxing::StreamMuxerBox::new(muxer))) - .timeout(Duration::from_secs(20))) + .timeout(std::time::Duration::from_secs(20))) } /// Builds an implementation of `Transport` that is suitable for usage with the `Swarm`. @@ -311,7 +309,7 @@ pub fn build_tcp_ws_secio_mplex_yamux(keypair: identity::Keypair) #[cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), feature = "tcp", feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux", feature = "pnet"))] #[cfg_attr(docsrs, doc(cfg(all(not(any(target_os = "emscripten", target_os = "unknown")), feature = "tcp", feature = "websocket", feature = "secio", feature = "mplex", feature = "yamux", feature = "pnet"))))] pub fn build_tcp_ws_pnet_secio_mplex_yamux(keypair: identity::Keypair, psk: PreSharedKey) - -> io::Result> + Send + Sync), Error = impl error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone> + -> std::io::Result> + Send + Sync), Error = impl std::error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone> { let transport = { let tcp = tcp::TcpConfig::new().nodelay(true); @@ -326,5 +324,5 @@ pub fn build_tcp_ws_pnet_secio_mplex_yamux(keypair: identity::Keypair, psk: PreS .authenticate(secio::SecioConfig::new(keypair)) .multiplex(core::upgrade::SelectUpgrade::new(yamux::Config::default(), mplex::MplexConfig::new())) .map(|(peer, muxer), _| (peer, core::muxing::StreamMuxerBox::new(muxer))) - .timeout(Duration::from_secs(20))) + .timeout(std::time::Duration::from_secs(20))) } From 3d0399c6b5ad44a8de3ede679e4990766bf28f15 Mon Sep 17 00:00:00 2001 From: David Craven Date: Tue, 12 May 2020 17:39:32 +0200 Subject: [PATCH 2/2] Update changelog. --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fcd438eaecd..5c75aef9fe5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,8 @@ be supported. IPv4 listener addresses are not affected by this change. [PR 1555](https://github.com/libp2p/rust-libp2p/pull/1555) +- `libp2p-core`: Updated to multihash 0.11.0. + # Version 0.18.1 (2020-04-17) - `libp2p-swarm`: Make sure inject_dial_failure is called in all situations.