Skip to content

Commit

Permalink
Cherry-pick commits from master to stable-futures (#1296)
Browse files Browse the repository at this point in the history
* Implement Debug for (ed25519|secp256k1)::(Keypair|SecretKey) (#1285)

* Fix possible arithmetic overflow in libp2p-kad. (#1291)

When the number of active queries exceeds the (internal)
JOBS_MAX_QUERIES limit, which is only supposed to bound
the number of concurrent queries relating to background
jobs, an arithmetic overflow occurs. This is fixed by
using saturating subtraction.

* protocols/plaintext: Add example on how to upgrade with PlainTextConfig1 (#1286)

* [mdns] - Support for long mDNS names (Bug #1232) (#1287)

* Dead code -- commenting out with a note referencing future implementation

* Adding "std" feature so that cargo can build in other directories (notably `misc/mdns`, so that I could run these tests)

* Permitting `PeerID` to be built from an `Identity` multihash

* The length limit for DNS labels is 63 characters, as per RFC1035

* Allocates the vector with capacity for the service name plus additional QNAME encoding bytes

* Added support for encoding/decoding peer IDs with an encoded length greater than 63 characters

* Removing "std" from ring features

Co-Authored-By: Pierre Krieger <pierre.krieger1708@gmail.com>

* Retaining MAX_INLINE_KEY_LENGTH with comment about future usage

* `segment_peer_id` consumes `peer_id` ... plus an early return for IDs that don't need to be segmented

* Fixing logic

* Bump most dependencies (#1268)

* Bump most dependencies

This actually builds 😊.

* Bump all dependencies

Includes the excellent work of @rschulman in #1265.

* Remove use of ed25519-dalek fork

* Monomorphize more dependencies

* Add compatibility hack for rand

Cargo allows a crate to depend on multiple versions of another, but
`cargo-web` panics in that situation.  Use a wrapper crate to work
around the panic.

* Use @tomaka’s idea for using a newer `rand`

instead of my own ugly hack.

* Switch to Parity master

as its dependency-bumping PR has been merged.

* Update some depenendencies again

* Remove unwraps and `#[allow(deprecated)]`.

* Remove spurious changes to dependencies

Bumping minor or patch versions is not needed, and increases likelyhood
of merge conflicts.

* Remove some redundant Cargo.toml changes

* Replace a retry loop with an expect

`ed25519::SecretKey::from_bytes` will never fail for 32-byte inputs.

* Revert changes that don’t belong in this PR

* Remove using void to bypass ICE (#1295)

* Publish 0.13.0 (#1294)
  • Loading branch information
tomaka authored Nov 6, 2019
1 parent 7eb4165 commit c1226b2
Show file tree
Hide file tree
Showing 36 changed files with 322 additions and 170 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Version 0.13.0 (2019-11-05)

- Reworked the transport upgrade API. See https://github.com/libp2p/rust-libp2p/pull/1240 for more information.
- Added a parameter allowing to choose the protocol negotiation protocol when upgrading a connection or a substream. See https://github.com/libp2p/rust-libp2p/pull/1245 for more information.
- Added an alternative `multistream-select` protocol called `V1Lazy`.
- Added `PlainText2Config` that implements the `/plaintext/2.0.0` protocol.
- Refactored `libp2p-identify`. Some items have been renamed.
- Now accepting `PeerId`s using the `identity` hashing algorithm as valid.
- Removed `libp2p-observed` and `libp2p-ratelimit`.
- Fixed mDNS long peer IDs not being transmitted properly.
- Added some `Debug` trait implementations.
- Fixed potential arithmetic overflows in `libp2p-kad` and `multistream-select`.

# Version 0.12.0 (2019-08-15)

- In some situations, `multistream-select` will now assume that protocol negotiation immediately succeeds. If it turns out that it failed, an error is generated when reading or writing from/to the stream.
Expand Down
48 changes: 24 additions & 24 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "libp2p"
edition = "2018"
description = "Peer-to-peer networking library"
version = "0.12.0"
version = "0.13.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand All @@ -16,39 +16,39 @@ secp256k1 = ["libp2p-core/secp256k1", "libp2p-secio/secp256k1"]
[dependencies]
bytes = "0.4"
futures = "0.1"
multiaddr = { package = "parity-multiaddr", version = "0.5.0", path = "misc/multiaddr" }
multihash = { package = "parity-multihash", version = "0.1.0", path = "misc/multihash" }
multiaddr = { package = "parity-multiaddr", version = "0.5.1", path = "misc/multiaddr" }
multihash = { package = "parity-multihash", version = "0.1.4", path = "misc/multihash" }
lazy_static = "1.2"
libp2p-mplex = { version = "0.12.0", path = "muxers/mplex" }
libp2p-identify = { version = "0.12.0", path = "protocols/identify" }
libp2p-kad = { version = "0.12.0", path = "protocols/kad" }
libp2p-floodsub = { version = "0.12.0", path = "protocols/floodsub" }
libp2p-ping = { version = "0.12.0", path = "protocols/ping" }
libp2p-plaintext = { version = "0.12.0", path = "protocols/plaintext" }
libp2p-core = { version = "0.12.0", path = "core" }
libp2p-core-derive = { version = "0.12.0", path = "misc/core-derive" }
libp2p-secio = { version = "0.12.0", path = "protocols/secio", default-features = false }
libp2p-swarm = { version = "0.2.0", path = "swarm" }
libp2p-uds = { version = "0.12.0", path = "transports/uds" }
libp2p-wasm-ext = { version = "0.5.0", path = "transports/wasm-ext" }
libp2p-yamux = { version = "0.12.0", path = "muxers/yamux" }
parking_lot = "0.8"
libp2p-mplex = { version = "0.13.0", path = "muxers/mplex" }
libp2p-identify = { version = "0.13.0", path = "protocols/identify" }
libp2p-kad = { version = "0.13.0", path = "protocols/kad" }
libp2p-floodsub = { version = "0.13.0", path = "protocols/floodsub" }
libp2p-ping = { version = "0.13.0", path = "protocols/ping" }
libp2p-plaintext = { version = "0.13.0", path = "protocols/plaintext" }
libp2p-core = { version = "0.13.0", path = "core" }
libp2p-core-derive = { version = "0.13.0", path = "misc/core-derive" }
libp2p-secio = { version = "0.13.0", path = "protocols/secio", default-features = false }
libp2p-swarm = { version = "0.3.0", path = "swarm" }
libp2p-uds = { version = "0.13.0", path = "transports/uds" }
libp2p-wasm-ext = { version = "0.6.0", path = "transports/wasm-ext" }
libp2p-yamux = { version = "0.13.0", path = "muxers/yamux" }
parking_lot = "0.9.0"
smallvec = "0.6"
tokio-codec = "0.1"
tokio-executor = "0.1"
tokio-io = "0.1"
wasm-timer = "0.1"

[target.'cfg(not(any(target_os = "emscripten", target_os = "unknown")))'.dependencies]
libp2p-deflate = { version = "0.4.0", path = "protocols/deflate" }
libp2p-dns = { version = "0.12.0", path = "transports/dns" }
libp2p-mdns = { version = "0.12.0", path = "misc/mdns" }
libp2p-noise = { version = "0.10.0", path = "protocols/noise" }
libp2p-tcp = { version = "0.12.0", path = "transports/tcp" }
libp2p-websocket = { version = "0.12.0", path = "transports/websocket", optional = true }
libp2p-deflate = { version = "0.5.0", path = "protocols/deflate" }
libp2p-dns = { version = "0.13.0", path = "transports/dns" }
libp2p-mdns = { version = "0.13.0", path = "misc/mdns" }
libp2p-noise = { version = "0.11.0", path = "protocols/noise" }
libp2p-tcp = { version = "0.13.0", path = "transports/tcp" }
libp2p-websocket = { version = "0.13.0", path = "transports/websocket", optional = true }

[dev-dependencies]
env_logger = "0.6.0"
env_logger = "0.7.1"
tokio = "0.1"
tokio-stdin-stdout = "0.1"

Expand Down
30 changes: 15 additions & 15 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "libp2p-core"
edition = "2018"
description = "Core traits and structs of libp2p"
version = "0.12.0"
version = "0.13.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand All @@ -11,22 +11,22 @@ categories = ["network-programming", "asynchronous"]

[dependencies]
asn1_der = "0.6.1"
bs58 = "0.2.0"
bs58 = "0.3.0"
bytes = "0.4"
ed25519-dalek = "1.0.0-pre.1"
ed25519-dalek = "1.0.0-pre.2"
failure = "0.1"
fnv = "1.0"
futures-timer = "0.3"
lazy_static = "1.2"
log = "0.4"
multiaddr = { package = "parity-multiaddr", version = "0.5.0", path = "../misc/multiaddr" }
multihash = { package = "parity-multihash", version = "0.1.0", path = "../misc/multihash" }
multistream-select = { version = "0.5.0", path = "../misc/multistream-select" }
multihash = { package = "parity-multihash", version = "0.1.4", path = "../misc/multihash" }
multistream-select = { version = "0.6.0", path = "../misc/multistream-select" }
futures-preview = { version = "0.3.0-alpha.18", features = ["compat", "io-compat"] }
parking_lot = "0.8"
parking_lot = "0.9.0"
protobuf = "2.8"
quick-error = "1.2"
rand = "0.6"
rand = "0.7"
rw-stream-sink = { version = "0.1.1", path = "../misc/rw-stream-sink" }
libsecp256k1 = { version = "0.3.1", optional = true }
sha2 = "0.8.0"
Expand All @@ -37,17 +37,17 @@ void = "1"
zeroize = "1"

[target.'cfg(not(any(target_os = "emscripten", target_os = "unknown")))'.dependencies]
ring = { version = "^0.16", features = ["alloc", "std"], default-features = false }
untrusted = { version = "0.6" }
ring = { version = "0.16.9", features = ["alloc", "std"], default-features = false }
untrusted = "0.7.0"

[dev-dependencies]
async-std = "0.99"
libp2p-swarm = { version = "0.2.0", path = "../swarm" }
libp2p-tcp = { version = "0.12.0", path = "../transports/tcp" }
libp2p-mplex = { version = "0.12.0", path = "../muxers/mplex" }
libp2p-secio = { version = "0.12.0", path = "../protocols/secio" }
rand = "0.6"
quickcheck = "0.8"
libp2p-swarm = { version = "0.3.0", path = "../swarm" }
libp2p-tcp = { version = "0.13.0", path = "../transports/tcp" }
libp2p-mplex = { version = "0.13.0", path = "../muxers/mplex" }
libp2p-secio = { version = "0.13.0", path = "../protocols/secio" }
rand = "0.7.2"
quickcheck = "0.9.0"
wasm-timer = "0.2"
assert_matches = "1.3"

Expand Down
25 changes: 21 additions & 4 deletions core/src/identity/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@

use ed25519_dalek as ed25519;
use failure::Fail;
use rand::RngCore;
use super::error::DecodingError;
use zeroize::Zeroize;
use core::fmt;

/// An Ed25519 keypair.
pub struct Keypair(ed25519::Keypair);

impl Keypair {
/// Generate a new Ed25519 keypair.
pub fn generate() -> Keypair {
Keypair(ed25519::Keypair::generate(&mut rand::thread_rng()))
Keypair::from(SecretKey::generate())
}

/// Encode the keypair into a byte array by concatenating the bytes
Expand Down Expand Up @@ -66,6 +68,12 @@ impl Keypair {
}
}

impl fmt::Debug for Keypair {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Keypair").field("public", &self.0.public).finish()
}
}

impl Clone for Keypair {
fn clone(&self) -> Keypair {
let mut sk_bytes = self.0.secret.to_bytes();
Expand All @@ -87,9 +95,9 @@ impl From<Keypair> for SecretKey {
/// Promote an Ed25519 secret key into a keypair.
impl From<SecretKey> for Keypair {
fn from(sk: SecretKey) -> Keypair {
let secret = sk.0;
let secret: ed25519::ExpandedSecretKey = (&sk.0).into();
let public = ed25519::PublicKey::from(&secret);
Keypair(ed25519::Keypair { secret, public })
Keypair(ed25519::Keypair { secret: sk.0, public })
}
}

Expand Down Expand Up @@ -135,10 +143,19 @@ impl Clone for SecretKey {
}
}

impl fmt::Debug for SecretKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "SecretKey")
}
}

impl SecretKey {
/// Generate a new Ed25519 secret key.
pub fn generate() -> SecretKey {
SecretKey(ed25519::SecretKey::generate(&mut rand::thread_rng()))
let mut bytes = [0u8; 32];
rand::thread_rng().fill_bytes(&mut bytes);
SecretKey(ed25519::SecretKey::from_bytes(&bytes)
.expect("this returns `Err` only if the length is wrong; the length is correct; qed"))
}

/// Create an Ed25519 secret key from a byte slice, zeroing the input on success.
Expand Down
13 changes: 13 additions & 0 deletions core/src/identity/secp256k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use sha2::{Digest as ShaDigestTrait, Sha256};
use secp256k1::{Message, Signature};
use super::error::{DecodingError, SigningError};
use zeroize::Zeroize;
use core::fmt;

/// A Secp256k1 keypair.
#[derive(Clone)]
Expand All @@ -51,6 +52,12 @@ impl Keypair {
}
}

impl fmt::Debug for Keypair {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Keypair").field("public", &self.public).finish()
}
}

/// Promote a Secp256k1 secret key into a keypair.
impl From<SecretKey> for Keypair {
fn from(secret: SecretKey) -> Keypair {
Expand All @@ -70,6 +77,12 @@ impl From<Keypair> for SecretKey {
#[derive(Clone)]
pub struct SecretKey(secp256k1::SecretKey);

impl fmt::Debug for SecretKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "SecretKey")
}
}

impl SecretKey {
/// Generate a new Secp256k1 secret key.
pub fn generate() -> SecretKey {
Expand Down
4 changes: 3 additions & 1 deletion core/src/peer_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ use std::{convert::TryFrom, fmt, str::FromStr};

/// Public keys with byte-lengths smaller than `MAX_INLINE_KEY_LENGTH` will be
/// automatically used as the peer id using an identity multihash.
//
// Note: see `from_public_key` for how this value will be used in the future.
const MAX_INLINE_KEY_LENGTH: usize = 42;

/// Identifier of a peer of the network.
Expand Down Expand Up @@ -98,7 +100,7 @@ impl PeerId {
/// returns back the data as an error.
#[inline]
pub fn from_multihash(data: multihash::Multihash) -> Result<PeerId, multihash::Multihash> {
if data.algorithm() == multihash::Hash::SHA2256 {
if data.algorithm() == multihash::Hash::SHA2256 || data.algorithm() == multihash::Hash::Identity {
Ok(PeerId { multihash: data })
} else {
Err(data)
Expand Down
4 changes: 2 additions & 2 deletions misc/core-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "libp2p-core-derive"
edition = "2018"
description = "Procedural macros of libp2p-core"
version = "0.12.0"
version = "0.13.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand All @@ -17,4 +17,4 @@ syn = { version = "0.15.22", default-features = false, features = ["clone-impls"
quote = "0.6"

[dev-dependencies]
libp2p = { version = "0.12.0", path = "../.." }
libp2p = { version = "0.13.0", path = "../.." }
6 changes: 3 additions & 3 deletions misc/mdns/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "libp2p-mdns"
edition = "2018"
version = "0.12.0"
version = "0.13.0"
description = "Implementation of the libp2p mDNS discovery method"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
Expand All @@ -14,8 +14,8 @@ async-std = "0.99"
data-encoding = "2.0"
dns-parser = "0.8"
futures-preview = "0.3.0-alpha.18"
libp2p-core = { version = "0.12.0", path = "../../core" }
libp2p-swarm = { version = "0.2.0", path = "../../swarm" }
libp2p-core = { version = "0.13.0", path = "../../core" }
libp2p-swarm = { version = "0.3.0", path = "../../swarm" }
log = "0.4"
multiaddr = { package = "parity-multiaddr", version = "0.5.0", path = "../multiaddr" }
net2 = "0.2"
Expand Down
Loading

0 comments on commit c1226b2

Please sign in to comment.