Update to latest multihash. (#1566)

* Update to latest multihash.

* Update changelog.

Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
This commit is contained in:
David Craven
2020-05-13 17:51:11 +02:00
committed by GitHub
parent a83654ca4c
commit 0443fea157
7 changed files with 16 additions and 17 deletions

View File

@ -27,6 +27,8 @@
be supported. IPv4 listener addresses are not affected by this change. be supported. IPv4 listener addresses are not affected by this change.
[PR 1555](https://github.com/libp2p/rust-libp2p/pull/1555) [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) # Version 0.18.1 (2020-04-17)
- `libp2p-swarm`: Make sure inject_dial_failure is called in all situations. - `libp2p-swarm`: Make sure inject_dial_failure is called in all situations.

View File

@ -55,7 +55,7 @@ secp256k1 = ["libp2p-core/secp256k1", "libp2p-secio/secp256k1"]
bytes = "0.5" bytes = "0.5"
futures = "0.3.1" futures = "0.3.1"
multiaddr = { package = "parity-multiaddr", version = "0.8.0", path = "misc/multiaddr" } multiaddr = { package = "parity-multiaddr", version = "0.8.0", path = "misc/multiaddr" }
multihash = "0.10" multihash = "0.11.0"
lazy_static = "1.2" lazy_static = "1.2"
libp2p-mplex = { version = "0.18.0", path = "muxers/mplex", optional = true } libp2p-mplex = { version = "0.18.0", path = "muxers/mplex", optional = true }
libp2p-identify = { version = "0.18.0", path = "protocols/identify", optional = true } libp2p-identify = { version = "0.18.0", path = "protocols/identify", optional = true }

View File

@ -21,7 +21,7 @@ lazy_static = "1.2"
libsecp256k1 = { version = "0.3.1", optional = true } libsecp256k1 = { version = "0.3.1", optional = true }
log = "0.4" log = "0.4"
multiaddr = { package = "parity-multiaddr", version = "0.8.0", path = "../misc/multiaddr" } 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" } multistream-select = { version = "0.8.0", path = "../misc/multistream-select" }
parking_lot = "0.10.0" parking_lot = "0.10.0"
pin-project = "0.4.6" pin-project = "0.4.6"

View File

@ -77,10 +77,9 @@ impl PeerId {
}; };
let canonical = canonical_algorithm.map(|alg| 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() let multihash = hash_algorithm.digest(&key_enc);
.expect("Identity and SHA-256 hasher are always supported").digest(&key_enc);
PeerId { multihash, canonical } PeerId { multihash, canonical }
} }
@ -158,7 +157,7 @@ impl PeerId {
pub fn is_public_key(&self, public_key: &PublicKey) -> Option<bool> { pub fn is_public_key(&self, public_key: &PublicKey) -> Option<bool> {
let alg = self.multihash.algorithm(); let alg = self.multihash.algorithm();
let enc = public_key.clone().into_protobuf_encoding(); 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<u8>, algo1: HashAlgo, algo2: HashAlgo) -> bool { fn property(data: Vec<u8>, algo1: HashAlgo, algo2: HashAlgo) -> bool {
let a = PeerId::try_from(algo1.0.hasher().unwrap().digest(&data)).unwrap(); let a = PeerId::try_from(algo1.0.digest(&data)).unwrap();
let b = PeerId::try_from(algo2.0.hasher().unwrap().digest(&data)).unwrap(); let b = PeerId::try_from(algo2.0.digest(&data)).unwrap();
if algo1 == algo2 || algo1.0 == Code::Identity || algo2.0 == Code::Identity { if algo1 == algo2 || algo1.0 == Code::Identity || algo2.0 == Code::Identity {
a == b a == b

View File

@ -13,7 +13,7 @@ arrayref = "0.3"
bs58 = "0.3.0" bs58 = "0.3.0"
byteorder = "1.3.1" byteorder = "1.3.1"
data-encoding = "2.1" data-encoding = "2.1"
multihash = "0.10" multihash = "0.11.0"
percent-encoding = "2.1.0" percent-encoding = "2.1.0"
serde = "1.0.70" serde = "1.0.70"
static_assertions = "1.1" static_assertions = "1.1"

View File

@ -19,7 +19,7 @@ futures = "0.3.1"
log = "0.4" log = "0.4"
libp2p-core = { version = "0.18.0", path = "../../core" } libp2p-core = { version = "0.18.0", path = "../../core" }
libp2p-swarm = { version = "0.18.0", path = "../../swarm" } libp2p-swarm = { version = "0.18.0", path = "../../swarm" }
multihash = "0.10" multihash = "0.11.0"
prost = "0.6.1" prost = "0.6.1"
rand = "0.7.2" rand = "0.7.2"
sha2 = "0.8.0" sha2 = "0.8.0"

View File

@ -262,8 +262,6 @@ pub use self::simple::SimpleProtocol;
pub use self::swarm::Swarm; pub use self::swarm::Swarm;
pub use self::transport_ext::TransportExt; 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. /// 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 /// > **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(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"))))] #[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) pub fn build_development_transport(keypair: identity::Keypair)
-> io::Result<impl Transport<Output = (PeerId, impl core::muxing::StreamMuxer<OutboundSubstream = impl Send, Substream = impl Send, Error = impl Into<io::Error>> + Send + Sync), Error = impl error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone> -> std::io::Result<impl Transport<Output = (PeerId, impl core::muxing::StreamMuxer<OutboundSubstream = impl Send, Substream = impl Send, Error = impl Into<std::io::Error>> + 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) 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(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"))))] #[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) pub fn build_tcp_ws_secio_mplex_yamux(keypair: identity::Keypair)
-> io::Result<impl Transport<Output = (PeerId, impl core::muxing::StreamMuxer<OutboundSubstream = impl Send, Substream = impl Send, Error = impl Into<io::Error>> + Send + Sync), Error = impl error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone> -> std::io::Result<impl Transport<Output = (PeerId, impl core::muxing::StreamMuxer<OutboundSubstream = impl Send, Substream = impl Send, Error = impl Into<std::io::Error>> + Send + Sync), Error = impl std::error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone>
{ {
let transport = { let transport = {
let tcp = tcp::TcpConfig::new().nodelay(true); 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)) .authenticate(secio::SecioConfig::new(keypair))
.multiplex(core::upgrade::SelectUpgrade::new(yamux::Config::default(), mplex::MplexConfig::new())) .multiplex(core::upgrade::SelectUpgrade::new(yamux::Config::default(), mplex::MplexConfig::new()))
.map(|(peer, muxer), _| (peer, core::muxing::StreamMuxerBox::new(muxer))) .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`. /// 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(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"))))] #[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) pub fn build_tcp_ws_pnet_secio_mplex_yamux(keypair: identity::Keypair, psk: PreSharedKey)
-> io::Result<impl Transport<Output = (PeerId, impl core::muxing::StreamMuxer<OutboundSubstream = impl Send, Substream = impl Send, Error = impl Into<io::Error>> + Send + Sync), Error = impl error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone> -> std::io::Result<impl Transport<Output = (PeerId, impl core::muxing::StreamMuxer<OutboundSubstream = impl Send, Substream = impl Send, Error = impl Into<std::io::Error>> + Send + Sync), Error = impl std::error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone>
{ {
let transport = { let transport = {
let tcp = tcp::TcpConfig::new().nodelay(true); 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)) .authenticate(secio::SecioConfig::new(keypair))
.multiplex(core::upgrade::SelectUpgrade::new(yamux::Config::default(), mplex::MplexConfig::new())) .multiplex(core::upgrade::SelectUpgrade::new(yamux::Config::default(), mplex::MplexConfig::new()))
.map(|(peer, muxer), _| (peer, core::muxing::StreamMuxerBox::new(muxer))) .map(|(peer, muxer), _| (peer, core::muxing::StreamMuxerBox::new(muxer)))
.timeout(Duration::from_secs(20))) .timeout(std::time::Duration::from_secs(20)))
} }