diff --git a/CHANGELOG.md b/CHANGELOG.md index a9de3715cc7..faeb4f58898 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,10 @@ - [`parity-multiaddr` CHANGELOG](misc/multiaddr/CHANGELOG.md) - [`libp2p-core-derive` CHANGELOG](misc/core-derive/CHANGELOG.md) +# Version 0.33.0 [unreleased] + +- Update `libp2p-core` and all dependent crates. + # Version 0.32.2 [2020-12-10] - Update `libp2p-websocket`. diff --git a/Cargo.toml b/Cargo.toml index d9c0478e8e0..149d9d01980 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p" edition = "2018" description = "Peer-to-peer networking library" -version = "0.32.2" +version = "0.33.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -61,22 +61,22 @@ atomic = "0.5.0" bytes = "0.5" futures = "0.3.1" lazy_static = "1.2" -libp2p-core = { version = "0.25.2", path = "core" } +libp2p-core = { version = "0.26.0", path = "core" } libp2p-core-derive = { version = "0.21.0", path = "misc/core-derive" } -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-floodsub = { version = "0.26.0", path = "protocols/floodsub", optional = true } +libp2p-gossipsub = { version = "0.26.0", path = "./protocols/gossipsub", optional = true } +libp2p-identify = { version = "0.26.0", path = "protocols/identify", optional = true } +libp2p-kad = { version = "0.27.0", path = "protocols/kad", optional = true } +libp2p-mplex = { version = "0.26.0", path = "muxers/mplex", optional = true } +libp2p-noise = { version = "0.28.0", path = "protocols/noise", optional = true } +libp2p-ping = { version = "0.26.0", path = "protocols/ping", optional = true } +libp2p-plaintext = { version = "0.26.0", path = "protocols/plaintext", optional = true } libp2p-pnet = { version = "0.19.2", path = "protocols/pnet", optional = true } -libp2p-request-response = { version = "0.7.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 } +libp2p-request-response = { version = "0.8.0", path = "protocols/request-response", optional = true } +libp2p-swarm = { version = "0.26.0", path = "swarm" } +libp2p-uds = { version = "0.26.0", path = "transports/uds", optional = true } +libp2p-wasm-ext = { version = "0.26.0", path = "transports/wasm-ext", optional = true } +libp2p-yamux = { version = "0.29.0", path = "muxers/yamux", optional = true } multiaddr = { package = "parity-multiaddr", version = "0.10.0", path = "misc/multiaddr" } parking_lot = "0.11.0" pin-project = "1.0.0" @@ -84,11 +84,11 @@ 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.25.0", path = "protocols/deflate", optional = true } -libp2p-dns = { version = "0.25.0", path = "transports/dns", optional = true } -libp2p-mdns = { version = "0.26.0", path = "protocols/mdns", optional = true } -libp2p-tcp = { version = "0.25.1", path = "transports/tcp", optional = true } -libp2p-websocket = { version = "0.26.3", path = "transports/websocket", optional = true } +libp2p-deflate = { version = "0.26.0", path = "protocols/deflate", optional = true } +libp2p-dns = { version = "0.26.0", path = "transports/dns", optional = true } +libp2p-mdns = { version = "0.27.0", path = "protocols/mdns", optional = true } +libp2p-tcp = { version = "0.26.0", path = "transports/tcp", optional = true } +libp2p-websocket = { version = "0.27.0", path = "transports/websocket", optional = true } [dev-dependencies] async-std = "1.6.2" diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 09e654d2a6a..327a65268d9 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -1,3 +1,8 @@ +# 0.26.0 [unreleased] + +- Make `PeerId` be `Copy`, including small `PeerId` API changes. + [PR 1874](https://github.com/libp2p/rust-libp2p/pull/1874/). + # 0.25.2 [2020-12-02] - Require `multistream-select-0.9.1`. diff --git a/core/Cargo.toml b/core/Cargo.toml index 2ccb78cfadd..db365e02321 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-core" edition = "2018" description = "Core traits and structs of libp2p" -version = "0.25.2" +version = "0.26.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -12,7 +12,6 @@ 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" diff --git a/core/benches/peer_id.rs b/core/benches/peer_id.rs index d10b42c9e2e..32b2c1f5e3f 100644 --- a/core/benches/peer_id.rs +++ b/core/benches/peer_id.rs @@ -18,18 +18,18 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput}; +use criterion::{black_box, criterion_group, criterion_main, Criterion}; use libp2p_core::{identity, PeerId}; fn from_bytes(c: &mut Criterion) { let peer_id_bytes = identity::Keypair::generate_ed25519() .public() .into_peer_id() - .into_bytes(); + .to_bytes(); c.bench_function("from_bytes", |b| { b.iter(|| { - black_box(PeerId::from_bytes(peer_id_bytes.clone()).unwrap()); + black_box(PeerId::from_bytes(&peer_id_bytes).unwrap()); }) }); } diff --git a/core/src/network/peer.rs b/core/src/network/peer.rs index a1039334d44..4e179e546c3 100644 --- a/core/src/network/peer.rs +++ b/core/src/network/peer.rs @@ -555,7 +555,7 @@ where } self.network.pool.add(connection, connected) - .map(|_id| ConnectedPeer { + .map(move |_id| ConnectedPeer { network: self.network, peer_id: self.peer_id, }) diff --git a/core/src/peer_id.rs b/core/src/peer_id.rs index b81eeefcfd3..5f9a8f78629 100644 --- a/core/src/peer_id.rs +++ b/core/src/peer_id.rs @@ -19,11 +19,10 @@ // DEALINGS IN THE SOFTWARE. use crate::PublicKey; -use bytes::Bytes; -use thiserror::Error; -use multihash::{Code, Multihash, MultihashDigest}; +use multihash::{Code, Error, Multihash, MultihashDigest}; use rand::Rng; -use std::{convert::TryFrom, borrow::Borrow, fmt, hash, str::FromStr, cmp}; +use std::{convert::TryFrom, fmt, str::FromStr}; +use thiserror::Error; /// Public keys with byte-lengths smaller than `MAX_INLINE_KEY_LENGTH` will be /// automatically used as the peer id using an identity multihash. @@ -32,10 +31,9 @@ const MAX_INLINE_KEY_LENGTH: usize = 42; /// Identifier of a peer of the network. /// /// The data is a multihash of the public key of the peer. -// TODO: maybe keep things in decoded version? -#[derive(Clone, Eq)] +#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct PeerId { - multihash: Bytes, + multihash: Multihash, } impl fmt::Debug for PeerId { @@ -52,21 +50,6 @@ impl fmt::Display for PeerId { } } -impl cmp::PartialOrd for PeerId { - fn partial_cmp(&self, other: &Self) -> Option { - Some(Ord::cmp(self, other)) - } -} - -impl cmp::Ord for PeerId { - fn cmp(&self, other: &Self) -> cmp::Ordering { - // must use borrow, because as_bytes is not consistent with equality - let lhs: &[u8] = self.borrow(); - let rhs: &[u8] = other.borrow(); - lhs.cmp(rhs) - } -} - impl PeerId { /// Builds a `PeerId` from a public key. pub fn from_public_key(key: PublicKey) -> PeerId { @@ -78,18 +61,15 @@ impl PeerId { Code::Sha2_256 }; - let multihash = hash_algorithm.digest(&key_enc).to_bytes().into(); + let multihash = hash_algorithm.digest(&key_enc); PeerId { multihash } } - /// 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) -> Result> { - match Multihash::from_bytes(&data) { - Ok(multihash) => PeerId::from_multihash(multihash).map_err(|_| data), - Err(_err) => Err(data), - } + /// Parses a `PeerId` from bytes. + pub fn from_bytes(data: &[u8]) -> Result { + Ok(PeerId::from_multihash(Multihash::from_bytes(&data)?) + .map_err(|mh| Error::UnsupportedCode(mh.code()))?) } /// Tries to turn a `Multihash` into a `PeerId`. @@ -99,9 +79,9 @@ impl PeerId { /// peer ID, it is returned as an `Err`. pub fn from_multihash(multihash: Multihash) -> Result { match Code::try_from(multihash.code()) { - Ok(Code::Sha2_256) => Ok(PeerId { multihash: multihash.to_bytes().into() }), + Ok(Code::Sha2_256) => Ok(PeerId { multihash }), Ok(Code::Identity) if multihash.digest().len() <= MAX_INLINE_KEY_LENGTH - => Ok(PeerId { multihash: multihash.to_bytes().into() }), + => Ok(PeerId { multihash }), _ => Err(multihash) } } @@ -113,31 +93,18 @@ impl PeerId { let peer_id = rand::thread_rng().gen::<[u8; 32]>(); PeerId { multihash: Multihash::wrap(Code::Identity.into(), &peer_id) - .expect("The digest size is never too large").to_bytes().into() + .expect("The digest size is never too large") } } /// Returns a raw bytes representation of this `PeerId`. - /// - /// **NOTE:** This byte representation is not necessarily consistent with - /// 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 { - self.multihash.to_vec() - } - - /// Returns a raw bytes representation of this `PeerId`. - /// - /// **NOTE:** This byte representation is not necessarily consistent with - /// 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 + pub fn to_bytes(&self) -> Vec { + self.multihash.to_bytes() } /// Returns a base-58 encoded string of this `PeerId`. pub fn to_base58(&self) -> String { - bs58::encode(self.borrow() as &[u8]).into_string() + bs58::encode(self.to_bytes()).into_string() } /// Checks whether the public key passed as parameter matches the public key of this `PeerId`. @@ -145,22 +112,10 @@ 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 { - let multihash = Multihash::from_bytes(&self.multihash) - .expect("Internal multihash is always a valid"); - let alg = Code::try_from(multihash.code()) + let alg = Code::try_from(self.multihash.code()) .expect("Internal multihash is always a valid `Code`"); let enc = public_key.clone().into_protobuf_encoding(); - Some(alg.digest(&enc) == multihash) - } -} - -impl hash::Hash for PeerId { - fn hash(&self, state: &mut H) - where - H: hash::Hasher - { - let digest = self.borrow() as &[u8]; - hash::Hash::hash(digest, state) + Some(alg.digest(&enc) == self.multihash) } } @@ -174,7 +129,7 @@ impl TryFrom> for PeerId { type Error = Vec; fn try_from(value: Vec) -> Result { - PeerId::from_bytes(value) + PeerId::from_bytes(&value).map_err(|_| value) } } @@ -186,33 +141,21 @@ impl TryFrom for PeerId { } } -impl PartialEq for PeerId { - fn eq(&self, other: &PeerId) -> bool { - let self_digest = self.borrow() as &[u8]; - let other_digest = other.borrow() as &[u8]; - self_digest == other_digest - } -} - -impl Borrow<[u8]> for PeerId { - fn borrow(&self) -> &[u8] { +impl AsRef for PeerId { + fn as_ref(&self) -> &Multihash { &self.multihash } } -/// **NOTE:** This byte representation is not necessarily consistent with -/// equality of peer IDs. That is, two peer IDs may be considered equal -/// while having a different byte representation as per `AsRef<[u8]>`. -impl AsRef<[u8]> for PeerId { - fn as_ref(&self) -> &[u8] { - self.as_bytes() +impl From for Multihash { + fn from(peer_id: PeerId) -> Self { + peer_id.multihash } } -impl From for Multihash { +impl From for Vec { fn from(peer_id: PeerId) -> Self { - Multihash::from_bytes(&peer_id.multihash) - .expect("PeerIds always contain valid Multihashes") + peer_id.to_bytes() } } @@ -230,7 +173,7 @@ impl FromStr for PeerId { #[inline] fn from_str(s: &str) -> Result { let bytes = bs58::decode(s).into_vec()?; - PeerId::from_bytes(bytes).map_err(|_| ParseError::MultiHash) + PeerId::from_bytes(&bytes).map_err(|_| ParseError::MultiHash) } } @@ -248,7 +191,7 @@ mod tests { #[test] fn peer_id_into_bytes_then_from_bytes() { let peer_id = identity::Keypair::generate_ed25519().public().into_peer_id(); - let second = PeerId::from_bytes(peer_id.clone().into_bytes()).unwrap(); + let second = PeerId::from_bytes(&peer_id.to_bytes()).unwrap(); assert_eq!(peer_id, second); } @@ -263,7 +206,7 @@ mod tests { fn random_peer_id_is_valid() { for _ in 0 .. 5000 { let peer_id = PeerId::random(); - assert_eq!(peer_id, PeerId::from_bytes(peer_id.clone().into_bytes()).unwrap()); + assert_eq!(peer_id, PeerId::from_bytes(&peer_id.to_bytes()).unwrap()); } } } diff --git a/muxers/mplex/CHANGELOG.md b/muxers/mplex/CHANGELOG.md index 2a1126104d7..4daf1b43b46 100644 --- a/muxers/mplex/CHANGELOG.md +++ b/muxers/mplex/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.26.0 [unreleased] + +- Update `libp2p-core`. + # 0.25.0 [2020-11-25] - Update `libp2p-core`. diff --git a/muxers/mplex/Cargo.toml b/muxers/mplex/Cargo.toml index 40b3d2ae963..19105aec5b0 100644 --- a/muxers/mplex/Cargo.toml +++ b/muxers/mplex/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-mplex" edition = "2018" description = "Mplex multiplexing protocol for libp2p" -version = "0.25.0" +version = "0.26.0" authors = ["Parity Technologies "] 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.25.0", path = "../../core" } +libp2p-core = { version = "0.26.0", path = "../../core" } log = "0.4" nohash-hasher = "0.2" parking_lot = "0.11" diff --git a/muxers/yamux/CHANGELOG.md b/muxers/yamux/CHANGELOG.md index a499d470f2d..2f38f555200 100644 --- a/muxers/yamux/CHANGELOG.md +++ b/muxers/yamux/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.29.0 [unreleased] + +- Update `libp2p-core`. + # 0.28.0 [2020-11-25] - Update `libp2p-core`. diff --git a/muxers/yamux/Cargo.toml b/muxers/yamux/Cargo.toml index 7376495ab10..d4423e9168f 100644 --- a/muxers/yamux/Cargo.toml +++ b/muxers/yamux/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-yamux" edition = "2018" description = "Yamux multiplexing protocol for libp2p" -version = "0.28.0" +version = "0.29.0" authors = ["Parity Technologies "] 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.25.0", path = "../../core" } +libp2p-core = { version = "0.26.0", path = "../../core" } parking_lot = "0.11" thiserror = "1.0" yamux = "0.8.0" diff --git a/protocols/deflate/CHANGELOG.md b/protocols/deflate/CHANGELOG.md index b0f3e1760e5..a30234b9d61 100644 --- a/protocols/deflate/CHANGELOG.md +++ b/protocols/deflate/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.26.0 [unreleased] + +- Update `libp2p-core`. + # 0.25.0 [2020-11-25] - Update `libp2p-core`. diff --git a/protocols/deflate/Cargo.toml b/protocols/deflate/Cargo.toml index b960433c411..3ba000c56ab 100644 --- a/protocols/deflate/Cargo.toml +++ b/protocols/deflate/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-deflate" edition = "2018" description = "Deflate encryption protocol for libp2p" -version = "0.25.0" +version = "0.26.0" authors = ["Parity Technologies "] 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.25.0", path = "../../core" } +libp2p-core = { version = "0.26.0", path = "../../core" } flate2 = "1.0" [dev-dependencies] diff --git a/protocols/floodsub/CHANGELOG.md b/protocols/floodsub/CHANGELOG.md index 927dfe608f4..be3a6c65323 100644 --- a/protocols/floodsub/CHANGELOG.md +++ b/protocols/floodsub/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.26.0 [unreleased] + +- Update `libp2p-swarm` and `libp2p-core`. + # 0.25.0 [2020-11-25] - Update `libp2p-swarm` and `libp2p-core`. diff --git a/protocols/floodsub/Cargo.toml b/protocols/floodsub/Cargo.toml index 3b87710e619..65df9746025 100644 --- a/protocols/floodsub/Cargo.toml +++ b/protocols/floodsub/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-floodsub" edition = "2018" description = "Floodsub protocol for libp2p" -version = "0.25.0" +version = "0.26.0" authors = ["Parity Technologies "] 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.25.0", path = "../../core" } -libp2p-swarm = { version = "0.25.0", path = "../../swarm" } +libp2p-core = { version = "0.26.0", path = "../../core" } +libp2p-swarm = { version = "0.26.0", path = "../../swarm" } log = "0.4" prost = "0.6.1" rand = "0.7" diff --git a/protocols/floodsub/src/protocol.rs b/protocols/floodsub/src/protocol.rs index 046c72d856b..bd0b5b2a646 100644 --- a/protocols/floodsub/src/protocol.rs +++ b/protocols/floodsub/src/protocol.rs @@ -61,7 +61,7 @@ where let mut messages = Vec::with_capacity(rpc.publish.len()); for publish in rpc.publish.into_iter() { messages.push(FloodsubMessage { - source: PeerId::from_bytes(publish.from.unwrap_or_default()).map_err(|_| { + source: PeerId::from_bytes(&publish.from.unwrap_or_default()).map_err(|_| { FloodsubDecodeError::InvalidPeerId })?, data: publish.data.unwrap_or_default(), @@ -179,7 +179,7 @@ impl FloodsubRpc { publish: self.messages.into_iter() .map(|msg| { rpc_proto::Message { - from: Some(msg.source.into_bytes()), + from: Some(msg.source.to_bytes()), data: Some(msg.data), seqno: Some(msg.sequence_number), topic_ids: msg.topics diff --git a/protocols/gossipsub/CHANGELOG.md b/protocols/gossipsub/CHANGELOG.md index fc01624c327..1040fa2714a 100644 --- a/protocols/gossipsub/CHANGELOG.md +++ b/protocols/gossipsub/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.26.0 [unreleased] + +- Update `libp2p-swarm` and `libp2p-core`. + # 0.25.0 [2020-11-25] - Update `libp2p-swarm` and `libp2p-core`. diff --git a/protocols/gossipsub/Cargo.toml b/protocols/gossipsub/Cargo.toml index 6f4c25b46e6..b3b16fb60f7 100644 --- a/protocols/gossipsub/Cargo.toml +++ b/protocols/gossipsub/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-gossipsub" edition = "2018" description = "Gossipsub protocol for libp2p" -version = "0.25.0" +version = "0.26.0" authors = ["Age Manning "] 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.25.0", path = "../../swarm" } -libp2p-core = { version = "0.25.0", path = "../../core" } +libp2p-swarm = { version = "0.26.0", path = "../../swarm" } +libp2p-core = { version = "0.26.0", path = "../../core" } bytes = "0.5.4" byteorder = "1.3.2" fnv = "1.0.6" diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index fb17190507b..eb8426a604d 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -1100,7 +1100,7 @@ impl Gossipsub { let signature = { let message = rpc_proto::Message { - from: Some(author.clone().into_bytes()), + from: Some(author.clone().to_bytes()), data: Some(data.clone()), seqno: Some(sequence_number.to_be_bytes().to_vec()), topic_ids: topics.clone().into_iter().map(|t| t.into()).collect(), diff --git a/protocols/gossipsub/src/config.rs b/protocols/gossipsub/src/config.rs index 330788ac5f7..2ef65b376ae 100644 --- a/protocols/gossipsub/src/config.rs +++ b/protocols/gossipsub/src/config.rs @@ -139,7 +139,7 @@ impl Default for GossipsubConfig { let mut source_string = if let Some(peer_id) = message.source.as_ref() { peer_id.to_base58() } else { - PeerId::from_bytes(vec![0, 1, 0]) + PeerId::from_bytes(&[0, 1, 0]) .expect("Valid peer id") .to_base58() }; diff --git a/protocols/gossipsub/src/protocol.rs b/protocols/gossipsub/src/protocol.rs index b1785513c5d..7184c882ba6 100644 --- a/protocols/gossipsub/src/protocol.rs +++ b/protocols/gossipsub/src/protocol.rs @@ -137,7 +137,7 @@ impl GossipsubCodec { } }; - let source = match PeerId::from_bytes(from.clone()) { + let source = match PeerId::from_bytes(&from) { Ok(v) => v, Err(_) => { debug!("Signature verification failed: Invalid Peer Id"); @@ -161,7 +161,7 @@ impl GossipsubCodec { .map(|key| PublicKey::from_protobuf_encoding(&key)) { Some(Ok(key)) => key, - _ => match PublicKey::from_protobuf_encoding(&source.as_bytes()[2..]) { + _ => match PublicKey::from_protobuf_encoding(&source.to_bytes()[2..]) { Ok(v) => v, Err(_) => { warn!("Signature verification failed: No valid public key supplied"); @@ -200,7 +200,7 @@ impl Encoder for GossipsubCodec { for message in item.messages.into_iter() { let message = rpc_proto::Message { - from: message.source.map(|m| m.into_bytes()), + from: message.source.map(|m| m.to_bytes()), data: Some(message.data), seqno: message.sequence_number.map(|s| s.to_be_bytes().to_vec()), topic_ids: message.topics.into_iter().map(TopicHash::into).collect(), @@ -372,7 +372,7 @@ impl Decoder for GossipsubCodec { let source = if verify_source { Some( - PeerId::from_bytes(message.from.unwrap_or_default()).map_err(|_| { + PeerId::from_bytes(&message.from.unwrap_or_default()).map_err(|_| { io::Error::new(io::ErrorKind::InvalidData, "Invalid Peer Id") })?, ) diff --git a/protocols/identify/CHANGELOG.md b/protocols/identify/CHANGELOG.md index db7796a29bc..3556a3b2463 100644 --- a/protocols/identify/CHANGELOG.md +++ b/protocols/identify/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.26.0 [unreleased] + +- Update `libp2p-swarm` and `libp2p-core`. + # 0.25.0 [2020-11-25] - Update `libp2p-swarm` and `libp2p-core`. diff --git a/protocols/identify/Cargo.toml b/protocols/identify/Cargo.toml index 3606a3cb87b..9b81b82cd9d 100644 --- a/protocols/identify/Cargo.toml +++ b/protocols/identify/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-identify" edition = "2018" description = "Nodes identifcation protocol for libp2p" -version = "0.25.0" +version = "0.26.0" authors = ["Parity Technologies "] 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.25.0", path = "../../core" } -libp2p-swarm = { version = "0.25.0", path = "../../swarm" } +libp2p-core = { version = "0.26.0", path = "../../core" } +libp2p-swarm = { version = "0.26.0", path = "../../swarm" } log = "0.4.1" prost = "0.6.1" smallvec = "1.0" diff --git a/protocols/kad/CHANGELOG.md b/protocols/kad/CHANGELOG.md index 4c42e37d1f7..74ad00f4749 100644 --- a/protocols/kad/CHANGELOG.md +++ b/protocols/kad/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.27.0 [unreleased] + +- Update `libp2p-core` and `libp2p-swarm`. + # 0.26.0 [2020-11-25] - Update `libp2p-core` and `libp2p-swarm`. diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index 2c23310e616..975f2913bb4 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-kad" edition = "2018" description = "Kademlia protocol for libp2p" -version = "0.26.0" +version = "0.27.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -17,8 +17,8 @@ fnv = "1.0" futures_codec = "0.4" futures = "0.3.1" log = "0.4" -libp2p-core = { version = "0.25.0", path = "../../core" } -libp2p-swarm = { version = "0.25.0", path = "../../swarm" } +libp2p-core = { version = "0.26.0", path = "../../core" } +libp2p-swarm = { version = "0.26.0", path = "../../swarm" } prost = "0.6.1" rand = "0.7.2" sha2 = "0.9.1" diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs index 2034e66e647..5cfd12ca30e 100644 --- a/protocols/kad/src/behaviour.rs +++ b/protocols/kad/src/behaviour.rs @@ -47,7 +47,7 @@ use libp2p_swarm::{ }; use log::{info, debug, warn}; use smallvec::SmallVec; -use std::{borrow::{Borrow, Cow}, error, iter, time::Duration}; +use std::{borrow::Cow, error, iter, time::Duration}; use std::collections::{HashSet, VecDeque}; use std::fmt; use std::num::NonZeroUsize; @@ -337,7 +337,7 @@ where /// Creates a new `Kademlia` network behaviour with the given configuration. pub fn with_config(id: PeerId, store: TStore, config: KademliaConfig) -> Self { - let local_key = kbucket::Key::new(id.clone()); + let local_key = kbucket::Key::from(id); let put_record_job = config .record_replication_interval @@ -428,7 +428,7 @@ where /// If the routing table has been updated as a result of this operation, /// a [`KademliaEvent::RoutingUpdated`] event is emitted. pub fn add_address(&mut self, peer: &PeerId, address: Multiaddr) -> RoutingUpdate { - let key = kbucket::Key::new(peer.clone()); + let key = kbucket::Key::from(*peer); match self.kbuckets.entry(&key) { kbucket::Entry::Present(mut entry, _) => { if entry.value().insert(address) { @@ -495,7 +495,7 @@ where pub fn remove_address(&mut self, peer: &PeerId, address: &Multiaddr) -> Option, Addresses>> { - let key = kbucket::Key::new(peer.clone()); + let key = kbucket::Key::from(*peer); match self.kbuckets.entry(&key) { kbucket::Entry::Present(mut entry, _) => { if entry.value().remove(address).is_err() { @@ -524,7 +524,7 @@ where pub fn remove_peer(&mut self, peer: &PeerId) -> Option, Addresses>> { - let key = kbucket::Key::new(peer.clone()); + let key = kbucket::Key::from(*peer); match self.kbuckets.entry(&key) { kbucket::Entry::Present(entry, _) => { Some(entry.remove()) @@ -551,9 +551,9 @@ where pub fn kbucket(&mut self, key: K) -> Option, Addresses>> where - K: Borrow<[u8]> + Clone + K: Into> + Clone { - self.kbuckets.bucket(&kbucket::Key::new(key)) + self.kbuckets.bucket(&key.into()) } /// Initiates an iterative query for the closest peers to the given key. @@ -562,10 +562,10 @@ where /// [`KademliaEvent::QueryResult{QueryResult::GetClosestPeers}`]. pub fn get_closest_peers(&mut self, key: K) -> QueryId where - K: Borrow<[u8]> + Clone + K: Into> + Into> + Clone { - let info = QueryInfo::GetClosestPeers { key: key.borrow().to_vec() }; - let target = kbucket::Key::new(key); + let info = QueryInfo::GetClosestPeers { key: key.clone().into() }; + let target: kbucket::Key = key.into(); let peers = self.kbuckets.closest_keys(&target); let inner = QueryInner::new(info); self.queries.add_iter_closest(target.clone(), peers, inner) @@ -823,7 +823,7 @@ where if &node_id == kbuckets.local_key().preimage() { Some(local_addrs.iter().cloned().collect::>()) } else { - let key = kbucket::Key::new(node_id.clone()); + let key = kbucket::Key::from(node_id); kbuckets.entry(&key).view().map(|e| e.node.value.clone().into_vec()) } } else { @@ -870,7 +870,7 @@ where /// Updates the routing table with a new connection status and address of a peer. fn connection_updated(&mut self, peer: PeerId, address: Option, new_status: NodeStatus) { - let key = kbucket::Key::new(peer.clone()); + let key = kbucket::Key::from(peer); match self.kbuckets.entry(&key) { kbucket::Entry::Present(mut entry, old_status) => { if let Some(address) = address { @@ -985,13 +985,13 @@ where // Pr(bucket-253) = 1 - (7/8)^16 ~= 0.88 // Pr(bucket-252) = 1 - (15/16)^16 ~= 0.64 // ... - let mut target = kbucket::Key::new(PeerId::random()); + let mut target = kbucket::Key::from(PeerId::random()); for _ in 0 .. 16 { let d = local_key.distance(&target); if b.contains(&d) { break; } - target = kbucket::Key::new(PeerId::random()); + target = kbucket::Key::from(PeerId::random()); } target }).collect::>().into_iter() @@ -1447,7 +1447,7 @@ where fn addresses_of_peer(&mut self, peer_id: &PeerId) -> Vec { // We should order addresses from decreasing likelyhood of connectivity, so start with // the addresses of that peer in the k-buckets. - let key = kbucket::Key::new(peer_id.clone()); + let key = kbucket::Key::from(*peer_id); let mut peer_addrs = if let kbucket::Entry::Present(mut entry, _) = self.kbuckets.entry(&key) { let addrs = entry.value().iter().cloned().collect::>(); @@ -1500,7 +1500,7 @@ where let (old, new) = (old.get_remote_address(), new.get_remote_address()); // Update routing table. - if let Some(addrs) = self.kbuckets.entry(&kbucket::Key::new(peer.clone())).value() { + if let Some(addrs) = self.kbuckets.entry(&kbucket::Key::from(*peer)).value() { if addrs.replace(old, new) { debug!("Address '{}' replaced with '{}' for peer '{}'.", old, new, peer); } else { @@ -1550,7 +1550,7 @@ where err: &dyn error::Error ) { if let Some(peer_id) = peer_id { - let key = kbucket::Key::new(peer_id.clone()); + let key = kbucket::Key::from(*peer_id); if let Some(addrs) = self.kbuckets.entry(&key).value() { // TODO: Ideally, the address should only be removed if the error can @@ -2403,7 +2403,7 @@ impl QueryInfo { fn to_request(&self, query_id: QueryId) -> KademliaHandlerIn { match &self { QueryInfo::Bootstrap { peer, .. } => KademliaHandlerIn::FindNodeReq { - key: peer.clone().into_bytes(), + key: peer.to_bytes(), user_data: query_id, }, QueryInfo::GetClosestPeers { key, .. } => KademliaHandlerIn::FindNodeReq { diff --git a/protocols/kad/src/behaviour/test.rs b/protocols/kad/src/behaviour/test.rs index 81533a5b5b7..e1b35105d70 100644 --- a/protocols/kad/src/behaviour/test.rs +++ b/protocols/kad/src/behaviour/test.rs @@ -239,13 +239,13 @@ fn query_iter() { // Ask the first peer in the list to search a random peer. The search should // propagate forwards through the list of peers. let search_target = PeerId::random(); - let search_target_key = kbucket::Key::new(search_target.clone()); - let qid = swarms[0].get_closest_peers(search_target.clone()); + let search_target_key = kbucket::Key::from(search_target); + let qid = swarms[0].get_closest_peers(search_target); match swarms[0].query(&qid) { Some(q) => match q.info() { QueryInfo::GetClosestPeers { key } => { - assert_eq!(&key[..], search_target.borrow() as &[u8]) + assert_eq!(&key[..], search_target.to_bytes().as_slice()) }, i => panic!("Unexpected query info: {:?}", i) } @@ -268,7 +268,7 @@ fn query_iter() { id, result: QueryResult::GetClosestPeers(Ok(ok)), .. })) => { assert_eq!(id, qid); - assert_eq!(&ok.key[..], search_target.as_bytes()); + assert_eq!(&ok.key[..], search_target.to_bytes().as_slice()); assert_eq!(swarm_ids[i], expected_swarm_id); assert_eq!(swarm.queries.size(), 0); assert!(expected_peer_ids.iter().all(|p| ok.peers.contains(p))); @@ -310,7 +310,7 @@ fn unresponsive_not_returned_direct() { // Ask first to search a random value. let search_target = PeerId::random(); - swarms[0].get_closest_peers(search_target.clone()); + swarms[0].get_closest_peers(search_target); block_on( poll_fn(move |ctx| { @@ -320,7 +320,7 @@ fn unresponsive_not_returned_direct() { Poll::Ready(Some(KademliaEvent::QueryResult { result: QueryResult::GetClosestPeers(Ok(ok)), .. })) => { - assert_eq!(&ok.key[..], search_target.as_bytes()); + assert_eq!(&ok.key[..], search_target.to_bytes().as_slice()); assert_eq!(ok.peers.len(), 0); return Poll::Ready(()); } @@ -360,7 +360,7 @@ fn unresponsive_not_returned_indirect() { // Ask second to search a random value. let search_target = PeerId::random(); - swarms[1].get_closest_peers(search_target.clone()); + swarms[1].get_closest_peers(search_target); block_on( poll_fn(move |ctx| { @@ -370,7 +370,7 @@ fn unresponsive_not_returned_indirect() { Poll::Ready(Some(KademliaEvent::QueryResult { result: QueryResult::GetClosestPeers(Ok(ok)), .. })) => { - assert_eq!(&ok.key[..], search_target.as_bytes()); + assert_eq!(&ok.key[..], search_target.to_bytes().as_slice()); assert_eq!(ok.peers.len(), 1); assert_eq!(ok.peers[0], first_peer_id); return Poll::Ready(()); @@ -570,8 +570,8 @@ fn put_record() { .cloned() .collect::>(); expected.sort_by(|id1, id2| - kbucket::Key::new(id1.clone()).distance(&key).cmp( - &kbucket::Key::new(id2.clone()).distance(&key))); + kbucket::Key::from(*id1).distance(&key).cmp( + &kbucket::Key::from(*id2).distance(&key))); let expected = expected .into_iter() @@ -838,8 +838,8 @@ fn add_provider() { .collect::>(); let kbucket_key = kbucket::Key::new(key); expected.sort_by(|id1, id2| - kbucket::Key::new(id1.clone()).distance(&kbucket_key).cmp( - &kbucket::Key::new(id2.clone()).distance(&kbucket_key))); + kbucket::Key::from(*id1).distance(&kbucket_key).cmp( + &kbucket::Key::from(*id2).distance(&kbucket_key))); let expected = expected .into_iter() @@ -1084,7 +1084,7 @@ fn manual_bucket_inserts() { routable.push(peer); if expected.is_empty() { for peer in routable.iter() { - let bucket = swarm.kbucket(peer.clone()).unwrap(); + let bucket = swarm.kbucket(*peer).unwrap(); assert!(bucket.iter().all(|e| e.node.key.preimage() != peer)); } return Poll::Ready(()) diff --git a/protocols/kad/src/kbucket/bucket.rs b/protocols/kad/src/kbucket/bucket.rs index dc83a04d693..5a7ee8817bb 100644 --- a/protocols/kad/src/kbucket/bucket.rs +++ b/protocols/kad/src/kbucket/bucket.rs @@ -432,7 +432,7 @@ mod tests { let mut bucket = KBucket::, ()>::new(timeout); let num_nodes = g.gen_range(1, K_VALUE.get() + 1); for _ in 0 .. num_nodes { - let key = Key::new(PeerId::random()); + let key = Key::from(PeerId::random()); let node = Node { key: key.clone(), value: () }; let status = NodeStatus::arbitrary(g); match bucket.insert(node, status) { @@ -464,7 +464,7 @@ mod tests { fn fill_bucket(bucket: &mut KBucket, ()>, status: NodeStatus) { let num_entries_start = bucket.num_entries(); for i in 0 .. K_VALUE.get() - num_entries_start { - let key = Key::new(PeerId::random()); + let key = Key::from(PeerId::random()); let node = Node { key, value: () }; assert_eq!(InsertResult::Inserted, bucket.insert(node, status)); assert_eq!(bucket.num_entries(), num_entries_start + i + 1); @@ -482,7 +482,7 @@ mod tests { // Fill the bucket, thereby populating the expected lists in insertion order. for status in status { - let key = Key::new(PeerId::random()); + let key = Key::from(PeerId::random()); let node = Node { key: key.clone(), value: () }; let full = bucket.num_entries() == K_VALUE.get(); match bucket.insert(node, status) { @@ -529,7 +529,7 @@ mod tests { fill_bucket(&mut bucket, NodeStatus::Disconnected); // Trying to insert another disconnected node fails. - let key = Key::new(PeerId::random()); + let key = Key::from(PeerId::random()); let node = Node { key, value: () }; match bucket.insert(node, NodeStatus::Disconnected) { InsertResult::Full => {}, @@ -544,7 +544,7 @@ mod tests { // Add a connected node, which is expected to be pending, scheduled to // replace the first (i.e. least-recently connected) node. - let key = Key::new(PeerId::random()); + let key = Key::from(PeerId::random()); let node = Node { key: key.clone(), value: () }; match bucket.insert(node.clone(), NodeStatus::Connected) { InsertResult::Pending { disconnected } => @@ -577,7 +577,7 @@ mod tests { assert_eq!(K_VALUE.get(), bucket.num_entries()); // Trying to insert another connected node fails. - let key = Key::new(PeerId::random()); + let key = Key::from(PeerId::random()); let node = Node { key, value: () }; match bucket.insert(node, NodeStatus::Connected) { InsertResult::Full => {}, @@ -593,7 +593,7 @@ mod tests { let first_disconnected = first.clone(); // Add a connected pending node. - let key = Key::new(PeerId::random()); + let key = Key::from(PeerId::random()); let node = Node { key: key.clone(), value: () }; if let InsertResult::Pending { disconnected } = bucket.insert(node, NodeStatus::Connected) { assert_eq!(&disconnected, &first_disconnected.key); diff --git a/protocols/kad/src/kbucket/key.rs b/protocols/kad/src/kbucket/key.rs index 56f4140bd23..e8d1af3e8b1 100644 --- a/protocols/kad/src/kbucket/key.rs +++ b/protocols/kad/src/kbucket/key.rs @@ -103,7 +103,11 @@ impl From for Key { impl From for Key { fn from(p: PeerId) -> Self { - Key::new(p) + let bytes = KeyBytes(Sha256::digest(&p.to_bytes())); + Key { + preimage: p, + bytes + } } } diff --git a/protocols/kad/src/protocol.rs b/protocols/kad/src/protocol.rs index 58ca1c3d840..7bac1dd7c2a 100644 --- a/protocols/kad/src/protocol.rs +++ b/protocols/kad/src/protocol.rs @@ -101,7 +101,7 @@ impl TryFrom for KadPeer { fn try_from(peer: proto::message::Peer) -> Result { // TODO: this is in fact a CID; not sure if this should be handled in `from_bytes` or // as a special case here - let node_id = PeerId::from_bytes(peer.id) + let node_id = PeerId::from_bytes(&peer.id) .map_err(|_| invalid_data("invalid peer id"))?; let mut addrs = Vec::with_capacity(peer.addrs.len()); @@ -126,7 +126,7 @@ impl TryFrom for KadPeer { impl Into for KadPeer { fn into(self) -> proto::message::Peer { proto::message::Peer { - id: self.node_id.into_bytes(), + id: self.node_id.to_bytes(), addrs: self.multiaddrs.into_iter().map(|a| a.to_vec()).collect(), connection: { let ct: proto::message::ConnectionType = self.connection_ty.into(); @@ -533,7 +533,7 @@ fn record_from_proto(record: proto::Record) -> Result { let publisher = if !record.publisher.is_empty() { - PeerId::from_bytes(record.publisher) + PeerId::from_bytes(&record.publisher) .map(Some) .map_err(|_| invalid_data("Invalid publisher peer ID."))? } else { @@ -554,7 +554,7 @@ fn record_to_proto(record: Record) -> proto::Record { proto::Record { key: record.key.to_vec(), value: record.value, - publisher: record.publisher.map(PeerId::into_bytes).unwrap_or_default(), + publisher: record.publisher.map(|id| id.to_bytes()).unwrap_or_default(), ttl: record.expires .map(|t| { let now = Instant::now(); diff --git a/protocols/kad/src/query/peers/closest/disjoint.rs b/protocols/kad/src/query/peers/closest/disjoint.rs index 7002444073c..b295355634b 100644 --- a/protocols/kad/src/query/peers/closest/disjoint.rs +++ b/protocols/kad/src/query/peers/closest/disjoint.rs @@ -770,7 +770,7 @@ mod tests { impl Graph { fn get_closest_peer(&self, target: &KeyBytes) -> PeerId { self.0.iter() - .map(|(peer_id, _)| (target.distance(&Key::new(peer_id.clone())), peer_id)) + .map(|(peer_id, _)| (target.distance(&Key::from(*peer_id)), peer_id)) .fold(None, |acc, (distance_b, peer_id_b)| { match acc { None => Some((distance_b, peer_id_b)), @@ -848,7 +848,7 @@ mod tests { let mut known_closest_peers = graph.0.iter() .take(K_VALUE.get()) - .map(|(key, _peers)| Key::new(key.clone())) + .map(|(key, _peers)| Key::from(*key)) .collect::>(); known_closest_peers.sort_unstable_by(|a, b| { target.distance(a).cmp(&target.distance(b)) @@ -934,7 +934,7 @@ mod tests { } } - let mut result = iter.into_result().into_iter().map(Key::new).collect::>(); + let mut result = iter.into_result().into_iter().map(Key::from).collect::>(); result.sort_unstable_by(|a, b| { target.distance(a).cmp(&target.distance(b)) }); diff --git a/protocols/kad/src/record/store/memory.rs b/protocols/kad/src/record/store/memory.rs index 6f2b95da648..c0bb219ae49 100644 --- a/protocols/kad/src/record/store/memory.rs +++ b/protocols/kad/src/record/store/memory.rs @@ -78,7 +78,7 @@ impl MemoryStore { /// Creates a new `MemoryRecordStore` with the given configuration. pub fn with_config(local_id: PeerId, config: MemoryStoreConfig) -> Self { MemoryStore { - local_key: kbucket::Key::new(local_id), + local_key: kbucket::Key::from(local_id), config, records: HashMap::default(), provided: HashSet::default(), @@ -161,9 +161,9 @@ impl<'a> RecordStore<'a> for MemoryStore { // It is a new provider record for that key. let local_key = self.local_key.clone(); let key = kbucket::Key::new(record.key.clone()); - let provider = kbucket::Key::new(record.provider.clone()); + let provider = kbucket::Key::from(record.provider); if let Some(i) = providers.iter().position(|p| { - let pk = kbucket::Key::new(p.provider.clone()); + let pk = kbucket::Key::from(p.provider); provider.distance(&key) < pk.distance(&key) }) { // Insert the new provider. @@ -225,7 +225,7 @@ mod tests { fn distance(r: &ProviderRecord) -> kbucket::Distance { kbucket::Key::new(r.key.clone()) - .distance(&kbucket::Key::new(r.provider.clone())) + .distance(&kbucket::Key::from(r.provider)) } #[test] @@ -318,4 +318,3 @@ mod tests { } } } - diff --git a/protocols/mdns/CHANGELOG.md b/protocols/mdns/CHANGELOG.md index d57371394fe..7c45c4dc268 100644 --- a/protocols/mdns/CHANGELOG.md +++ b/protocols/mdns/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.27.0 [unreleased] + +- Update `libp2p-swarm` and `libp2p-core`. + # 0.26.0 [2020-12-08] - Create multiple multicast response packets as required to avoid diff --git a/protocols/mdns/Cargo.toml b/protocols/mdns/Cargo.toml index d1af2fde669..8a326677f92 100644 --- a/protocols/mdns/Cargo.toml +++ b/protocols/mdns/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "libp2p-mdns" edition = "2018" -version = "0.26.0" +version = "0.27.0" description = "Implementation of the libp2p mDNS discovery method" authors = ["Parity Technologies "] license = "MIT" @@ -16,8 +16,8 @@ dns-parser = "0.8.0" futures = "0.3.8" if-watch = "0.1.6" lazy_static = "1.4.0" -libp2p-core = { version = "0.25.0", path = "../../core" } -libp2p-swarm = { version = "0.25.0", path = "../../swarm" } +libp2p-core = { version = "0.26.0", path = "../../core" } +libp2p-swarm = { version = "0.26.0", path = "../../swarm" } log = "0.4.11" rand = "0.7.3" smallvec = "1.5.0" diff --git a/protocols/mdns/src/dns.rs b/protocols/mdns/src/dns.rs index f8a008b1e8f..4627d7d5e4e 100644 --- a/protocols/mdns/src/dns.rs +++ b/protocols/mdns/src/dns.rs @@ -281,7 +281,7 @@ fn segment_peer_id(peer_id: String) -> String { /// Combines and encodes a `PeerId` and service name for a DNS query. fn encode_peer_id(peer_id: &PeerId) -> Vec { // DNS-safe encoding for the Peer ID - let raw_peer_id = data_encoding::BASE32_DNSCURVE.encode(&peer_id.as_bytes()); + let raw_peer_id = data_encoding::BASE32_DNSCURVE.encode(&peer_id.to_bytes()); // ensure we don't have any labels over 63 bytes long let encoded_peer_id = segment_peer_id(raw_peer_id); let service_name = str::from_utf8(SERVICE_NAME).expect("SERVICE_NAME is always ASCII"); diff --git a/protocols/mdns/src/service.rs b/protocols/mdns/src/service.rs index 7cbd56af99a..84c535d8fc6 100644 --- a/protocols/mdns/src/service.rs +++ b/protocols/mdns/src/service.rs @@ -450,7 +450,7 @@ impl MdnsResponse { peer_name.retain(|c| c != '.'); let peer_id = match data_encoding::BASE32_DNSCURVE.decode(peer_name.as_bytes()) { - Ok(bytes) => match PeerId::from_bytes(bytes) { + Ok(bytes) => match PeerId::from_bytes(&bytes) { Ok(id) => id, Err(_) => return None, }, diff --git a/protocols/noise/CHANGELOG.md b/protocols/noise/CHANGELOG.md index 29a6e0cbbc1..70ae16c6806 100644 --- a/protocols/noise/CHANGELOG.md +++ b/protocols/noise/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.28.0 [unreleased] + +- Update `libp2p-core`. + # 0.27.0 [2020-11-25] - Update `libp2p-core`. diff --git a/protocols/noise/Cargo.toml b/protocols/noise/Cargo.toml index 59b6f9eac7b..135de2def70 100644 --- a/protocols/noise/Cargo.toml +++ b/protocols/noise/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "libp2p-noise" description = "Cryptographic handshake protocol using the noise framework." -version = "0.27.0" +version = "0.28.0" authors = ["Parity Technologies "] 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.25.0", path = "../../core" } +libp2p-core = { version = "0.26.0", path = "../../core" } log = "0.4" prost = "0.6.1" rand = "0.7.2" diff --git a/protocols/ping/CHANGELOG.md b/protocols/ping/CHANGELOG.md index a86557c4b9f..f2c6e9ef749 100644 --- a/protocols/ping/CHANGELOG.md +++ b/protocols/ping/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.26.0 [unreleased] + +- Update `libp2p-swarm` and `libp2p-core`. + # 0.25.0 [2020-11-25] - Update `libp2p-swarm` and `libp2p-core`. diff --git a/protocols/ping/Cargo.toml b/protocols/ping/Cargo.toml index 3aa96f74857..51abeb2ecf6 100644 --- a/protocols/ping/Cargo.toml +++ b/protocols/ping/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-ping" edition = "2018" description = "Ping protocol for libp2p" -version = "0.25.0" +version = "0.26.0" authors = ["Parity Technologies "] 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.25.0", path = "../../core" } -libp2p-swarm = { version = "0.25.0", path = "../../swarm" } +libp2p-core = { version = "0.26.0", path = "../../core" } +libp2p-swarm = { version = "0.26.0", path = "../../swarm" } log = "0.4.1" rand = "0.7.2" void = "1.0" diff --git a/protocols/plaintext/CHANGELOG.md b/protocols/plaintext/CHANGELOG.md index 635ae3cee98..31557d66374 100644 --- a/protocols/plaintext/CHANGELOG.md +++ b/protocols/plaintext/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.26.0 [unreleased] + +- Update `libp2p-core`. + # 0.25.0 [2020-11-25] - Update `libp2p-core`. diff --git a/protocols/plaintext/Cargo.toml b/protocols/plaintext/Cargo.toml index 017d2611cd8..25c8fe60b21 100644 --- a/protocols/plaintext/Cargo.toml +++ b/protocols/plaintext/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-plaintext" edition = "2018" description = "Plaintext encryption dummy protocol for libp2p" -version = "0.25.0" +version = "0.26.0" authors = ["Parity Technologies "] 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.25.0", path = "../../core" } +libp2p-core = { version = "0.26.0", path = "../../core" } log = "0.4.8" prost = "0.6.1" unsigned-varint = { version = "0.5.1", features = ["futures-codec"] } diff --git a/protocols/plaintext/src/handshake.rs b/protocols/plaintext/src/handshake.rs index 983a2d0ee8f..dda29af496d 100644 --- a/protocols/plaintext/src/handshake.rs +++ b/protocols/plaintext/src/handshake.rs @@ -53,7 +53,7 @@ pub struct Remote { impl HandshakeContext { fn new(config: PlainText2Config) -> Result { let exchange = Exchange { - id: Some(config.local_public_key.clone().into_peer_id().into_bytes()), + id: Some(config.local_public_key.clone().into_peer_id().to_bytes()), pubkey: Some(config.local_public_key.clone().into_protobuf_encoding()) }; let mut buf = Vec::with_capacity(exchange.encoded_len()); @@ -86,7 +86,7 @@ impl HandshakeContext { return Err(PlainTextError::InvalidPayload(None)); }, }; - let peer_id = match PeerId::from_bytes(prop.id.unwrap_or_default()) { + let peer_id = match PeerId::from_bytes(&prop.id.unwrap_or_default()) { Ok(p) => p, Err(_) => { debug!("failed to parse remote's exchange's id protobuf"); diff --git a/protocols/request-response/CHANGELOG.md b/protocols/request-response/CHANGELOG.md index a37a8a09ed5..3f993ea9912 100644 --- a/protocols/request-response/CHANGELOG.md +++ b/protocols/request-response/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.8.0 [unreleased] + +- Update `libp2p-swarm` and `libp2p-core`. + # 0.7.0 [2020-12-08] - Refine emitted events for inbound requests, introducing diff --git a/protocols/request-response/Cargo.toml b/protocols/request-response/Cargo.toml index c2c99d0f8b7..5b51cd8b57a 100644 --- a/protocols/request-response/Cargo.toml +++ b/protocols/request-response/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-request-response" edition = "2018" description = "Generic Request/Response Protocols" -version = "0.7.0" +version = "0.8.0" authors = ["Parity Technologies "] 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.25.0", path = "../../core" } -libp2p-swarm = { version = "0.25.0", path = "../../swarm" } +libp2p-core = { version = "0.26.0", path = "../../core" } +libp2p-swarm = { version = "0.26.0", path = "../../swarm" } log = "0.4.11" lru = "0.6" minicbor = { version = "0.7", features = ["std", "derive"] } diff --git a/protocols/secio/CHANGELOG.md b/protocols/secio/CHANGELOG.md index 3c24d7664c2..dc13b13681d 100644 --- a/protocols/secio/CHANGELOG.md +++ b/protocols/secio/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.26.0 [unreleased] + +- Update `libp2p-core`. + # 0.25.0 [2020-11-25] - Update `libp2p-core`. diff --git a/protocols/secio/Cargo.toml b/protocols/secio/Cargo.toml index fef7ae16f55..55e0090a3e3 100644 --- a/protocols/secio/Cargo.toml +++ b/protocols/secio/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-secio" edition = "2018" description = "Secio encryption protocol for libp2p" -version = "0.25.0" +version = "0.26.0" authors = ["Parity Technologies "] 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.25.0", path = "../../core" } +libp2p-core = { version = "0.26.0", path = "../../core" } log = "0.4.6" prost = "0.6.1" pin-project = "1.0.0" diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index c0437d9eafc..71b4c720642 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.26.0 [unreleased] + +- Update `libp2p-core`. + # 0.25.1 [2020-11-26] - Add `ExpandedSwarm::is_connected`. diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index 7c82ff67d67..5628b216c02 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-swarm" edition = "2018" description = "The libp2p swarm" -version = "0.25.1" +version = "0.26.0" authors = ["Parity Technologies "] 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.25.0", path = "../core" } +libp2p-core = { version = "0.26.0", path = "../core" } log = "0.4" rand = "0.7" smallvec = "1.0" diff --git a/transports/dns/CHANGELOG.md b/transports/dns/CHANGELOG.md index af69d4c0d62..af417160c7e 100644 --- a/transports/dns/CHANGELOG.md +++ b/transports/dns/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.26.0 [unreleased] + +- Update `libp2p-core`. + # 0.25.0 [2020-11-25] - Update `libp2p-core`. diff --git a/transports/dns/Cargo.toml b/transports/dns/Cargo.toml index 405edfe2d07..91cc136b422 100644 --- a/transports/dns/Cargo.toml +++ b/transports/dns/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-dns" edition = "2018" description = "DNS transport implementation for libp2p" -version = "0.25.0" +version = "0.26.0" authors = ["Parity Technologies "] 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.25.0", path = "../../core" } +libp2p-core = { version = "0.26.0", path = "../../core" } log = "0.4.1" futures = "0.3.1" diff --git a/transports/tcp/CHANGELOG.md b/transports/tcp/CHANGELOG.md index cf32e603aa9..6e57124e617 100644 --- a/transports/tcp/CHANGELOG.md +++ b/transports/tcp/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.26.0 [unreleased] + +- Update `async-io`. + # 0.25.1 [2020-11-26] - Lower `async-std` version to `1.6`, for compatibility diff --git a/transports/tcp/Cargo.toml b/transports/tcp/Cargo.toml index 9717c394e96..4ccf5beb50f 100644 --- a/transports/tcp/Cargo.toml +++ b/transports/tcp/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-tcp" edition = "2018" description = "TCP/IP transport protocol for libp2p" -version = "0.25.1" +version = "0.26.0" authors = ["Parity Technologies "] 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.25.0", path = "../../core" } +libp2p-core = { version = "0.26.0", path = "../../core" } log = "0.4.1" socket2 = { version = "0.3.12" } tokio = { version = "0.3", default-features = false, features = ["net"], optional = true } diff --git a/transports/uds/CHANGELOG.md b/transports/uds/CHANGELOG.md index f9df580ec3c..0bf8608c396 100644 --- a/transports/uds/CHANGELOG.md +++ b/transports/uds/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.26.0 [unreleased] + +- Update `libp2p-core`. + # 0.25.0 [2020-11-25] - Update `libp2p-core`. diff --git a/transports/uds/Cargo.toml b/transports/uds/Cargo.toml index 825ecafc470..a669c7d164f 100644 --- a/transports/uds/Cargo.toml +++ b/transports/uds/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-uds" edition = "2018" description = "Unix domain sockets transport for libp2p" -version = "0.25.0" +version = "0.26.0" authors = ["Parity Technologies "] 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.25.0", path = "../../core" } +libp2p-core = { version = "0.26.0", path = "../../core" } log = "0.4.1" futures = "0.3.1" tokio = { version = "0.3", default-features = false, features = ["net"], optional = true } diff --git a/transports/wasm-ext/CHANGELOG.md b/transports/wasm-ext/CHANGELOG.md index 03429ba533c..3361551283f 100644 --- a/transports/wasm-ext/CHANGELOG.md +++ b/transports/wasm-ext/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.26.0 [unreleased] + +- Update `libp2p-core`. + # 0.25.0 [2020-11-25] - Update `libp2p-core`. diff --git a/transports/wasm-ext/Cargo.toml b/transports/wasm-ext/Cargo.toml index c21d15a68b6..077a5f44039 100644 --- a/transports/wasm-ext/Cargo.toml +++ b/transports/wasm-ext/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "libp2p-wasm-ext" -version = "0.25.0" +version = "0.26.0" authors = ["Pierre Krieger "] 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.25.0", path = "../../core" } +libp2p-core = { version = "0.26.0", path = "../../core" } parity-send-wrapper = "0.1.0" wasm-bindgen = "0.2.42" wasm-bindgen-futures = "0.4.4" diff --git a/transports/websocket/CHANGELOG.md b/transports/websocket/CHANGELOG.md index f7367b98d0a..e2223698d1a 100644 --- a/transports/websocket/CHANGELOG.md +++ b/transports/websocket/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.27.0 [unreleased] + +- Update `libp2p-core`. + # 0.26.3 [2020-12-10] - Update `async-tls`. diff --git a/transports/websocket/Cargo.toml b/transports/websocket/Cargo.toml index 6347c92b896..385798d287f 100644 --- a/transports/websocket/Cargo.toml +++ b/transports/websocket/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-websocket" edition = "2018" description = "WebSocket transport for libp2p" -version = "0.26.3" +version = "0.27.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -13,7 +13,7 @@ categories = ["network-programming", "asynchronous"] async-tls = "0.11.0" either = "1.5.3" futures = "0.3.1" -libp2p-core = { version = "0.25.0", path = "../../core" } +libp2p-core = { version = "0.26.0", path = "../../core" } log = "0.4.8" quicksink = "0.1" rustls = "0.19.0" diff --git a/transports/websocket/src/tls.rs b/transports/websocket/src/tls.rs index a46cffa1b78..7ffdd057a38 100644 --- a/transports/websocket/src/tls.rs +++ b/transports/websocket/src/tls.rs @@ -168,4 +168,3 @@ impl From for Error { Error::Io(e) } } -