mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-15 02:51:25 +00:00
Stack allocated PeerId (#1874)
* Stack allocate PeerId. * Update stuff. * Upgrade rusttls to fix build. * Remove unnecessary manual implementations. * Remove PeerId::into_bytes. * Remove bytes dependency. * Perform some cleanup. * Use Into<kbucket::Key<K>>. * Update versions and changelogs. * Fix PR link. * Fix benchmarks. Co-authored-by: Roman S. Borschel <roman@parity.io>
This commit is contained in:
@ -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`.
|
||||
|
40
Cargo.toml
40
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 <admin@parity.io>"]
|
||||
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"
|
||||
|
@ -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`.
|
||||
|
@ -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 <admin@parity.io>"]
|
||||
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"
|
||||
|
@ -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());
|
||||
})
|
||||
});
|
||||
}
|
||||
|
@ -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,
|
||||
})
|
||||
|
@ -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<cmp::Ordering> {
|
||||
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<u8>) -> Result<PeerId, Vec<u8>> {
|
||||
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<PeerId, Error> {
|
||||
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<PeerId, Multihash> {
|
||||
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<u8> {
|
||||
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<u8> {
|
||||
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<bool> {
|
||||
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<H>(&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<Vec<u8>> for PeerId {
|
||||
type Error = Vec<u8>;
|
||||
|
||||
fn try_from(value: Vec<u8>) -> Result<Self, Self::Error> {
|
||||
PeerId::from_bytes(value)
|
||||
PeerId::from_bytes(&value).map_err(|_| value)
|
||||
}
|
||||
}
|
||||
|
||||
@ -186,33 +141,21 @@ impl TryFrom<Multihash> for PeerId {
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<PeerId> 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<Multihash> 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<PeerId> for Multihash {
|
||||
fn from(peer_id: PeerId) -> Self {
|
||||
Multihash::from_bytes(&peer_id.multihash)
|
||||
.expect("PeerIds always contain valid Multihashes")
|
||||
peer_id.multihash
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PeerId> for Vec<u8> {
|
||||
fn from(peer_id: PeerId) -> Self {
|
||||
peer_id.to_bytes()
|
||||
}
|
||||
}
|
||||
|
||||
@ -230,7 +173,7 @@ impl FromStr for PeerId {
|
||||
#[inline]
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,7 @@
|
||||
# 0.26.0 [unreleased]
|
||||
|
||||
- Update `libp2p-core`.
|
||||
|
||||
# 0.25.0 [2020-11-25]
|
||||
|
||||
- Update `libp2p-core`.
|
||||
|
@ -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 <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.25.0", path = "../../core" }
|
||||
libp2p-core = { version = "0.26.0", path = "../../core" }
|
||||
log = "0.4"
|
||||
nohash-hasher = "0.2"
|
||||
parking_lot = "0.11"
|
||||
|
@ -1,3 +1,7 @@
|
||||
# 0.29.0 [unreleased]
|
||||
|
||||
- Update `libp2p-core`.
|
||||
|
||||
# 0.28.0 [2020-11-25]
|
||||
|
||||
- Update `libp2p-core`.
|
||||
|
@ -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 <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.25.0", path = "../../core" }
|
||||
libp2p-core = { version = "0.26.0", path = "../../core" }
|
||||
parking_lot = "0.11"
|
||||
thiserror = "1.0"
|
||||
yamux = "0.8.0"
|
||||
|
@ -1,3 +1,7 @@
|
||||
# 0.26.0 [unreleased]
|
||||
|
||||
- Update `libp2p-core`.
|
||||
|
||||
# 0.25.0 [2020-11-25]
|
||||
|
||||
- Update `libp2p-core`.
|
||||
|
@ -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 <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.25.0", path = "../../core" }
|
||||
libp2p-core = { version = "0.26.0", path = "../../core" }
|
||||
flate2 = "1.0"
|
||||
|
||||
[dev-dependencies]
|
||||
|
@ -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`.
|
||||
|
@ -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 <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.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"
|
||||
|
@ -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
|
||||
|
@ -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`.
|
||||
|
@ -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 <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.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"
|
||||
|
@ -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(),
|
||||
|
@ -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()
|
||||
};
|
||||
|
@ -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")
|
||||
})?,
|
||||
)
|
||||
|
@ -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`.
|
||||
|
@ -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 <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.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"
|
||||
|
@ -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`.
|
||||
|
@ -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 <admin@parity.io>"]
|
||||
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"
|
||||
|
@ -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<kbucket::EntryView<kbucket::Key<PeerId>, 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<kbucket::EntryView<kbucket::Key<PeerId>, 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<K>(&mut self, key: K)
|
||||
-> Option<kbucket::KBucketRef<'_, kbucket::Key<PeerId>, Addresses>>
|
||||
where
|
||||
K: Borrow<[u8]> + Clone
|
||||
K: Into<kbucket::Key<K>> + 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<K>(&mut self, key: K) -> QueryId
|
||||
where
|
||||
K: Borrow<[u8]> + Clone
|
||||
K: Into<kbucket::Key<K>> + Into<Vec<u8>> + 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<K> = 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::<Vec<_>>())
|
||||
} 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<Multiaddr>, 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::<Vec<_>>().into_iter()
|
||||
@ -1447,7 +1447,7 @@ where
|
||||
fn addresses_of_peer(&mut self, peer_id: &PeerId) -> Vec<Multiaddr> {
|
||||
// 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::<Vec<_>>();
|
||||
@ -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<QueryId> {
|
||||
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 {
|
||||
|
@ -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::<Vec<_>>();
|
||||
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::<Vec<_>>();
|
||||
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(())
|
||||
|
@ -432,7 +432,7 @@ mod tests {
|
||||
let mut bucket = KBucket::<Key<PeerId>, ()>::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<Key<PeerId>, ()>, 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);
|
||||
|
@ -103,7 +103,11 @@ impl From<Multihash> for Key<Multihash> {
|
||||
|
||||
impl From<PeerId> for Key<PeerId> {
|
||||
fn from(p: PeerId) -> Self {
|
||||
Key::new(p)
|
||||
let bytes = KeyBytes(Sha256::digest(&p.to_bytes()));
|
||||
Key {
|
||||
preimage: p,
|
||||
bytes
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ impl TryFrom<proto::message::Peer> for KadPeer {
|
||||
fn try_from(peer: proto::message::Peer) -> Result<KadPeer, Self::Error> {
|
||||
// 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<proto::message::Peer> for KadPeer {
|
||||
impl Into<proto::message::Peer> 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<Record, io::Error> {
|
||||
|
||||
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();
|
||||
|
@ -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::<Vec<_>>();
|
||||
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::<Vec<_>>();
|
||||
let mut result = iter.into_result().into_iter().map(Key::from).collect::<Vec<_>>();
|
||||
result.sort_unstable_by(|a, b| {
|
||||
target.distance(a).cmp(&target.distance(b))
|
||||
});
|
||||
|
@ -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 {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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 <admin@parity.io>"]
|
||||
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"
|
||||
|
@ -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<u8> {
|
||||
// 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");
|
||||
|
@ -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,
|
||||
},
|
||||
|
@ -1,3 +1,7 @@
|
||||
# 0.28.0 [unreleased]
|
||||
|
||||
- Update `libp2p-core`.
|
||||
|
||||
# 0.27.0 [2020-11-25]
|
||||
|
||||
- Update `libp2p-core`.
|
||||
|
@ -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 <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.25.0", path = "../../core" }
|
||||
libp2p-core = { version = "0.26.0", path = "../../core" }
|
||||
log = "0.4"
|
||||
prost = "0.6.1"
|
||||
rand = "0.7.2"
|
||||
|
@ -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`.
|
||||
|
@ -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 <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.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"
|
||||
|
@ -1,3 +1,7 @@
|
||||
# 0.26.0 [unreleased]
|
||||
|
||||
- Update `libp2p-core`.
|
||||
|
||||
# 0.25.0 [2020-11-25]
|
||||
|
||||
- Update `libp2p-core`.
|
||||
|
@ -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 <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.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"] }
|
||||
|
@ -53,7 +53,7 @@ pub struct Remote {
|
||||
impl HandshakeContext<Local> {
|
||||
fn new(config: PlainText2Config) -> Result<Self, PlainTextError> {
|
||||
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<Local> {
|
||||
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");
|
||||
|
@ -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
|
||||
|
@ -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 <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.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"] }
|
||||
|
@ -1,3 +1,7 @@
|
||||
# 0.26.0 [unreleased]
|
||||
|
||||
- Update `libp2p-core`.
|
||||
|
||||
# 0.25.0 [2020-11-25]
|
||||
|
||||
- Update `libp2p-core`.
|
||||
|
@ -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 <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.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"
|
||||
|
@ -1,3 +1,7 @@
|
||||
# 0.26.0 [unreleased]
|
||||
|
||||
- Update `libp2p-core`.
|
||||
|
||||
# 0.25.1 [2020-11-26]
|
||||
|
||||
- Add `ExpandedSwarm::is_connected`.
|
||||
|
@ -2,7 +2,7 @@
|
||||
name = "libp2p-swarm"
|
||||
edition = "2018"
|
||||
description = "The libp2p swarm"
|
||||
version = "0.25.1"
|
||||
version = "0.26.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.25.0", path = "../core" }
|
||||
libp2p-core = { version = "0.26.0", path = "../core" }
|
||||
log = "0.4"
|
||||
rand = "0.7"
|
||||
smallvec = "1.0"
|
||||
|
@ -1,3 +1,7 @@
|
||||
# 0.26.0 [unreleased]
|
||||
|
||||
- Update `libp2p-core`.
|
||||
|
||||
# 0.25.0 [2020-11-25]
|
||||
|
||||
- Update `libp2p-core`.
|
||||
|
@ -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 <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.25.0", path = "../../core" }
|
||||
libp2p-core = { version = "0.26.0", path = "../../core" }
|
||||
log = "0.4.1"
|
||||
futures = "0.3.1"
|
||||
|
@ -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
|
||||
|
@ -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 <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.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 }
|
||||
|
@ -1,3 +1,7 @@
|
||||
# 0.26.0 [unreleased]
|
||||
|
||||
- Update `libp2p-core`.
|
||||
|
||||
# 0.25.0 [2020-11-25]
|
||||
|
||||
- Update `libp2p-core`.
|
||||
|
@ -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 <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.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 }
|
||||
|
@ -1,3 +1,7 @@
|
||||
# 0.26.0 [unreleased]
|
||||
|
||||
- Update `libp2p-core`.
|
||||
|
||||
# 0.25.0 [2020-11-25]
|
||||
|
||||
- Update `libp2p-core`.
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "libp2p-wasm-ext"
|
||||
version = "0.25.0"
|
||||
version = "0.26.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.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"
|
||||
|
@ -1,3 +1,7 @@
|
||||
# 0.27.0 [unreleased]
|
||||
|
||||
- Update `libp2p-core`.
|
||||
|
||||
# 0.26.3 [2020-12-10]
|
||||
|
||||
- Update `async-tls`.
|
||||
|
@ -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 <admin@parity.io>"]
|
||||
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"
|
||||
|
@ -168,4 +168,3 @@ impl From<io::Error> for Error {
|
||||
Error::Io(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user