From 95d68b0920260661e4c1109b4ca83c53923d8944 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 22 Mar 2023 12:58:53 +0100 Subject: [PATCH 01/20] Remove `multiaddr` dependency from `libp2p-identity` --- Cargo.lock | 1 - identity/CHANGELOG.md | 8 ++++++++ identity/Cargo.toml | 3 +-- identity/src/peer_id.rs | 40 ---------------------------------------- 4 files changed, 9 insertions(+), 43 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e1f482786e0..efb67b3a533 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2434,7 +2434,6 @@ dependencies = [ "ed25519-dalek", "libsecp256k1", "log", - "multiaddr", "multihash", "p256 0.12.0", "prost", diff --git a/identity/CHANGELOG.md b/identity/CHANGELOG.md index e74f4004b0c..3dbb76dabd9 100644 --- a/identity/CHANGELOG.md +++ b/identity/CHANGELOG.md @@ -1,3 +1,11 @@ +# 0.2.0 - unreleased + +- Remove `PeerId::try_from_multiaddr`. + `multiaddr::Protocol::P2p` is now type-safe and contains a `PeerId` directly, rendering this function obsolete. + See [PR XXXX]. + +[PR XXXX]: https://github.com/libp2p/rust-libp2p/pull/XXXX + # 0.1.1 - Add `From` impl for specific keypairs. diff --git a/identity/Cargo.toml b/identity/Cargo.toml index 83af0c96201..cb916afc3f5 100644 --- a/identity/Cargo.toml +++ b/identity/Cargo.toml @@ -17,7 +17,6 @@ bs58 = { version = "0.4.0", optional = true } ed25519-dalek = { version = "1.0.1", optional = true } libsecp256k1 = { version = "0.7.0", optional = true } log = "0.4" -multiaddr = { version = "0.17.0", optional = true } multihash = { version = "0.17.0", default-features = false, features = ["std", "multihash-impl", "identity", "sha2"], optional = true } p256 = { version = "0.12", default-features = false, features = ["ecdsa", "std"], optional = true } prost = { version = "0.11", optional = true } @@ -38,7 +37,7 @@ secp256k1 = [ "libsecp256k1", "asn1_der", "prost", "rand", "sha2", "zeroize" ] ecdsa = [ "p256", "prost", "rand", "void", "zeroize", "sec1" ] rsa = [ "dep:ring", "asn1_der", "prost", "rand", "zeroize" ] ed25519 = [ "ed25519-dalek", "prost", "rand", "zeroize" ] -peerid = [ "multihash", "multiaddr", "bs58", "rand", "thiserror" ] +peerid = [ "multihash", "bs58", "rand", "thiserror" ] [dev-dependencies] quickcheck = { package = "quickcheck-ext", path = "../misc/quickcheck-ext" } diff --git a/identity/src/peer_id.rs b/identity/src/peer_id.rs index ae9ffc80c0a..106baa75ce5 100644 --- a/identity/src/peer_id.rs +++ b/identity/src/peer_id.rs @@ -18,7 +18,6 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use multiaddr::{Multiaddr, Protocol}; use multihash::{Code, Error, Multihash}; use rand::Rng; use std::{convert::TryFrom, fmt, str::FromStr}; @@ -91,17 +90,6 @@ impl PeerId { } } - /// Tries to extract a [`PeerId`] from the given [`Multiaddr`]. - /// - /// In case the given [`Multiaddr`] ends with `/p2p/`, this function - /// will return the encapsulated [`PeerId`], otherwise it will return `None`. - pub fn try_from_multiaddr(address: &Multiaddr) -> Option { - address.iter().last().and_then(|p| match p { - Protocol::P2p(hash) => PeerId::from_multihash(hash).ok(), - _ => None, - }) - } - /// Generates a random peer ID from a cryptographically secure PRNG. /// /// This is useful for randomly walking on a DHT, or for testing purposes. @@ -288,32 +276,4 @@ mod tests { assert_eq!(peer_id, PeerId::from_bytes(&peer_id.to_bytes()).unwrap()); } } - - #[test] - fn extract_peer_id_from_multi_address() { - let address = "/memory/1234/p2p/12D3KooWGQmdpzHXCqLno4mMxWXKNFQHASBeF99gTm2JR8Vu5Bdc" - .to_string() - .parse() - .unwrap(); - - #[allow(deprecated)] - let peer_id = PeerId::try_from_multiaddr(&address).unwrap(); - - assert_eq!( - peer_id, - "12D3KooWGQmdpzHXCqLno4mMxWXKNFQHASBeF99gTm2JR8Vu5Bdc" - .parse() - .unwrap() - ); - } - - #[test] - fn no_panic_on_extract_peer_id_from_multi_address_if_not_present() { - let address = "/memory/1234".to_string().parse().unwrap(); - - #[allow(deprecated)] - let maybe_empty = PeerId::try_from_multiaddr(&address); - - assert!(maybe_empty.is_none()); - } } From baaf8c8e07ff7b8fe7d9d2999a37e30ebc398177 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 22 Mar 2023 13:32:04 +0100 Subject: [PATCH 02/20] Bump `libp2p-identity` version --- Cargo.lock | 2 +- core/Cargo.toml | 2 +- identity/Cargo.toml | 2 +- libp2p/Cargo.toml | 2 +- misc/allow-block-list/Cargo.toml | 2 +- misc/connection-limits/Cargo.toml | 2 +- misc/keygen/Cargo.toml | 2 +- misc/metrics/Cargo.toml | 2 +- muxers/mplex/Cargo.toml | 2 +- protocols/autonat/Cargo.toml | 2 +- protocols/dcutr/Cargo.toml | 2 +- protocols/floodsub/Cargo.toml | 2 +- protocols/gossipsub/Cargo.toml | 2 +- protocols/identify/Cargo.toml | 2 +- protocols/kad/Cargo.toml | 2 +- protocols/mdns/Cargo.toml | 2 +- protocols/perf/Cargo.toml | 2 +- protocols/ping/Cargo.toml | 2 +- protocols/relay/Cargo.toml | 2 +- protocols/rendezvous/Cargo.toml | 2 +- protocols/request-response/Cargo.toml | 2 +- swarm-test/Cargo.toml | 2 +- swarm/Cargo.toml | 4 ++-- transports/dns/Cargo.toml | 2 +- transports/noise/Cargo.toml | 2 +- transports/plaintext/Cargo.toml | 2 +- transports/quic/Cargo.toml | 2 +- transports/tcp/Cargo.toml | 2 +- transports/tls/Cargo.toml | 2 +- transports/webrtc/Cargo.toml | 2 +- transports/websocket/Cargo.toml | 2 +- 31 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index efb67b3a533..907f5d3ff28 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2425,7 +2425,7 @@ dependencies = [ [[package]] name = "libp2p-identity" -version = "0.1.1" +version = "0.2.0" dependencies = [ "asn1_der", "base64 0.21.0", diff --git a/core/Cargo.toml b/core/Cargo.toml index f05c912ad72..4f031698187 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -16,7 +16,7 @@ fnv = "1.0" futures = { version = "0.3.27", features = ["executor", "thread-pool"] } futures-timer = "3" instant = "0.1.11" -libp2p-identity = { version = "0.1", path = "../identity", features = ["peerid", "ed25519"] } +libp2p-identity = { version = "0.2", path = "../identity", features = ["peerid", "ed25519"] } log = "0.4" multiaddr = { version = "0.17.0" } multihash = { version = "0.17.0", default-features = false, features = ["std", "multihash-impl", "identity", "sha2"] } diff --git a/identity/Cargo.toml b/identity/Cargo.toml index cb916afc3f5..88cdd1c3e37 100644 --- a/identity/Cargo.toml +++ b/identity/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "libp2p-identity" -version = "0.1.1" +version = "0.2.0" edition = "2021" description = "Data structures and algorithms for identifying peers in libp2p." rust-version = "1.60.0" diff --git a/libp2p/Cargo.toml b/libp2p/Cargo.toml index 33176cfaf95..a9c59f48987 100644 --- a/libp2p/Cargo.toml +++ b/libp2p/Cargo.toml @@ -103,7 +103,7 @@ libp2p-core = { version = "0.39.0", path = "../core" } libp2p-dcutr = { version = "0.9.0", path = "../protocols/dcutr", optional = true } libp2p-floodsub = { version = "0.42.0", path = "../protocols/floodsub", optional = true } libp2p-identify = { version = "0.42.0", path = "../protocols/identify", optional = true } -libp2p-identity = { version = "0.1.0", path = "../identity" } +libp2p-identity = { version = "0.2.0", path = "../identity" } libp2p-kad = { version = "0.43.0", path = "../protocols/kad", optional = true } libp2p-metrics = { version = "0.12.0", path = "../misc/metrics", optional = true } libp2p-mplex = { version = "0.39.0", path = "../muxers/mplex", optional = true } diff --git a/misc/allow-block-list/Cargo.toml b/misc/allow-block-list/Cargo.toml index a175876179f..5a9b0688692 100644 --- a/misc/allow-block-list/Cargo.toml +++ b/misc/allow-block-list/Cargo.toml @@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-swarm = { version = "0.42.0", path = "../../swarm" } -libp2p-identity = { version = "0.1.0", path = "../../identity", features = ["peerid"] } +libp2p-identity = { version = "0.2.0", path = "../../identity", features = ["peerid"] } void = "1" [dev-dependencies] diff --git a/misc/connection-limits/Cargo.toml b/misc/connection-limits/Cargo.toml index 3bf2675beb4..33b4eaf5ed6 100644 --- a/misc/connection-limits/Cargo.toml +++ b/misc/connection-limits/Cargo.toml @@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-swarm = { version = "0.42.0", path = "../../swarm" } -libp2p-identity = { version = "0.1.0", path = "../../identity", features = ["peerid"] } +libp2p-identity = { version = "0.2.0", path = "../../identity", features = ["peerid"] } void = "1" [dev-dependencies] diff --git a/misc/keygen/Cargo.toml b/misc/keygen/Cargo.toml index bd9cdc4b4a9..51e554dad8d 100644 --- a/misc/keygen/Cargo.toml +++ b/misc/keygen/Cargo.toml @@ -16,4 +16,4 @@ serde = { version = "1.0.157", features = ["derive"] } serde_json = "1.0.94" libp2p-core = { version = "0.39.0", path = "../../core" } base64 = "0.21.0" -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } diff --git a/misc/metrics/Cargo.toml b/misc/metrics/Cargo.toml index 63a017b4923..a2ef4c86746 100644 --- a/misc/metrics/Cargo.toml +++ b/misc/metrics/Cargo.toml @@ -26,7 +26,7 @@ libp2p-kad = { version = "0.43.0", path = "../../protocols/kad", optional = true libp2p-ping = { version = "0.42.0", path = "../../protocols/ping", optional = true } libp2p-relay = { version = "0.15.0", path = "../../protocols/relay", optional = true } libp2p-swarm = { version = "0.42.0", path = "../../swarm" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } prometheus-client = "0.19.0" [target.'cfg(not(target_os = "unknown"))'.dependencies] diff --git a/muxers/mplex/Cargo.toml b/muxers/mplex/Cargo.toml index 240a5ab0cd9..87813e15447 100644 --- a/muxers/mplex/Cargo.toml +++ b/muxers/mplex/Cargo.toml @@ -15,7 +15,7 @@ bytes = "1" futures = "0.3.27" asynchronous-codec = "0.6" libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } log = "0.4" nohash-hasher = "0.2" parking_lot = "0.12" diff --git a/protocols/autonat/Cargo.toml b/protocols/autonat/Cargo.toml index 8fc4f15c1f4..ef4ae6ea46a 100644 --- a/protocols/autonat/Cargo.toml +++ b/protocols/autonat/Cargo.toml @@ -18,7 +18,7 @@ instant = "0.1" libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-swarm = { version = "0.42.0", path = "../../swarm" } libp2p-request-response = { version = "0.24.0", path = "../request-response" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } log = "0.4" rand = "0.8" quick-protobuf = "0.8" diff --git a/protocols/dcutr/Cargo.toml b/protocols/dcutr/Cargo.toml index c79aac026cf..0395abae7ab 100644 --- a/protocols/dcutr/Cargo.toml +++ b/protocols/dcutr/Cargo.toml @@ -18,7 +18,7 @@ futures-timer = "3.0" instant = "0.1.11" libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-swarm = { version = "0.42.0", path = "../../swarm" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } log = "0.4" quick-protobuf = "0.8" quick-protobuf-codec = { version = "0.1", path = "../../misc/quick-protobuf-codec" } diff --git a/protocols/floodsub/Cargo.toml b/protocols/floodsub/Cargo.toml index 22a772f8259..e86bf64226a 100644 --- a/protocols/floodsub/Cargo.toml +++ b/protocols/floodsub/Cargo.toml @@ -17,7 +17,7 @@ fnv = "1.0" futures = "0.3.27" libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-swarm = { version = "0.42.0", path = "../../swarm" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } log = "0.4" quick-protobuf = "0.8" quick-protobuf-codec = { version = "0.1", path = "../../misc/quick-protobuf-codec" } diff --git a/protocols/gossipsub/Cargo.toml b/protocols/gossipsub/Cargo.toml index ef82ee553ac..8684112dbb8 100644 --- a/protocols/gossipsub/Cargo.toml +++ b/protocols/gossipsub/Cargo.toml @@ -13,7 +13,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] libp2p-swarm = { version = "0.42.0", path = "../../swarm" } libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } bytes = "1.4" byteorder = "1.3.4" fnv = "1.0.7" diff --git a/protocols/identify/Cargo.toml b/protocols/identify/Cargo.toml index a9b5eea2e6f..f6418a6c718 100644 --- a/protocols/identify/Cargo.toml +++ b/protocols/identify/Cargo.toml @@ -16,7 +16,7 @@ futures = "0.3.27" futures-timer = "3.0.2" libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-swarm = { version = "0.42.0", path = "../../swarm" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } log = "0.4.1" lru = "0.9.0" quick-protobuf-codec = { version = "0.1", path = "../../misc/quick-protobuf-codec" } diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index aa76253fe88..4332be3941c 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -21,7 +21,7 @@ log = "0.4" libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-swarm = { version = "0.42.0", path = "../../swarm" } quick-protobuf = "0.8" -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } rand = "0.8" sha2 = "0.10.0" smallvec = "1.6.1" diff --git a/protocols/mdns/Cargo.toml b/protocols/mdns/Cargo.toml index 37a2e4fc7e1..a99d8e2fc21 100644 --- a/protocols/mdns/Cargo.toml +++ b/protocols/mdns/Cargo.toml @@ -17,7 +17,7 @@ futures = "0.3.27" if-watch = "3.0.0" libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-swarm = { version = "0.42.0", path = "../../swarm" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } log = "0.4.14" rand = "0.8.3" smallvec = "1.6.1" diff --git a/protocols/perf/Cargo.toml b/protocols/perf/Cargo.toml index fb69cc03ab5..3fb068f5b26 100644 --- a/protocols/perf/Cargo.toml +++ b/protocols/perf/Cargo.toml @@ -19,7 +19,7 @@ futures = "0.3.26" instant = "0.1.11" libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-dns = { version = "0.39.0", path = "../../transports/dns", features = ["async-std"] } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } libp2p-noise = { version = "0.42.0", path = "../../transports/noise" } libp2p-quic = { version = "0.7.0-alpha.2", path = "../../transports/quic", features = ["async-std"] } libp2p-swarm = { version = "0.42.0", path = "../../swarm", features = ["macros", "async-std"] } diff --git a/protocols/ping/Cargo.toml b/protocols/ping/Cargo.toml index 7a8af417a05..69639e28a53 100644 --- a/protocols/ping/Cargo.toml +++ b/protocols/ping/Cargo.toml @@ -17,7 +17,7 @@ futures-timer = "3.0.2" instant = "0.1.11" libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-swarm = { version = "0.42.0", path = "../../swarm" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } log = "0.4.1" rand = "0.8" void = "1.0" diff --git a/protocols/relay/Cargo.toml b/protocols/relay/Cargo.toml index e7ec57233d6..944c8dc085f 100644 --- a/protocols/relay/Cargo.toml +++ b/protocols/relay/Cargo.toml @@ -19,7 +19,7 @@ futures-timer = "3" instant = "0.1.11" libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-swarm = { version = "0.42.0", path = "../../swarm", features = ["async-std"] } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } log = "0.4" quick-protobuf = "0.8" quick-protobuf-codec = { version = "0.1", path = "../../misc/quick-protobuf-codec" } diff --git a/protocols/rendezvous/Cargo.toml b/protocols/rendezvous/Cargo.toml index 1575c5dd21e..3ba3b892a32 100644 --- a/protocols/rendezvous/Cargo.toml +++ b/protocols/rendezvous/Cargo.toml @@ -18,7 +18,7 @@ futures-timer = "3.0.2" instant = "0.1.11" libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-swarm = { version = "0.42.0", path = "../../swarm" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } log = "0.4" quick-protobuf = "0.8" quick-protobuf-codec = { version = "0.1", path = "../../misc/quick-protobuf-codec" } diff --git a/protocols/request-response/Cargo.toml b/protocols/request-response/Cargo.toml index d30709e65fe..3395fa636db 100644 --- a/protocols/request-response/Cargo.toml +++ b/protocols/request-response/Cargo.toml @@ -16,7 +16,7 @@ futures = "0.3.27" instant = "0.1.11" libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-swarm = { version = "0.42.0", path = "../../swarm" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } rand = "0.8" smallvec = "1.6.1" diff --git a/swarm-test/Cargo.toml b/swarm-test/Cargo.toml index a6e41dc144a..22dfd178041 100644 --- a/swarm-test/Cargo.toml +++ b/swarm-test/Cargo.toml @@ -14,7 +14,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] async-trait = "0.1.57" libp2p-core = { version = "0.39.1", path = "../core" } -libp2p-identity = { version = "0.1.1", path = "../identity" } +libp2p-identity = { version = "0.2.0", path = "../identity" } libp2p-plaintext = { version = "0.39.1", path = "../transports/plaintext" } libp2p-swarm = { version = "0.42.0", path = "../swarm" } libp2p-tcp = { version = "0.39.0", path = "../transports/tcp", features = ["async-io"] } diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index 47ab4489407..3a5a7f759a5 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -17,7 +17,7 @@ futures = "0.3.27" futures-timer = "3.0.2" instant = "0.1.11" libp2p-core = { version = "0.39.0", path = "../core" } -libp2p-identity = { version = "0.1.0", path = "../identity" } +libp2p-identity = { version = "0.2.0", path = "../identity" } libp2p-swarm-derive = { version = "0.32.0", path = "../swarm-derive", optional = true } log = "0.4" rand = "0.8" @@ -42,7 +42,7 @@ either = "1.6.0" env_logger = "0.10" futures = "0.3.27" libp2p-identify = { path = "../protocols/identify" } -libp2p-identity = { version = "0.1.0", path = "../identity", features = ["ed25519"] } +libp2p-identity = { version = "0.2.0", path = "../identity", features = ["ed25519"] } libp2p-kad = { path = "../protocols/kad" } libp2p-ping = { path = "../protocols/ping" } libp2p-plaintext = { path = "../transports/plaintext" } diff --git a/transports/dns/Cargo.toml b/transports/dns/Cargo.toml index f3375ab4223..4c2fd8cbcaa 100644 --- a/transports/dns/Cargo.toml +++ b/transports/dns/Cargo.toml @@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } log = "0.4.1" futures = "0.3.27" async-std-resolver = { version = "0.22", optional = true } diff --git a/transports/noise/Cargo.toml b/transports/noise/Cargo.toml index c879583d566..d33a519d44b 100644 --- a/transports/noise/Cargo.toml +++ b/transports/noise/Cargo.toml @@ -13,7 +13,7 @@ bytes = "1" curve25519-dalek = "3.0.0" futures = "0.3.27" libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-identity = { version = "0.1.0", path = "../../identity", features = ["ed25519"] } +libp2p-identity = { version = "0.2.0", path = "../../identity", features = ["ed25519"] } log = "0.4" quick-protobuf = "0.8" once_cell = "1.17.1" diff --git a/transports/plaintext/Cargo.toml b/transports/plaintext/Cargo.toml index 71d94d186bd..f250c3cd8a2 100644 --- a/transports/plaintext/Cargo.toml +++ b/transports/plaintext/Cargo.toml @@ -15,7 +15,7 @@ asynchronous-codec = "0.6" bytes = "1" futures = "0.3.27" libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } log = "0.4.8" quick-protobuf = "0.8" unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] } diff --git a/transports/quic/Cargo.toml b/transports/quic/Cargo.toml index 61a623e269c..0187067581a 100644 --- a/transports/quic/Cargo.toml +++ b/transports/quic/Cargo.toml @@ -16,7 +16,7 @@ futures-timer = "3.0.2" if-watch = "3.0.0" libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-tls = { version = "0.1.0", path = "../tls" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } log = "0.4" parking_lot = "0.12.0" quinn-proto = { version = "0.9.0", default-features = false, features = ["tls-rustls"] } diff --git a/transports/tcp/Cargo.toml b/transports/tcp/Cargo.toml index c4a5ee6b4ce..ed745787768 100644 --- a/transports/tcp/Cargo.toml +++ b/transports/tcp/Cargo.toml @@ -17,7 +17,7 @@ futures-timer = "3.0" if-watch = "3.0.0" libc = "0.2.140" libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } log = "0.4.11" socket2 = { version = "0.4.0", features = ["all"] } tokio = { version = "1.19.0", default-features = false, features = ["net"], optional = true } diff --git a/transports/tls/Cargo.toml b/transports/tls/Cargo.toml index 64647c7fb51..0bf948a4124 100644 --- a/transports/tls/Cargo.toml +++ b/transports/tls/Cargo.toml @@ -12,7 +12,7 @@ exclude = ["src/test_assets"] futures = { version = "0.3.27", default-features = false } futures-rustls = "0.22.2" libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } rcgen = "0.10.0" ring = "0.16.20" thiserror = "1.0.39" diff --git a/transports/webrtc/Cargo.toml b/transports/webrtc/Cargo.toml index 6f18265cd27..aca636ad255 100644 --- a/transports/webrtc/Cargo.toml +++ b/transports/webrtc/Cargo.toml @@ -20,7 +20,7 @@ hex = "0.4" if-watch = "3.0" libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-noise = { version = "0.42.0", path = "../../transports/noise" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } log = "0.4" multihash = { version = "0.17.0", default-features = false, features = ["sha2"] } quick-protobuf = "0.8" diff --git a/transports/websocket/Cargo.toml b/transports/websocket/Cargo.toml index ab829ffdc7a..39fcf59680d 100644 --- a/transports/websocket/Cargo.toml +++ b/transports/websocket/Cargo.toml @@ -15,7 +15,7 @@ futures-rustls = "0.22" either = "1.5.3" futures = "0.3.27" libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } log = "0.4.8" parking_lot = "0.12.0" quicksink = "0.1" From bac21d28f422dfad00698c37384a10c4733260fb Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 22 Mar 2023 13:32:37 +0100 Subject: [PATCH 03/20] Upgrade to `multihash 0.18.0` --- Cargo.lock | 21 +++++++++++++++++---- identity/Cargo.toml | 2 +- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 907f5d3ff28..041d330a75b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2264,7 +2264,7 @@ dependencies = [ "libp2p-noise", "log", "multiaddr", - "multihash", + "multihash 0.17.0", "multistream-select", "once_cell", "parking_lot 0.12.1", @@ -2434,7 +2434,7 @@ dependencies = [ "ed25519-dalek", "libsecp256k1", "log", - "multihash", + "multihash 0.18.0", "p256 0.12.0", "prost", "quick-protobuf", @@ -2923,7 +2923,7 @@ dependencies = [ "libp2p-ping", "libp2p-swarm", "log", - "multihash", + "multihash 0.17.0", "quick-protobuf", "quick-protobuf-codec", "quickcheck", @@ -3166,7 +3166,7 @@ dependencies = [ "byteorder", "data-encoding", "multibase", - "multihash", + "multihash 0.17.0", "percent-encoding", "serde", "static_assertions", @@ -3203,6 +3203,19 @@ dependencies = [ "unsigned-varint", ] +[[package]] +name = "multihash" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15e5d911412e631e1de11eb313e4dd71f73fd964401102aab23d6c8327c431ba" +dependencies = [ + "core2", + "digest 0.10.6", + "multihash-derive", + "sha2 0.10.6", + "unsigned-varint", +] + [[package]] name = "multihash-derive" version = "0.8.1" diff --git a/identity/Cargo.toml b/identity/Cargo.toml index 88cdd1c3e37..34e1ff81b45 100644 --- a/identity/Cargo.toml +++ b/identity/Cargo.toml @@ -17,7 +17,7 @@ bs58 = { version = "0.4.0", optional = true } ed25519-dalek = { version = "1.0.1", optional = true } libsecp256k1 = { version = "0.7.0", optional = true } log = "0.4" -multihash = { version = "0.17.0", default-features = false, features = ["std", "multihash-impl", "identity", "sha2"], optional = true } +multihash = { version = "0.18.0", default-features = false, features = ["std", "multihash-impl", "identity", "sha2"], optional = true } p256 = { version = "0.12", default-features = false, features = ["ecdsa", "std"], optional = true } prost = { version = "0.11", optional = true } quick-protobuf = "0.8.1" From eb8dfc19f7d808cf707daaa04f2f53a92f66cd98 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 22 Mar 2023 23:46:15 +1100 Subject: [PATCH 04/20] Update identity/CHANGELOG.md --- identity/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/identity/CHANGELOG.md b/identity/CHANGELOG.md index 3dbb76dabd9..ee332316b69 100644 --- a/identity/CHANGELOG.md +++ b/identity/CHANGELOG.md @@ -2,9 +2,9 @@ - Remove `PeerId::try_from_multiaddr`. `multiaddr::Protocol::P2p` is now type-safe and contains a `PeerId` directly, rendering this function obsolete. - See [PR XXXX]. + See [PR 3656]. -[PR XXXX]: https://github.com/libp2p/rust-libp2p/pull/XXXX +[PR 3656]: https://github.com/libp2p/rust-libp2p/pull/3656 # 0.1.1 From eac13185bce93dae8c651a11e3f8a6d61be06cd7 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 6 Jun 2023 13:02:32 +0200 Subject: [PATCH 05/20] Update `libp2p-identity` to latest multihash --- Cargo.lock | 134 +++++++++++++++++++++++++++++----------- Cargo.toml | 2 +- identity/Cargo.toml | 2 +- identity/src/peer_id.rs | 18 +++--- 4 files changed, 111 insertions(+), 45 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1d37d3001b9..5d8d7e2f744 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -617,6 +617,12 @@ dependencies = [ "futures-lite", ] +[[package]] +name = "bs58" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" + [[package]] name = "bs58" version = "0.5.0" @@ -1330,6 +1336,18 @@ dependencies = [ "signature 1.6.4", ] +[[package]] +name = "ecdsa" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12844141594ad74185a926d030f3b605f6a903b4e3fec351f3ea338ac5b7637e" +dependencies = [ + "der 0.6.1", + "elliptic-curve 0.12.3", + "rfc6979 0.3.1", + "signature 2.0.0", +] + [[package]] name = "ecdsa" version = "0.16.6" @@ -2256,7 +2274,7 @@ dependencies = [ "base64 0.21.2", "clap", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "serde", "serde_json", "zeroize", @@ -2313,7 +2331,7 @@ dependencies = [ "libp2p-floodsub", "libp2p-gossipsub", "libp2p-identify", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-kad", "libp2p-mdns", "libp2p-metrics", @@ -2344,7 +2362,7 @@ version = "0.2.0" dependencies = [ "async-std", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-swarm", "libp2p-swarm-derive", "libp2p-swarm-test", @@ -2362,7 +2380,7 @@ dependencies = [ "futures-timer", "instant", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-request-response", "libp2p-swarm", "libp2p-swarm-test", @@ -2378,7 +2396,7 @@ dependencies = [ "async-std", "libp2p-core", "libp2p-identify", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-ping", "libp2p-swarm", "libp2p-swarm-derive", @@ -2398,7 +2416,7 @@ dependencies = [ "futures", "futures-timer", "instant", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-mplex", "libp2p-noise", "log", @@ -2434,7 +2452,7 @@ dependencies = [ "libp2p-core", "libp2p-dns", "libp2p-identify", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-noise", "libp2p-ping", "libp2p-plaintext", @@ -2474,7 +2492,7 @@ dependencies = [ "env_logger 0.10.0", "futures", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "log", "parking_lot", "smallvec", @@ -2491,7 +2509,7 @@ dependencies = [ "fnv", "futures", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-swarm", "log", "quick-protobuf", @@ -2520,7 +2538,7 @@ dependencies = [ "hex_fmt", "instant", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-noise", "libp2p-swarm", "libp2p-swarm-test", @@ -2550,7 +2568,7 @@ dependencies = [ "futures", "futures-timer", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-swarm", "libp2p-swarm-test", "log", @@ -2562,13 +2580,38 @@ dependencies = [ "void", ] +[[package]] +name = "libp2p-identity" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e2d584751cecb2aabaa56106be6be91338a60a0f4e420cf2af639204f596fc1" +dependencies = [ + "asn1_der", + "bs58 0.4.0", + "ed25519-dalek", + "libsecp256k1", + "log", + "multiaddr", + "multihash 0.17.0", + "p256 0.12.0", + "quick-protobuf", + "rand 0.8.5", + "ring", + "sec1 0.3.0", + "serde", + "sha2 0.10.6", + "thiserror", + "void", + "zeroize", +] + [[package]] name = "libp2p-identity" version = "0.2.0" dependencies = [ "asn1_der", "base64 0.21.2", - "bs58", + "bs58 0.5.0", "criterion", "ed25519-dalek", "hex-literal", @@ -2606,7 +2649,7 @@ dependencies = [ "instant", "libp2p-core", "libp2p-identify", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-noise", "libp2p-swarm", "libp2p-swarm-test", @@ -2635,7 +2678,7 @@ dependencies = [ "futures", "if-watch", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-noise", "libp2p-swarm", "libp2p-swarm-test", @@ -2659,7 +2702,7 @@ dependencies = [ "libp2p-dcutr", "libp2p-gossipsub", "libp2p-identify", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-kad", "libp2p-ping", "libp2p-relay", @@ -2679,7 +2722,7 @@ dependencies = [ "env_logger 0.10.0", "futures", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-muxer-test-harness", "libp2p-plaintext", "libp2p-tcp", @@ -2713,7 +2756,7 @@ dependencies = [ "futures", "futures_ringbuf", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "log", "once_cell", "quick-protobuf", @@ -2739,7 +2782,7 @@ dependencies = [ "instant", "libp2p-core", "libp2p-dns", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-quic", "libp2p-request-response", "libp2p-swarm", @@ -2767,7 +2810,7 @@ dependencies = [ "futures-timer", "instant", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-swarm", "libp2p-swarm-test", "log", @@ -2786,7 +2829,7 @@ dependencies = [ "futures", "futures_ringbuf", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "log", "quick-protobuf", "quickcheck-ext", @@ -2800,7 +2843,7 @@ version = "0.23.0" dependencies = [ "futures", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-noise", "libp2p-swarm", "libp2p-tcp", @@ -2826,7 +2869,7 @@ dependencies = [ "futures-timer", "if-watch", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-muxer-test-harness", "libp2p-noise", "libp2p-tcp", @@ -2854,7 +2897,7 @@ dependencies = [ "futures-timer", "instant", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-ping", "libp2p-plaintext", "libp2p-swarm", @@ -2882,7 +2925,7 @@ dependencies = [ "instant", "libp2p-core", "libp2p-identify", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-noise", "libp2p-ping", "libp2p-swarm", @@ -2909,7 +2952,7 @@ dependencies = [ "futures_ringbuf", "instant", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-noise", "libp2p-swarm", "libp2p-swarm-test", @@ -2938,7 +2981,7 @@ dependencies = [ "instant", "libp2p-core", "libp2p-identify", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-kad", "libp2p-ping", "libp2p-plaintext", @@ -2976,7 +3019,7 @@ dependencies = [ "futures", "futures-timer", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-plaintext", "libp2p-swarm", "libp2p-tcp", @@ -2997,7 +3040,7 @@ dependencies = [ "if-watch", "libc", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "log", "socket2 0.5.3", "tokio", @@ -3012,7 +3055,7 @@ dependencies = [ "hex", "hex-literal", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-swarm", "libp2p-yamux", "rcgen 0.10.0", @@ -3064,7 +3107,7 @@ dependencies = [ "hex-literal", "if-watch", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-noise", "libp2p-ping", "libp2p-swarm", @@ -3097,7 +3140,7 @@ dependencies = [ "futures-rustls 0.22.2", "libp2p-core", "libp2p-dns", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-tcp", "log", "parking_lot", @@ -3353,11 +3396,9 @@ dependencies = [ [[package]] name = "multihash" version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15e5d911412e631e1de11eb313e4dd71f73fd964401102aab23d6c8327c431ba" +source = "git+https://github.com/multiformats/rust-multihash#a5e3a5cbeba0bedbeff738cdc93d64aa3c4569f6" dependencies = [ "core2", - "multihash-derive", "unsigned-varint", ] @@ -3385,7 +3426,7 @@ dependencies = [ "futures", "futures_ringbuf", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-plaintext", "libp2p-swarm", "libp2p-yamux", @@ -3580,6 +3621,18 @@ dependencies = [ "sha2 0.10.6", ] +[[package]] +name = "p256" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49c124b3cbce43bcbac68c58ec181d98ed6cc7e6d0aa7c3ba97b2563410b0e55" +dependencies = [ + "ecdsa 0.15.1", + "elliptic-curve 0.12.3", + "primeorder 0.12.1", + "sha2 0.10.6", +] + [[package]] name = "p256" version = "0.13.2" @@ -3588,7 +3641,7 @@ checksum = "c9863ad85fa8f4460f9c48cb909d38a0d689dba1f6f6988a5e3e0d31071bcd4b" dependencies = [ "ecdsa 0.16.6", "elliptic-curve 0.13.4", - "primeorder", + "primeorder 0.13.1", "sha2 0.10.6", ] @@ -3844,6 +3897,15 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "primeorder" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b54f7131b3dba65a2f414cf5bd25b66d4682e4608610668eae785750ba4c5b2" +dependencies = [ + "elliptic-curve 0.12.3", +] + [[package]] name = "primeorder" version = "0.13.1" diff --git a/Cargo.toml b/Cargo.toml index 8400238368d..98e5e264421 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -70,7 +70,7 @@ libp2p-dns = { version = "0.40.0", path = "transports/dns" } libp2p-floodsub = { version = "0.43.0", path = "protocols/floodsub" } libp2p-gossipsub = { version = "0.45.0", path = "protocols/gossipsub" } libp2p-identify = { version = "0.43.0", path = "protocols/identify" } -libp2p-identity = { version = "0.2.0", path = "identity" } +libp2p-identity = { version = "0.1.0" } libp2p-kad = { version = "0.44.0", path = "protocols/kad" } libp2p-mdns = { version = "0.44.0", path = "protocols/mdns" } libp2p-metrics = { version = "0.13.0", path = "misc/metrics" } diff --git a/identity/Cargo.toml b/identity/Cargo.toml index 8f22a144703..1495551f5e5 100644 --- a/identity/Cargo.toml +++ b/identity/Cargo.toml @@ -17,7 +17,7 @@ bs58 = { version = "0.5.0", optional = true } ed25519-dalek = { version = "1.0.1", optional = true } libsecp256k1 = { version = "0.7.0", optional = true } log = "0.4" -multihash = { version = "0.18.0", default-features = false, features = ["std"], optional = true } +multihash = { git = "https://github.com/multiformats/rust-multihash", optional = true } p256 = { version = "0.13", default-features = false, features = ["ecdsa", "std", "pem"], optional = true } quick-protobuf = "0.8.1" rand = { version = "0.8", optional = true } diff --git a/identity/src/peer_id.rs b/identity/src/peer_id.rs index af2f915dc2c..30b2cb76cc6 100644 --- a/identity/src/peer_id.rs +++ b/identity/src/peer_id.rs @@ -18,7 +18,6 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use multihash::{Error, MultihashGeneric}; use rand::Rng; use sha2::Digest as _; use std::{convert::TryFrom, fmt, str::FromStr}; @@ -29,7 +28,7 @@ use thiserror::Error; /// Must be big enough to accommodate for `MAX_INLINE_KEY_LENGTH`. /// 64 satisfies that and can hold 512 bit hashes which is what the ecosystem typically uses. /// Given that this appears in our type-signature, using a "common" number here makes us more compatible. -type Multihash = MultihashGeneric<64>; +type Multihash = multihash::Multihash<64>; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -79,9 +78,9 @@ impl PeerId { } /// Parses a `PeerId` from bytes. - pub fn from_bytes(data: &[u8]) -> Result { + pub fn from_bytes(data: &[u8]) -> Result { PeerId::from_multihash(Multihash::from_bytes(data)?) - .map_err(|mh| Error::UnsupportedCode(mh.code())) + .map_err(|mh| ParseError::UnsupportedCode(mh.code())) } /// Tries to turn a `Multihash` into a `PeerId`. @@ -234,12 +233,15 @@ impl<'de> Deserialize<'de> for PeerId { } } +/// Error when parsing a [`PeerId`] from string or bytes. #[derive(Debug, Error)] pub enum ParseError { #[error("base-58 decode error: {0}")] B58(#[from] bs58::decode::Error), - #[error("decoding multihash failed")] - MultiHash, + #[error("unsupported multihash code '{0}'")] + UnsupportedCode(u64), + #[error("invalid multihash")] + InvalidMultihash(#[from] multihash::Error), } impl FromStr for PeerId { @@ -248,7 +250,9 @@ 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) + let peer_id = PeerId::from_bytes(&bytes)?; + + Ok(peer_id) } } From 58478259acc4bc4055aee30830629fb8573bc039 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 6 Jun 2023 13:23:52 +0200 Subject: [PATCH 06/20] Upgrade to typesafe PeerId in multiaddr --- Cargo.lock | 192 +++++++----------- Cargo.toml | 4 +- core/Cargo.toml | 6 +- core/src/peer_record.rs | 2 +- .../distributed-key-value-store/Cargo.toml | 2 +- examples/file-sharing/Cargo.toml | 2 +- examples/ipfs-private/Cargo.toml | 2 +- examples/ping-example/Cargo.toml | 2 +- swarm/src/dial_opts.rs | 51 ++--- swarm/src/lib.rs | 26 +-- transports/plaintext/src/error.rs | 6 +- transports/quic/tests/smoke.rs | 2 +- transports/tcp/src/lib.rs | 2 +- transports/webrtc/Cargo.toml | 2 +- transports/webrtc/src/tokio/fingerprint.rs | 3 +- transports/webrtc/src/tokio/transport.rs | 6 +- transports/websocket/src/lib.rs | 2 +- 17 files changed, 120 insertions(+), 192 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5d8d7e2f744..496247178b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -617,12 +617,6 @@ dependencies = [ "futures-lite", ] -[[package]] -name = "bs58" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" - [[package]] name = "bs58" version = "0.5.0" @@ -1315,7 +1309,7 @@ dependencies = [ "env_logger 0.10.0", "futures", "libp2p", - "multiaddr", + "multiaddr 0.18.0", ] [[package]] @@ -1336,18 +1330,6 @@ dependencies = [ "signature 1.6.4", ] -[[package]] -name = "ecdsa" -version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12844141594ad74185a926d030f3b605f6a903b4e3fec351f3ea338ac5b7637e" -dependencies = [ - "der 0.6.1", - "elliptic-curve 0.12.3", - "rfc6979 0.3.1", - "signature 2.0.0", -] - [[package]] name = "ecdsa" version = "0.16.6" @@ -1540,7 +1522,7 @@ dependencies = [ "env_logger 0.10.0", "futures", "libp2p", - "multiaddr", + "multiaddr 0.18.0", "void", ] @@ -2213,7 +2195,7 @@ dependencies = [ "env_logger 0.10.0", "futures", "libp2p", - "multiaddr", + "multiaddr 0.18.0", ] [[package]] @@ -2274,7 +2256,7 @@ dependencies = [ "base64 0.21.2", "clap", "libp2p-core", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "serde", "serde_json", "zeroize", @@ -2331,7 +2313,7 @@ dependencies = [ "libp2p-floodsub", "libp2p-gossipsub", "libp2p-identify", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "libp2p-kad", "libp2p-mdns", "libp2p-metrics", @@ -2351,7 +2333,7 @@ dependencies = [ "libp2p-webrtc", "libp2p-websocket", "libp2p-yamux", - "multiaddr", + "multiaddr 0.17.1", "pin-project", "tokio", ] @@ -2362,7 +2344,7 @@ version = "0.2.0" dependencies = [ "async-std", "libp2p-core", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "libp2p-swarm", "libp2p-swarm-derive", "libp2p-swarm-test", @@ -2380,7 +2362,7 @@ dependencies = [ "futures-timer", "instant", "libp2p-core", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "libp2p-request-response", "libp2p-swarm", "libp2p-swarm-test", @@ -2396,7 +2378,7 @@ dependencies = [ "async-std", "libp2p-core", "libp2p-identify", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "libp2p-ping", "libp2p-swarm", "libp2p-swarm-derive", @@ -2416,12 +2398,12 @@ dependencies = [ "futures", "futures-timer", "instant", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "libp2p-mplex", "libp2p-noise", "log", - "multiaddr", - "multihash 0.17.0", + "multiaddr 0.18.0", + "multihash 0.18.0", "multistream-select", "once_cell", "parking_lot", @@ -2452,7 +2434,7 @@ dependencies = [ "libp2p-core", "libp2p-dns", "libp2p-identify", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "libp2p-noise", "libp2p-ping", "libp2p-plaintext", @@ -2492,7 +2474,7 @@ dependencies = [ "env_logger 0.10.0", "futures", "libp2p-core", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "log", "parking_lot", "smallvec", @@ -2509,7 +2491,7 @@ dependencies = [ "fnv", "futures", "libp2p-core", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "libp2p-swarm", "log", "quick-protobuf", @@ -2538,7 +2520,7 @@ dependencies = [ "hex_fmt", "instant", "libp2p-core", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "libp2p-noise", "libp2p-swarm", "libp2p-swarm-test", @@ -2568,7 +2550,7 @@ dependencies = [ "futures", "futures-timer", "libp2p-core", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "libp2p-swarm", "libp2p-swarm-test", "log", @@ -2582,23 +2564,26 @@ dependencies = [ [[package]] name = "libp2p-identity" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e2d584751cecb2aabaa56106be6be91338a60a0f4e420cf2af639204f596fc1" +version = "0.2.0" dependencies = [ "asn1_der", - "bs58 0.4.0", + "base64 0.21.2", + "bs58", + "criterion", "ed25519-dalek", + "hex-literal", "libsecp256k1", "log", - "multiaddr", - "multihash 0.17.0", - "p256 0.12.0", + "multihash 0.18.0", + "p256 0.13.2", "quick-protobuf", + "quickcheck-ext", "rand 0.8.5", "ring", - "sec1 0.3.0", + "rmp-serde", + "sec1 0.7.1", "serde", + "serde_json", "sha2 0.10.6", "thiserror", "void", @@ -2608,29 +2593,15 @@ dependencies = [ [[package]] name = "libp2p-identity" version = "0.2.0" +source = "git+https://github.com/libp2p/rust-libp2p?branch=libp2p-identity-no-multiaddr#eac13185bce93dae8c651a11e3f8a6d61be06cd7" dependencies = [ - "asn1_der", - "base64 0.21.2", - "bs58 0.5.0", - "criterion", - "ed25519-dalek", - "hex-literal", - "libsecp256k1", + "bs58", "log", "multihash 0.18.0", - "p256 0.13.2", "quick-protobuf", - "quickcheck-ext", "rand 0.8.5", - "ring", - "rmp-serde", - "sec1 0.7.1", - "serde", - "serde_json", "sha2 0.10.6", "thiserror", - "void", - "zeroize", ] [[package]] @@ -2649,7 +2620,7 @@ dependencies = [ "instant", "libp2p-core", "libp2p-identify", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "libp2p-noise", "libp2p-swarm", "libp2p-swarm-test", @@ -2678,7 +2649,7 @@ dependencies = [ "futures", "if-watch", "libp2p-core", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "libp2p-noise", "libp2p-swarm", "libp2p-swarm-test", @@ -2702,7 +2673,7 @@ dependencies = [ "libp2p-dcutr", "libp2p-gossipsub", "libp2p-identify", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "libp2p-kad", "libp2p-ping", "libp2p-relay", @@ -2722,7 +2693,7 @@ dependencies = [ "env_logger 0.10.0", "futures", "libp2p-core", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "libp2p-muxer-test-harness", "libp2p-plaintext", "libp2p-tcp", @@ -2756,7 +2727,7 @@ dependencies = [ "futures", "futures_ringbuf", "libp2p-core", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "log", "once_cell", "quick-protobuf", @@ -2782,7 +2753,7 @@ dependencies = [ "instant", "libp2p-core", "libp2p-dns", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "libp2p-quic", "libp2p-request-response", "libp2p-swarm", @@ -2810,7 +2781,7 @@ dependencies = [ "futures-timer", "instant", "libp2p-core", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "libp2p-swarm", "libp2p-swarm-test", "log", @@ -2829,7 +2800,7 @@ dependencies = [ "futures", "futures_ringbuf", "libp2p-core", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "log", "quick-protobuf", "quickcheck-ext", @@ -2843,7 +2814,7 @@ version = "0.23.0" dependencies = [ "futures", "libp2p-core", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "libp2p-noise", "libp2p-swarm", "libp2p-tcp", @@ -2869,7 +2840,7 @@ dependencies = [ "futures-timer", "if-watch", "libp2p-core", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "libp2p-muxer-test-harness", "libp2p-noise", "libp2p-tcp", @@ -2897,7 +2868,7 @@ dependencies = [ "futures-timer", "instant", "libp2p-core", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "libp2p-ping", "libp2p-plaintext", "libp2p-swarm", @@ -2925,7 +2896,7 @@ dependencies = [ "instant", "libp2p-core", "libp2p-identify", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "libp2p-noise", "libp2p-ping", "libp2p-swarm", @@ -2952,7 +2923,7 @@ dependencies = [ "futures_ringbuf", "instant", "libp2p-core", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "libp2p-noise", "libp2p-swarm", "libp2p-swarm-test", @@ -2981,7 +2952,7 @@ dependencies = [ "instant", "libp2p-core", "libp2p-identify", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "libp2p-kad", "libp2p-ping", "libp2p-plaintext", @@ -3019,7 +2990,7 @@ dependencies = [ "futures", "futures-timer", "libp2p-core", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "libp2p-plaintext", "libp2p-swarm", "libp2p-tcp", @@ -3040,7 +3011,7 @@ dependencies = [ "if-watch", "libc", "libp2p-core", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "log", "socket2 0.5.3", "tokio", @@ -3055,7 +3026,7 @@ dependencies = [ "hex", "hex-literal", "libp2p-core", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "libp2p-swarm", "libp2p-yamux", "rcgen 0.10.0", @@ -3107,12 +3078,12 @@ dependencies = [ "hex-literal", "if-watch", "libp2p-core", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "libp2p-noise", "libp2p-ping", "libp2p-swarm", "log", - "multihash 0.17.0", + "multihash 0.18.0", "quick-protobuf", "quick-protobuf-codec", "quickcheck", @@ -3140,7 +3111,7 @@ dependencies = [ "futures-rustls 0.22.2", "libp2p-core", "libp2p-dns", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "libp2p-tcp", "log", "parking_lot", @@ -3366,6 +3337,24 @@ dependencies = [ "url", ] +[[package]] +name = "multiaddr" +version = "0.18.0" +source = "git+https://github.com/thomaseizinger/rust-multiaddr?branch=typesafe-p2p#0e455ce32e829150ac2be196b0fed78019b19142" +dependencies = [ + "arrayref", + "byteorder", + "data-encoding", + "libp2p-identity 0.2.0 (git+https://github.com/libp2p/rust-libp2p?branch=libp2p-identity-no-multiaddr)", + "multibase", + "multihash 0.18.0", + "percent-encoding", + "serde", + "static_assertions", + "unsigned-varint", + "url", +] + [[package]] name = "multibase" version = "0.9.1" @@ -3383,13 +3372,8 @@ version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "835d6ff01d610179fbce3de1694d007e500bf33a7f29689838941d6bf783ae40" dependencies = [ - "arbitrary", "core2", "multihash-derive", - "quickcheck", - "rand 0.8.5", - "serde", - "serde-big-array", "unsigned-varint", ] @@ -3398,7 +3382,11 @@ name = "multihash" version = "0.18.0" source = "git+https://github.com/multiformats/rust-multihash#a5e3a5cbeba0bedbeff738cdc93d64aa3c4569f6" dependencies = [ + "arbitrary", "core2", + "quickcheck", + "rand 0.8.5", + "serde", "unsigned-varint", ] @@ -3426,7 +3414,7 @@ dependencies = [ "futures", "futures_ringbuf", "libp2p-core", - "libp2p-identity 0.1.2", + "libp2p-identity 0.2.0", "libp2p-plaintext", "libp2p-swarm", "libp2p-yamux", @@ -3621,18 +3609,6 @@ dependencies = [ "sha2 0.10.6", ] -[[package]] -name = "p256" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49c124b3cbce43bcbac68c58ec181d98ed6cc7e6d0aa7c3ba97b2563410b0e55" -dependencies = [ - "ecdsa 0.15.1", - "elliptic-curve 0.12.3", - "primeorder 0.12.1", - "sha2 0.10.6", -] - [[package]] name = "p256" version = "0.13.2" @@ -3641,7 +3617,7 @@ checksum = "c9863ad85fa8f4460f9c48cb909d38a0d689dba1f6f6988a5e3e0d31071bcd4b" dependencies = [ "ecdsa 0.16.6", "elliptic-curve 0.13.4", - "primeorder 0.13.1", + "primeorder", "sha2 0.10.6", ] @@ -3786,7 +3762,7 @@ dependencies = [ "async-trait", "futures", "libp2p", - "multiaddr", + "multiaddr 0.18.0", ] [[package]] @@ -3897,15 +3873,6 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" -[[package]] -name = "primeorder" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b54f7131b3dba65a2f414cf5bd25b66d4682e4608610668eae785750ba4c5b2" -dependencies = [ - "elliptic-curve 0.12.3", -] - [[package]] name = "primeorder" version = "0.13.1" @@ -4604,15 +4571,6 @@ dependencies = [ "serde_derive", ] -[[package]] -name = "serde-big-array" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd31f59f6fe2b0c055371bb2f16d7f0aa7d8881676c04a55b1596d1a17cd10a4" -dependencies = [ - "serde", -] - [[package]] name = "serde_cbor" version = "0.11.2" diff --git a/Cargo.toml b/Cargo.toml index 98e5e264421..2c7d13313b7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -70,7 +70,7 @@ libp2p-dns = { version = "0.40.0", path = "transports/dns" } libp2p-floodsub = { version = "0.43.0", path = "protocols/floodsub" } libp2p-gossipsub = { version = "0.45.0", path = "protocols/gossipsub" } libp2p-identify = { version = "0.43.0", path = "protocols/identify" } -libp2p-identity = { version = "0.1.0" } +libp2p-identity = { version = "0.2.0", path = "identity" } libp2p-kad = { version = "0.44.0", path = "protocols/kad" } libp2p-mdns = { version = "0.44.0", path = "protocols/mdns" } libp2p-metrics = { version = "0.13.0", path = "misc/metrics" } @@ -99,3 +99,5 @@ multistream-select = { version = "0.13.0", path = "misc/multistream-select" } quick-protobuf-codec = { version = "0.2.0", path = "misc/quick-protobuf-codec" } quickcheck = { package = "quickcheck-ext", path = "misc/quickcheck-ext" } rw-stream-sink = { version = "0.4.0", path = "misc/rw-stream-sink" } +multiaddr = { git = "https://github.com/thomaseizinger/rust-multiaddr", branch = "typesafe-p2p" } +multihash = { git = "https://github.com/multiformats/rust-multihash" } diff --git a/core/Cargo.toml b/core/Cargo.toml index 626529779df..e4a458babe2 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -18,8 +18,8 @@ futures-timer = "3" instant = "0.1.12" libp2p-identity = { workspace = true, features = ["peerid", "ed25519"] } log = "0.4" -multiaddr = { version = "0.17.1" } -multihash = { version = "0.17.0", default-features = false, features = ["std"] } +multiaddr = { workspace = true } +multihash = { workspace = true , features = ["std"] } multistream-select = { workspace = true } once_cell = "1.18.0" parking_lot = "0.12.0" @@ -37,7 +37,7 @@ void = "1" async-std = { version = "1.6.2", features = ["attributes"] } libp2p-mplex = { workspace = true } libp2p-noise = { workspace = true } -multihash = { version = "0.17.0", default-features = false, features = ["arb"] } +multihash = { workspace = true , features = ["arb"] } quickcheck = { workspace = true } [features] diff --git a/core/src/peer_record.rs b/core/src/peer_record.rs index a73168a30f1..2fd6a39ef2b 100644 --- a/core/src/peer_record.rs +++ b/core/src/peer_record.rs @@ -138,7 +138,7 @@ pub enum FromEnvelopeError { InvalidPeerRecord(#[from] DecodeError), /// Failed to decode the peer ID. #[error("Failed to decode bytes as PeerId")] - InvalidPeerId(#[from] multihash::Error), + InvalidPeerId(#[from] libp2p_identity::ParseError), /// The signer of the envelope is different than the peer id in the record. #[error("The signer of the envelope is different than the peer id in the record")] MismatchedSignature, diff --git a/examples/distributed-key-value-store/Cargo.toml b/examples/distributed-key-value-store/Cargo.toml index 8d9681e52d2..23e3635db96 100644 --- a/examples/distributed-key-value-store/Cargo.toml +++ b/examples/distributed-key-value-store/Cargo.toml @@ -11,4 +11,4 @@ async-trait = "0.1" env_logger = "0.10" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "dns", "kad", "mdns", "noise", "macros", "tcp", "websocket", "yamux"] } -multiaddr = { version = "0.17.1" } +multiaddr = { workspace = true } diff --git a/examples/file-sharing/Cargo.toml b/examples/file-sharing/Cargo.toml index 3bec5e1dc55..23c8bc4ae5f 100644 --- a/examples/file-sharing/Cargo.toml +++ b/examples/file-sharing/Cargo.toml @@ -13,5 +13,5 @@ either = "1.8" env_logger = "0.10" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "dns", "kad", "noise", "macros", "request-response", "tcp", "websocket", "yamux"] } -multiaddr = { version = "0.17.1" } +multiaddr = { workspace = true } void = "1.0.2" diff --git a/examples/ipfs-private/Cargo.toml b/examples/ipfs-private/Cargo.toml index 5271f71c5bf..c778f1b6ebb 100644 --- a/examples/ipfs-private/Cargo.toml +++ b/examples/ipfs-private/Cargo.toml @@ -12,4 +12,4 @@ either = "1.8" env_logger = "0.10" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "gossipsub", "dns", "identify", "kad", "macros", "noise", "ping", "pnet", "tcp", "websocket", "yamux"] } -multiaddr = { version = "0.17.1" } \ No newline at end of file +multiaddr = { workspace = true } diff --git a/examples/ping-example/Cargo.toml b/examples/ping-example/Cargo.toml index db612b556f7..7a2d34ff22b 100644 --- a/examples/ping-example/Cargo.toml +++ b/examples/ping-example/Cargo.toml @@ -10,4 +10,4 @@ async-std = { version = "1.12", features = ["attributes"] } async-trait = "0.1" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "dns", "macros", "noise", "ping", "tcp", "websocket", "yamux"] } -multiaddr = { version = "0.17.1" } \ No newline at end of file +multiaddr = { workspace = true } diff --git a/swarm/src/dial_opts.rs b/swarm/src/dial_opts.rs index dc3d94cb83b..9be7280b3df 100644 --- a/swarm/src/dial_opts.rs +++ b/swarm/src/dial_opts.rs @@ -22,7 +22,6 @@ use crate::ConnectionId; use libp2p_core::connection::Endpoint; use libp2p_core::multiaddr::Protocol; -use libp2p_core::multihash::Multihash; use libp2p_core::Multiaddr; use libp2p_identity::PeerId; use std::num::NonZeroU8; @@ -81,9 +80,21 @@ impl DialOpts { WithoutPeerId {} } - /// Get the [`PeerId`] specified in a [`DialOpts`] if any. + /// Retrieves the [`PeerId`] from the [`DialOpts`] if specified or otherwise tries to extract it + /// from the multihash in the `/p2p` part of the address, if present. pub fn get_peer_id(&self) -> Option { - self.peer_id + if let Some(peer_id) = self.peer_id { + return Some(peer_id); + } + + let first_address = self.addresses.first()?; + let last_protocol = first_address.iter().last()?; + + if let Protocol::P2p(p) = last_protocol { + return Some(p); + } + + None } /// Get the [`ConnectionId`] of this dial attempt. @@ -94,40 +105,6 @@ impl DialOpts { self.connection_id } - /// Retrieves the [`PeerId`] from the [`DialOpts`] if specified or otherwise tries to parse it - /// from the multihash in the `/p2p` part of the address, if present. - /// - /// Note: A [`Multiaddr`] with something else other than a [`PeerId`] within the `/p2p` protocol is invalid as per specification. - /// Unfortunately, we are not making good use of the type system here. - /// Really, this function should be merged with [`DialOpts::get_peer_id`] above. - /// If it weren't for the parsing error, the function signatures would be the same. - /// - /// See . - pub(crate) fn get_or_parse_peer_id(&self) -> Result, Multihash> { - if let Some(peer_id) = self.peer_id { - return Ok(Some(peer_id)); - } - - let first_address = match self.addresses.first() { - Some(first_address) => first_address, - None => return Ok(None), - }; - - let maybe_peer_id = first_address - .iter() - .last() - .and_then(|p| { - if let Protocol::P2p(ma) = p { - Some(PeerId::try_from(ma)) - } else { - None - } - }) - .transpose()?; - - Ok(maybe_peer_id) - } - pub(crate) fn get_addresses(&self) -> Vec { self.addresses.clone() } diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index ff54ae58000..a1d466d15c7 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -136,7 +136,6 @@ use futures::{prelude::*, stream::FusedStream}; use libp2p_core::{ connection::ConnectedPoint, multiaddr, - multihash::Multihash, muxing::StreamMuxerBox, transport::{self, ListenerId, TransportError, TransportEvent}, Endpoint, Multiaddr, Transport, @@ -414,9 +413,7 @@ where pub fn dial(&mut self, opts: impl Into) -> Result<(), DialError> { let dial_opts = opts.into(); - let peer_id = dial_opts - .get_or_parse_peer_id() - .map_err(DialError::InvalidPeerId)?; + let peer_id = dial_opts.get_peer_id(); let condition = dial_opts.peer_condition(); let connection_id = dial_opts.connection_id(); @@ -1007,11 +1004,11 @@ where match event { ToSwarm::GenerateEvent(event) => return Some(SwarmEvent::Behaviour(event)), ToSwarm::Dial { opts } => { - let peer_id = opts.get_or_parse_peer_id(); + let peer_id = opts.get_peer_id(); let connection_id = opts.connection_id(); if let Ok(()) = self.dial(opts) { return Some(SwarmEvent::Dialing { - peer_id: peer_id.ok().flatten(), + peer_id, connection_id, }); } @@ -1518,8 +1515,6 @@ pub enum DialError { DialPeerConditionFalse(dial_opts::PeerCondition), /// Pending connection attempt has been aborted. Aborted, - /// The provided peer identity is invalid. - InvalidPeerId(Multihash), /// The peer identity obtained on the connection did not match the one that was expected. WrongPeerId { obtained: PeerId, @@ -1560,9 +1555,6 @@ impl fmt::Display for DialError { f, "Dial error: Pending connection attempt has been aborted." ), - DialError::InvalidPeerId(multihash) => { - write!(f, "Dial error: multihash {multihash:?} is not a PeerId") - } DialError::WrongPeerId { obtained, endpoint } => write!( f, "Dial error: Unexpected peer ID {obtained} at {endpoint:?}." @@ -1603,7 +1595,6 @@ impl error::Error for DialError { DialError::NoAddresses => None, DialError::DialPeerConditionFalse(_) => None, DialError::Aborted => None, - DialError::InvalidPeerId { .. } => None, DialError::WrongPeerId { .. } => None, DialError::Transport(_) => None, DialError::Denied { cause } => Some(cause), @@ -1762,14 +1753,15 @@ fn p2p_addr(peer: Option, addr: Multiaddr) -> Result return Ok(addr), }; - if let Some(multiaddr::Protocol::P2p(hash)) = addr.iter().last() { - if &hash != peer.as_ref() { + if let Some(multiaddr::Protocol::P2p(peer_id)) = addr.iter().last() { + if peer_id != peer { return Err(addr); } - Ok(addr) - } else { - Ok(addr.with(multiaddr::Protocol::P2p(peer.into()))) + + return Ok(addr); } + + Ok(addr.with(multiaddr::Protocol::P2p(peer))) } #[cfg(test)] diff --git a/transports/plaintext/src/error.rs b/transports/plaintext/src/error.rs index 2daac496f12..a47eb5fc6d2 100644 --- a/transports/plaintext/src/error.rs +++ b/transports/plaintext/src/error.rs @@ -34,7 +34,7 @@ pub enum PlainTextError { InvalidPublicKey(libp2p_core::identity::error::DecodingError), /// Failed to parse the [`PeerId`](libp2p_core::PeerId) from bytes in the protobuf message. - InvalidPeerId(libp2p_core::multihash::Error), + InvalidPeerId(libp2p_identity::ParseError), /// The peer id of the exchange isn't consistent with the remote public key. PeerIdMismatch, @@ -99,8 +99,8 @@ impl From for PlainTextError { } } -impl From for PlainTextError { - fn from(err: libp2p_core::multihash::Error) -> PlainTextError { +impl From for PlainTextError { + fn from(err: libp2p_identity::ParseError) -> PlainTextError { PlainTextError::InvalidPeerId(err) } } diff --git a/transports/quic/tests/smoke.rs b/transports/quic/tests/smoke.rs index 93bb78e2ae8..8a6d689a7b0 100644 --- a/transports/quic/tests/smoke.rs +++ b/transports/quic/tests/smoke.rs @@ -215,7 +215,7 @@ async fn wrong_peerid() { let (b_peer_id, mut b_transport) = create_default_transport::(); let a_addr = start_listening(&mut a_transport, "/ip6/::1/udp/0/quic-v1").await; - let a_addr_random_peer = a_addr.with(Protocol::P2p(PeerId::random().into())); + let a_addr_random_peer = a_addr.with(Protocol::P2p(PeerId::random())); let ((a_connected, _, _), (b_connected, _)) = connect(&mut a_transport, &mut b_transport, a_addr_random_peer).await; diff --git a/transports/tcp/src/lib.rs b/transports/tcp/src/lib.rs index bf53706b75d..b1737cf7bed 100644 --- a/transports/tcp/src/lib.rs +++ b/transports/tcp/src/lib.rs @@ -1280,7 +1280,7 @@ mod tests { let tcp_observed_addr = Multiaddr::empty() .with(Protocol::Ip4(observed_ip)) .with(Protocol::Tcp(1)) - .with(Protocol::P2p(PeerId::random().into())); + .with(Protocol::P2p(PeerId::random())); let translated = transport .address_translation(&tcp_listen_addr, &tcp_observed_addr) diff --git a/transports/webrtc/Cargo.toml b/transports/webrtc/Cargo.toml index 1019a49678f..e4e24b42b42 100644 --- a/transports/webrtc/Cargo.toml +++ b/transports/webrtc/Cargo.toml @@ -23,7 +23,7 @@ libp2p-noise = { workspace = true } libp2p-identity = { workspace = true } log = "0.4" sha2 = "0.10.6" -multihash = { version = "0.17.0", default-features = false } +multihash = { workspace = true } quick-protobuf = "0.8" quick-protobuf-codec = { workspace = true } rand = "0.8" diff --git a/transports/webrtc/src/tokio/fingerprint.rs b/transports/webrtc/src/tokio/fingerprint.rs index 3776f0dc24e..3eb28645907 100644 --- a/transports/webrtc/src/tokio/fingerprint.rs +++ b/transports/webrtc/src/tokio/fingerprint.rs @@ -18,7 +18,6 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use multihash::MultihashGeneric; use sha2::Digest as _; use std::fmt; use webrtc::dtls_transport::dtls_fingerprint::RTCDtlsFingerprint; @@ -26,7 +25,7 @@ use webrtc::dtls_transport::dtls_fingerprint::RTCDtlsFingerprint; const SHA256: &str = "sha-256"; const MULTIHASH_SHA256_CODE: u64 = 0x12; -type Multihash = MultihashGeneric<64>; +type Multihash = multihash::Multihash<64>; /// A certificate fingerprint that is assumed to be created using the SHA256 hash algorithm. #[derive(Eq, PartialEq, Copy, Clone)] diff --git a/transports/webrtc/src/tokio/transport.rs b/transports/webrtc/src/tokio/transport.rs index 21f465ba063..163bc7fe59f 100644 --- a/transports/webrtc/src/tokio/transport.rs +++ b/transports/webrtc/src/tokio/transport.rs @@ -393,7 +393,7 @@ fn socketaddr_to_multiaddr(socket_addr: &SocketAddr, certhash: Option Option { let webrtc = iter.next()?; let port = match (port, webrtc) { - (Protocol::Udp(port), Protocol::WebRTC) => port, + (Protocol::Udp(port), Protocol::WebRTCDirect) => port, _ => return None, }; @@ -442,7 +442,7 @@ fn parse_webrtc_dial_addr(addr: &Multiaddr) -> Option<(SocketAddr, Fingerprint)> let certhash = iter.next()?; let (port, fingerprint) = match (port, webrtc, certhash) { - (Protocol::Udp(port), Protocol::WebRTC, Protocol::Certhash(cert_hash)) => { + (Protocol::Udp(port), Protocol::WebRTCDirect, Protocol::Certhash(cert_hash)) => { let fingerprint = Fingerprint::try_from_multihash(cert_hash)?; (port, fingerprint) diff --git a/transports/websocket/src/lib.rs b/transports/websocket/src/lib.rs index 7462f281817..01c02b15320 100644 --- a/transports/websocket/src/lib.rs +++ b/transports/websocket/src/lib.rs @@ -338,7 +338,7 @@ mod tests { let outbound = new_ws_config() .boxed() - .dial(addr.with(Protocol::P2p(PeerId::random().into()))) + .dial(addr.with(Protocol::P2p(PeerId::random()))) .unwrap(); let (a, b) = futures::join!(inbound, outbound); From 96f09b4aaee7a5b668bb3a5f0ec0e37f1127536f Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 6 Jun 2023 13:33:07 +0200 Subject: [PATCH 07/20] Temporarily disable version check --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bd3737a49f4..f9dcb413822 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,7 +72,7 @@ jobs: tool: tomlq - name: Enforce version in `workspace.dependencies` matches latest version - if: env.CRATE != 'libp2p' + if: env.CRATE != 'libp2p' && env.CRATE != 'libp2p-identity' run: | PACKAGE_VERSION=$(cargo metadata --format-version=1 --no-deps | jq -e -r '.packages[] | select(.name == "'"$CRATE"'") | .version') SPECIFIED_VERSION=$(tomlq "workspace.dependencies.$CRATE.version" --file ./Cargo.toml) From 3ce77ae72c707f7e15bc9291514a9beff9dac57f Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 6 Jun 2023 16:59:16 +0200 Subject: [PATCH 08/20] Update to `multihash` 0.19 --- Cargo.lock | 7 ++++--- identity/Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5d8d7e2f744..16959ee0179 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2617,7 +2617,7 @@ dependencies = [ "hex-literal", "libsecp256k1", "log", - "multihash 0.18.0", + "multihash 0.19.0", "p256 0.13.2", "quick-protobuf", "quickcheck-ext", @@ -3395,8 +3395,9 @@ dependencies = [ [[package]] name = "multihash" -version = "0.18.0" -source = "git+https://github.com/multiformats/rust-multihash#a5e3a5cbeba0bedbeff738cdc93d64aa3c4569f6" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fd59dcc2bbe70baabeac52cd22ae52c55eefe6c38ff11a9439f16a350a939f2" dependencies = [ "core2", "unsigned-varint", diff --git a/identity/Cargo.toml b/identity/Cargo.toml index 1495551f5e5..ca987c6b7b2 100644 --- a/identity/Cargo.toml +++ b/identity/Cargo.toml @@ -17,7 +17,7 @@ bs58 = { version = "0.5.0", optional = true } ed25519-dalek = { version = "1.0.1", optional = true } libsecp256k1 = { version = "0.7.0", optional = true } log = "0.4" -multihash = { git = "https://github.com/multiformats/rust-multihash", optional = true } +multihash = { version = "0.19.0", optional = true } p256 = { version = "0.13", default-features = false, features = ["ecdsa", "std", "pem"], optional = true } quick-protobuf = "0.8.1" rand = { version = "0.8", optional = true } From b97a3805fe23f9e12724c3142d20caa89e9e4266 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 6 Jun 2023 19:07:33 +0200 Subject: [PATCH 09/20] Remove unused function --- identity/CHANGELOG.md | 3 +++ identity/src/peer_id.rs | 14 -------------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/identity/CHANGELOG.md b/identity/CHANGELOG.md index 77d79a0f669..fcf8bf6ba81 100644 --- a/identity/CHANGELOG.md +++ b/identity/CHANGELOG.md @@ -17,6 +17,9 @@ `multiaddr::Protocol::P2p` is now type-safe and contains a `PeerId` directly, rendering this function obsolete. See [PR 3656]. +- Remove `PeerId::is_public_key` because it is unused and can be implemented externally. + See [PR 3656]. + [PR 3656]: https://github.com/libp2p/rust-libp2p/pull/3656 [PR 3850]: https://github.com/libp2p/rust-libp2p/pull/3850 [PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 diff --git a/identity/src/peer_id.rs b/identity/src/peer_id.rs index 30b2cb76cc6..91f5b8aa38b 100644 --- a/identity/src/peer_id.rs +++ b/identity/src/peer_id.rs @@ -117,20 +117,6 @@ impl PeerId { pub fn to_base58(&self) -> String { bs58::encode(self.to_bytes()).into_string() } - - /// Checks whether the public key passed as parameter matches the public key of this `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: &crate::PublicKey) -> Option { - let other_peer_id = PeerId::from_public_key(public_key); - - if self.multihash.code() != other_peer_id.multihash.code() { - return None; - } - - Some(self == &other_peer_id) - } } impl From for PeerId { From c44730a11ca114258869193d561ae10abf95ce59 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 6 Jun 2023 19:08:10 +0200 Subject: [PATCH 10/20] Remove test --- identity/src/peer_id.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/identity/src/peer_id.rs b/identity/src/peer_id.rs index 91f5b8aa38b..60ded4ad37c 100644 --- a/identity/src/peer_id.rs +++ b/identity/src/peer_id.rs @@ -246,14 +246,6 @@ impl FromStr for PeerId { mod tests { use super::*; - #[test] - #[cfg(feature = "ed25519")] - fn peer_id_is_public_key() { - let key = crate::Keypair::generate_ed25519().public(); - let peer_id = key.to_peer_id(); - assert_eq!(peer_id.is_public_key(&key), Some(true)); - } - #[test] #[cfg(feature = "ed25519")] fn peer_id_into_bytes_then_from_bytes() { From caf9ebe89f3fc1de00837fbbf619589895bad33d Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 6 Jun 2023 19:14:08 +0200 Subject: [PATCH 11/20] Re-enable version check --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f9dcb413822..bd3737a49f4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,7 +72,7 @@ jobs: tool: tomlq - name: Enforce version in `workspace.dependencies` matches latest version - if: env.CRATE != 'libp2p' && env.CRATE != 'libp2p-identity' + if: env.CRATE != 'libp2p' run: | PACKAGE_VERSION=$(cargo metadata --format-version=1 --no-deps | jq -e -r '.packages[] | select(.name == "'"$CRATE"'") | .version') SPECIFIED_VERSION=$(tomlq "workspace.dependencies.$CRATE.version" --file ./Cargo.toml) From 18310e3e62abf972a7b0803029f94e1ce963cdd9 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 6 Jun 2023 19:51:55 +0200 Subject: [PATCH 12/20] Update to latest multihash and multiaddr --- Cargo.lock | 196 +++++------------- Cargo.toml | 2 +- examples/dcutr/src/main.rs | 2 +- examples/file-sharing/src/main.rs | 4 +- examples/file-sharing/src/network.rs | 7 +- examples/rendezvous/src/bin/rzv-discover.rs | 2 +- libp2p/Cargo.toml | 2 +- misc/metrics/src/swarm.rs | 4 - protocols/autonat/src/behaviour/as_server.rs | 16 +- protocols/autonat/tests/test_server.rs | 2 +- protocols/dcutr/src/behaviour_impl.rs | 2 +- protocols/dcutr/tests/lib.rs | 6 +- protocols/identify/src/behaviour.rs | 6 +- protocols/identify/tests/smoke.rs | 2 +- protocols/kad/src/behaviour.rs | 1 - protocols/kad/src/behaviour/test.rs | 6 +- protocols/kad/src/kbucket/key.rs | 8 +- protocols/kad/src/record_priv.rs | 6 +- protocols/kad/src/record_priv/store/memory.rs | 2 +- protocols/mdns/src/behaviour/iface/query.rs | 18 +- protocols/relay/src/behaviour.rs | 2 +- protocols/relay/src/priv_client/handler.rs | 2 +- protocols/relay/src/priv_client/transport.rs | 6 +- protocols/relay/tests/lib.rs | 35 ++-- swarm/src/lib.rs | 4 +- transports/webrtc/src/tokio/transport.rs | 5 +- 26 files changed, 126 insertions(+), 222 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e3fcb3d6830..5ee03d8ae25 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1309,7 +1309,7 @@ dependencies = [ "env_logger 0.10.0", "futures", "libp2p", - "multiaddr 0.18.0", + "multiaddr", ] [[package]] @@ -1522,7 +1522,7 @@ dependencies = [ "env_logger 0.10.0", "futures", "libp2p", - "multiaddr 0.18.0", + "multiaddr", "void", ] @@ -2195,7 +2195,7 @@ dependencies = [ "env_logger 0.10.0", "futures", "libp2p", - "multiaddr 0.18.0", + "multiaddr", ] [[package]] @@ -2256,7 +2256,7 @@ dependencies = [ "base64 0.21.2", "clap", "libp2p-core", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde", "serde_json", "zeroize", @@ -2313,7 +2313,7 @@ dependencies = [ "libp2p-floodsub", "libp2p-gossipsub", "libp2p-identify", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p-kad", "libp2p-mdns", "libp2p-metrics", @@ -2333,7 +2333,7 @@ dependencies = [ "libp2p-webrtc", "libp2p-websocket", "libp2p-yamux", - "multiaddr 0.17.1", + "multiaddr", "pin-project", "tokio", ] @@ -2344,7 +2344,7 @@ version = "0.2.0" dependencies = [ "async-std", "libp2p-core", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p-swarm", "libp2p-swarm-derive", "libp2p-swarm-test", @@ -2362,7 +2362,7 @@ dependencies = [ "futures-timer", "instant", "libp2p-core", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p-request-response", "libp2p-swarm", "libp2p-swarm-test", @@ -2378,7 +2378,7 @@ dependencies = [ "async-std", "libp2p-core", "libp2p-identify", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p-ping", "libp2p-swarm", "libp2p-swarm-derive", @@ -2398,12 +2398,12 @@ dependencies = [ "futures", "futures-timer", "instant", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p-mplex", "libp2p-noise", "log", - "multiaddr 0.18.0", - "multihash 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", + "multiaddr", + "multihash", "multistream-select", "once_cell", "parking_lot", @@ -2434,7 +2434,7 @@ dependencies = [ "libp2p-core", "libp2p-dns", "libp2p-identify", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p-noise", "libp2p-ping", "libp2p-plaintext", @@ -2474,7 +2474,7 @@ dependencies = [ "env_logger 0.10.0", "futures", "libp2p-core", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log", "parking_lot", "smallvec", @@ -2491,7 +2491,7 @@ dependencies = [ "fnv", "futures", "libp2p-core", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p-swarm", "log", "quick-protobuf", @@ -2520,7 +2520,7 @@ dependencies = [ "hex_fmt", "instant", "libp2p-core", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p-noise", "libp2p-swarm", "libp2p-swarm-test", @@ -2550,7 +2550,7 @@ dependencies = [ "futures", "futures-timer", "libp2p-core", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p-swarm", "libp2p-swarm-test", "log", @@ -2574,7 +2574,7 @@ dependencies = [ "hex-literal", "libsecp256k1", "log", - "multihash 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", + "multihash", "p256 0.13.2", "quick-protobuf", "quickcheck-ext", @@ -2593,15 +2593,25 @@ dependencies = [ [[package]] name = "libp2p-identity" version = "0.2.0" -source = "git+https://github.com/libp2p/rust-libp2p?branch=libp2p-identity-no-multiaddr#eac13185bce93dae8c651a11e3f8a6d61be06cd7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93a7b3534b84fe89985d8076246806c845e716d0cdac50925dcf65caf49ab3c0" dependencies = [ + "asn1_der", "bs58", + "ed25519-dalek", + "libsecp256k1", "log", - "multihash 0.19.0 (git+https://github.com/multiformats/rust-multihash)", + "multihash", + "p256 0.13.2", "quick-protobuf", "rand 0.8.5", + "ring", + "sec1 0.7.1", + "serde", "sha2 0.10.6", "thiserror", + "void", + "zeroize", ] [[package]] @@ -2620,7 +2630,7 @@ dependencies = [ "instant", "libp2p-core", "libp2p-identify", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p-noise", "libp2p-swarm", "libp2p-swarm-test", @@ -2649,7 +2659,7 @@ dependencies = [ "futures", "if-watch", "libp2p-core", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p-noise", "libp2p-swarm", "libp2p-swarm-test", @@ -2673,7 +2683,7 @@ dependencies = [ "libp2p-dcutr", "libp2p-gossipsub", "libp2p-identify", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p-kad", "libp2p-ping", "libp2p-relay", @@ -2693,7 +2703,7 @@ dependencies = [ "env_logger 0.10.0", "futures", "libp2p-core", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p-muxer-test-harness", "libp2p-plaintext", "libp2p-tcp", @@ -2727,7 +2737,7 @@ dependencies = [ "futures", "futures_ringbuf", "libp2p-core", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log", "once_cell", "quick-protobuf", @@ -2753,7 +2763,7 @@ dependencies = [ "instant", "libp2p-core", "libp2p-dns", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p-quic", "libp2p-request-response", "libp2p-swarm", @@ -2781,7 +2791,7 @@ dependencies = [ "futures-timer", "instant", "libp2p-core", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p-swarm", "libp2p-swarm-test", "log", @@ -2800,7 +2810,7 @@ dependencies = [ "futures", "futures_ringbuf", "libp2p-core", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log", "quick-protobuf", "quickcheck-ext", @@ -2814,7 +2824,7 @@ version = "0.23.0" dependencies = [ "futures", "libp2p-core", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p-noise", "libp2p-swarm", "libp2p-tcp", @@ -2840,7 +2850,7 @@ dependencies = [ "futures-timer", "if-watch", "libp2p-core", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p-muxer-test-harness", "libp2p-noise", "libp2p-tcp", @@ -2868,7 +2878,7 @@ dependencies = [ "futures-timer", "instant", "libp2p-core", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p-ping", "libp2p-plaintext", "libp2p-swarm", @@ -2896,7 +2906,7 @@ dependencies = [ "instant", "libp2p-core", "libp2p-identify", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p-noise", "libp2p-ping", "libp2p-swarm", @@ -2923,7 +2933,7 @@ dependencies = [ "futures_ringbuf", "instant", "libp2p-core", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p-noise", "libp2p-swarm", "libp2p-swarm-test", @@ -2952,7 +2962,7 @@ dependencies = [ "instant", "libp2p-core", "libp2p-identify", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p-kad", "libp2p-ping", "libp2p-plaintext", @@ -2990,7 +3000,7 @@ dependencies = [ "futures", "futures-timer", "libp2p-core", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p-plaintext", "libp2p-swarm", "libp2p-tcp", @@ -3011,7 +3021,7 @@ dependencies = [ "if-watch", "libc", "libp2p-core", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log", "socket2 0.5.3", "tokio", @@ -3026,7 +3036,7 @@ dependencies = [ "hex", "hex-literal", "libp2p-core", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p-swarm", "libp2p-yamux", "rcgen 0.10.0", @@ -3078,12 +3088,12 @@ dependencies = [ "hex-literal", "if-watch", "libp2p-core", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p-noise", "libp2p-ping", "libp2p-swarm", "log", - "multihash 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", + "multihash", "quick-protobuf", "quick-protobuf-codec", "quickcheck", @@ -3111,7 +3121,7 @@ dependencies = [ "futures-rustls 0.22.2", "libp2p-core", "libp2p-dns", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p-tcp", "log", "parking_lot", @@ -3318,36 +3328,17 @@ dependencies = [ "windows-sys 0.42.0", ] -[[package]] -name = "multiaddr" -version = "0.17.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b36f567c7099511fa8612bbbb52dda2419ce0bdbacf31714e3a5ffdb766d3bd" -dependencies = [ - "arrayref", - "byteorder", - "data-encoding", - "log", - "multibase", - "multihash 0.17.0", - "percent-encoding", - "serde", - "static_assertions", - "unsigned-varint", - "url", -] - [[package]] name = "multiaddr" version = "0.18.0" -source = "git+https://github.com/thomaseizinger/rust-multiaddr?branch=typesafe-p2p#0e455ce32e829150ac2be196b0fed78019b19142" +source = "git+https://github.com/thomaseizinger/rust-multiaddr?branch=typesafe-p2p#bdbef13c78962923199855e2ad92f7d103ae3779" dependencies = [ "arrayref", "byteorder", "data-encoding", - "libp2p-identity 0.2.0 (git+https://github.com/libp2p/rust-libp2p?branch=libp2p-identity-no-multiaddr)", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "multibase", - "multihash 0.19.0 (git+https://github.com/multiformats/rust-multihash)", + "multihash", "percent-encoding", "serde", "static_assertions", @@ -3366,17 +3357,6 @@ dependencies = [ "data-encoding-macro", ] -[[package]] -name = "multihash" -version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "835d6ff01d610179fbce3de1694d007e500bf33a7f29689838941d6bf783ae40" -dependencies = [ - "core2", - "multihash-derive", - "unsigned-varint", -] - [[package]] name = "multihash" version = "0.19.0" @@ -3391,29 +3371,6 @@ dependencies = [ "unsigned-varint", ] -[[package]] -name = "multihash" -version = "0.19.0" -source = "git+https://github.com/multiformats/rust-multihash#16e68d8203c787768688dab8aed4295a32f33bf0" -dependencies = [ - "core2", - "unsigned-varint", -] - -[[package]] -name = "multihash-derive" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d6d4752e6230d8ef7adf7bd5d8c4b1f6561c1014c5ba9a37445ccefe18aa1db" -dependencies = [ - "proc-macro-crate", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 1.0.109", - "synstructure", -] - [[package]] name = "multistream-select" version = "0.13.0" @@ -3424,7 +3381,7 @@ dependencies = [ "futures", "futures_ringbuf", "libp2p-core", - "libp2p-identity 0.2.0", + "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p-plaintext", "libp2p-swarm", "libp2p-yamux", @@ -3772,7 +3729,7 @@ dependencies = [ "async-trait", "futures", "libp2p", - "multiaddr 0.18.0", + "multiaddr", ] [[package]] @@ -3892,40 +3849,6 @@ dependencies = [ "elliptic-curve 0.13.4", ] -[[package]] -name = "proc-macro-crate" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e17d47ce914bf4de440332250b0edd23ce48c005f59fab39d3335866b114f11a" -dependencies = [ - "thiserror", - "toml", -] - -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn 1.0.109", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - [[package]] name = "proc-macro-warning" version = "0.4.1" @@ -5060,15 +4983,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "toml" -version = "0.5.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" -dependencies = [ - "serde", -] - [[package]] name = "tower-service" version = "0.3.2" diff --git a/Cargo.toml b/Cargo.toml index 650f52375aa..3f57d5ba9fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -70,7 +70,7 @@ libp2p-dns = { version = "0.40.0", path = "transports/dns" } libp2p-floodsub = { version = "0.43.0", path = "protocols/floodsub" } libp2p-gossipsub = { version = "0.45.0", path = "protocols/gossipsub" } libp2p-identify = { version = "0.43.0", path = "protocols/identify" } -libp2p-identity = { version = "0.2.0", path = "identity" } +libp2p-identity = { version = "0.2.0" } libp2p-kad = { version = "0.44.0", path = "protocols/kad" } libp2p-mdns = { version = "0.44.0", path = "protocols/mdns" } libp2p-metrics = { version = "0.13.0", path = "misc/metrics" } diff --git a/examples/dcutr/src/main.rs b/examples/dcutr/src/main.rs index 11d65401aea..df14e79828b 100644 --- a/examples/dcutr/src/main.rs +++ b/examples/dcutr/src/main.rs @@ -231,7 +231,7 @@ fn main() -> Result<(), Box> { .dial( opts.relay_address .with(Protocol::P2pCircuit) - .with(Protocol::P2p(opts.remote_peer_id.unwrap().into())), + .with(Protocol::P2p(opts.remote_peer_id.unwrap())), ) .unwrap(); } diff --git a/examples/file-sharing/src/main.rs b/examples/file-sharing/src/main.rs index 9a0ec29ef7e..4b6d368fc47 100644 --- a/examples/file-sharing/src/main.rs +++ b/examples/file-sharing/src/main.rs @@ -27,7 +27,7 @@ use clap::Parser; use futures::prelude::*; use futures::StreamExt; -use libp2p::{core::Multiaddr, multiaddr::Protocol, PeerId}; +use libp2p::{core::Multiaddr, multiaddr::Protocol}; use std::error::Error; use std::io::Write; use std::path::PathBuf; @@ -60,7 +60,7 @@ async fn main() -> Result<(), Box> { // In case the user provided an address of a peer on the CLI, dial it. if let Some(addr) = opt.peer { let peer_id = match addr.iter().last() { - Some(Protocol::P2p(hash)) => PeerId::from_multihash(hash).expect("Valid hash."), + Some(Protocol::P2p(peer_id)) => peer_id, _ => return Err("Expect peer multiaddr to contain peer ID.".into()), }; network_client diff --git a/examples/file-sharing/src/network.rs b/examples/file-sharing/src/network.rs index f497d0ce299..6004c046adf 100644 --- a/examples/file-sharing/src/network.rs +++ b/examples/file-sharing/src/network.rs @@ -307,7 +307,7 @@ impl EventLoop { let local_peer_id = *self.swarm.local_peer_id(); eprintln!( "Local node is listening on {:?}", - address.with(Protocol::P2p(local_peer_id.into())) + address.with(Protocol::P2p(local_peer_id)) ); } SwarmEvent::IncomingConnection { .. } => {} @@ -355,10 +355,7 @@ impl EventLoop { .behaviour_mut() .kademlia .add_address(&peer_id, peer_addr.clone()); - match self - .swarm - .dial(peer_addr.with(Protocol::P2p(peer_id.into()))) - { + match self.swarm.dial(peer_addr.with(Protocol::P2p(peer_id))) { Ok(()) => { e.insert(sender); } diff --git a/examples/rendezvous/src/bin/rzv-discover.rs b/examples/rendezvous/src/bin/rzv-discover.rs index 8eb8b623791..710b491ff0a 100644 --- a/examples/rendezvous/src/bin/rzv-discover.rs +++ b/examples/rendezvous/src/bin/rzv-discover.rs @@ -91,7 +91,7 @@ async fn main() { let peer = registration.record.peer_id(); log::info!("Discovered peer {} at {}", peer, address); - let p2p_suffix = Protocol::P2p(*peer.as_ref()); + let p2p_suffix = Protocol::P2p(peer); let address_with_p2p = if !address.ends_with(&Multiaddr::empty().with(p2p_suffix.clone())) { address.clone().with(p2p_suffix) diff --git a/libp2p/Cargo.toml b/libp2p/Cargo.toml index 7cedac929c6..fce177c962d 100644 --- a/libp2p/Cargo.toml +++ b/libp2p/Cargo.toml @@ -114,7 +114,7 @@ libp2p-swarm = { workspace = true } libp2p-wasm-ext = { workspace = true, optional = true } libp2p-yamux = { workspace = true, optional = true } -multiaddr = { version = "0.17.0" } +multiaddr = { workspace = true } pin-project = "1.0.0" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] diff --git a/misc/metrics/src/swarm.rs b/misc/metrics/src/swarm.rs index 9ad57003fa7..8837457d36a 100644 --- a/misc/metrics/src/swarm.rs +++ b/misc/metrics/src/swarm.rs @@ -259,9 +259,6 @@ impl super::Recorder record(OutgoingConnectionError::Aborted), - libp2p_swarm::DialError::InvalidPeerId { .. } => { - record(OutgoingConnectionError::InvalidPeerId) - } libp2p_swarm::DialError::WrongPeerId { .. } => { record(OutgoingConnectionError::WrongPeerId) } @@ -371,7 +368,6 @@ enum OutgoingConnectionError { NoAddresses, DialPeerConditionFalse, Aborted, - InvalidPeerId, WrongPeerId, TransportMultiaddrNotSupported, TransportOther, diff --git a/protocols/autonat/src/behaviour/as_server.rs b/protocols/autonat/src/behaviour/as_server.rs index 063943392f3..09c70a27e93 100644 --- a/protocols/autonat/src/behaviour/as_server.rs +++ b/protocols/autonat/src/behaviour/as_server.rs @@ -338,7 +338,7 @@ impl<'a> AsServer<'a> { let is_valid = addr.iter().all(|proto| match proto { Protocol::P2pCircuit => false, - Protocol::P2p(hash) => hash == peer.into(), + Protocol::P2p(peer_id) => peer_id == peer, _ => true, }); @@ -346,7 +346,7 @@ impl<'a> AsServer<'a> { return None; } if !addr.iter().any(|p| matches!(p, Protocol::P2p(_))) { - addr.push(Protocol::P2p(peer.into())) + addr.push(Protocol::P2p(peer)) } // Only collect distinct addresses. distinct.insert(addr.clone()).then_some(addr) @@ -380,26 +380,26 @@ mod test { let observed_addr = Multiaddr::empty() .with(observed_ip.clone()) .with(random_port()) - .with(Protocol::P2p(peer_id.into())); + .with(Protocol::P2p(peer_id)); // Valid address with matching peer-id let demanded_1 = Multiaddr::empty() .with(random_ip()) .with(random_port()) - .with(Protocol::P2p(peer_id.into())); + .with(Protocol::P2p(peer_id)); // Invalid because peer_id does not match let demanded_2 = Multiaddr::empty() .with(random_ip()) .with(random_port()) - .with(Protocol::P2p(PeerId::random().into())); + .with(Protocol::P2p(PeerId::random())); // Valid address without peer-id let demanded_3 = Multiaddr::empty().with(random_ip()).with(random_port()); // Invalid because relayed let demanded_4 = Multiaddr::empty() .with(random_ip()) .with(random_port()) - .with(Protocol::P2p(PeerId::random().into())) + .with(Protocol::P2p(PeerId::random())) .with(Protocol::P2pCircuit) - .with(Protocol::P2p(peer_id.into())); + .with(Protocol::P2p(peer_id)); let demanded = vec![ demanded_1.clone(), demanded_2, @@ -413,7 +413,7 @@ mod test { let expected_2 = demanded_3 .replace(0, |_| Some(observed_ip)) .unwrap() - .with(Protocol::P2p(peer_id.into())); + .with(Protocol::P2p(peer_id)); assert_eq!(filtered, vec![expected_1, expected_2]); } } diff --git a/protocols/autonat/tests/test_server.rs b/protocols/autonat/tests/test_server.rs index 0f14c6edb27..1bb5f624793 100644 --- a/protocols/autonat/tests/test_server.rs +++ b/protocols/autonat/tests/test_server.rs @@ -69,7 +69,7 @@ async fn test_dial_back() { let expect_addr = Multiaddr::empty() .with(Protocol::Ip4(observed_client_ip)) .with(Protocol::Tcp(client_port)) - .with(Protocol::P2p(client_id.into())); + .with(Protocol::P2p(client_id)); let request_probe_id = match server.next_behaviour_event().await { Event::InboundProbe(InboundProbeEvent::Request { peer, diff --git a/protocols/dcutr/src/behaviour_impl.rs b/protocols/dcutr/src/behaviour_impl.rs index 6e3406c6f13..4993da655d3 100644 --- a/protocols/dcutr/src/behaviour_impl.rs +++ b/protocols/dcutr/src/behaviour_impl.rs @@ -105,7 +105,7 @@ impl Behaviour { .iter() .cloned() .filter(|a| !a.iter().any(|p| p == Protocol::P2pCircuit)) - .map(|a| a.with(Protocol::P2p(self.local_peer_id.into()))) + .map(|a| a.with(Protocol::P2p(self.local_peer_id))) .collect() } diff --git a/protocols/dcutr/tests/lib.rs b/protocols/dcutr/tests/lib.rs index fedb3299df9..6888e5914a0 100644 --- a/protocols/dcutr/tests/lib.rs +++ b/protocols/dcutr/tests/lib.rs @@ -49,9 +49,9 @@ async fn connect() { async_std::task::spawn(relay.loop_on_next()); let dst_relayed_addr = relay_addr - .with(Protocol::P2p(relay_peer_id.into())) + .with(Protocol::P2p(relay_peer_id)) .with(Protocol::P2pCircuit) - .with(Protocol::P2p(dst_peer_id.into())); + .with(Protocol::P2p(dst_peer_id)); dst.listen_on(dst_relayed_addr.clone()).unwrap(); wait_for_reservation( @@ -84,7 +84,7 @@ async fn connect() { } } - let dst_addr = dst_addr.with(Protocol::P2p(dst_peer_id.into())); + let dst_addr = dst_addr.with(Protocol::P2p(dst_peer_id)); src.wait(move |e| match e { SwarmEvent::ConnectionEstablished { endpoint, .. } => { diff --git a/protocols/identify/src/behaviour.rs b/protocols/identify/src/behaviour.rs index 8081924fffd..f572b937d38 100644 --- a/protocols/identify/src/behaviour.rs +++ b/protocols/identify/src/behaviour.rs @@ -446,7 +446,7 @@ pub enum Event { fn multiaddr_matches_peer_id(addr: &Multiaddr, peer_id: &PeerId) -> bool { let last_component = addr.iter().last(); if let Some(multiaddr::Protocol::P2p(multi_addr_peer_id)) = last_component { - return multi_addr_peer_id == *peer_id.as_ref(); + return multi_addr_peer_id == *peer_id; } true } @@ -504,8 +504,8 @@ mod tests { let addr_without_peer_id: Multiaddr = addr.clone(); let mut addr_with_other_peer_id = addr.clone(); - addr.push(multiaddr::Protocol::P2p(peer_id.into())); - addr_with_other_peer_id.push(multiaddr::Protocol::P2p(other_peer_id.into())); + addr.push(multiaddr::Protocol::P2p(peer_id)); + addr_with_other_peer_id.push(multiaddr::Protocol::P2p(other_peer_id)); assert!(multiaddr_matches_peer_id(&addr, &peer_id)); assert!(!multiaddr_matches_peer_id( diff --git a/protocols/identify/tests/smoke.rs b/protocols/identify/tests/smoke.rs index 2cf7cc899bc..c70ab3181b4 100644 --- a/protocols/identify/tests/smoke.rs +++ b/protocols/identify/tests/smoke.rs @@ -56,7 +56,7 @@ async fn periodic_identify() { s1_info.observed_addr, swarm1_memory_listen .clone() - .with(Protocol::P2p(swarm1_peer_id.into())) + .with(Protocol::P2p(swarm1_peer_id)) ); assert!(s1_info.listen_addrs.contains(&swarm2_tcp_listen_addr)); assert!(s1_info.listen_addrs.contains(&swarm2_memory_listen)); diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs index 5d4b84c65f6..7df17c91e1a 100644 --- a/protocols/kad/src/behaviour.rs +++ b/protocols/kad/src/behaviour.rs @@ -1907,7 +1907,6 @@ where match error { DialError::LocalPeerId { .. } - | DialError::InvalidPeerId { .. } | DialError::WrongPeerId { .. } | DialError::Aborted | DialError::Denied { .. } diff --git a/protocols/kad/src/behaviour/test.rs b/protocols/kad/src/behaviour/test.rs index ce7712b9e8e..cd4337e9094 100644 --- a/protocols/kad/src/behaviour/test.rs +++ b/protocols/kad/src/behaviour/test.rs @@ -138,7 +138,7 @@ fn build_fully_connected_nodes_with_config( swarms } -fn random_multihash() -> Multihash { +fn random_multihash() -> Multihash<64> { Multihash::wrap(SHA_256_MH, &thread_rng().gen::<[u8; 32]>()).unwrap() } @@ -1102,7 +1102,7 @@ fn disjoint_query_does_not_finish_before_all_paths_did() { let mut bob = build_node(); let key = Key::from( - Multihash::wrap(SHA_256_MH, &thread_rng().gen::<[u8; 32]>()) + Multihash::<64>::wrap(SHA_256_MH, &thread_rng().gen::<[u8; 32]>()) .expect("32 array to fit into 64 byte multihash"), ); let record_bob = Record::new(key.clone(), b"bob".to_vec()); @@ -1254,7 +1254,7 @@ fn manual_bucket_inserts() { .skip(2) .map(|(a, s)| { let pid = *Swarm::local_peer_id(s); - let addr = a.clone().with(Protocol::P2p(pid.into())); + let addr = a.clone().with(Protocol::P2p(pid)); (addr, pid) }) .collect::>(); diff --git a/protocols/kad/src/kbucket/key.rs b/protocols/kad/src/kbucket/key.rs index 1c48184078a..15cedaaaa32 100644 --- a/protocols/kad/src/kbucket/key.rs +++ b/protocols/kad/src/kbucket/key.rs @@ -93,8 +93,8 @@ impl From> for KeyBytes { } } -impl From for Key { - fn from(m: Multihash) -> Self { +impl From> for Key> { + fn from(m: Multihash) -> Self { let bytes = KeyBytes(Sha256::digest(m.to_bytes())); Key { preimage: m, bytes } } @@ -205,8 +205,8 @@ mod tests { } } - impl Arbitrary for Key { - fn arbitrary(g: &mut Gen) -> Key { + impl Arbitrary for Key> { + fn arbitrary(g: &mut Gen) -> Key> { let hash: [u8; 32] = core::array::from_fn(|_| u8::arbitrary(g)); Key::from(Multihash::wrap(SHA_256_MH, &hash).unwrap()) } diff --git a/protocols/kad/src/record_priv.rs b/protocols/kad/src/record_priv.rs index 2abe32d5894..4eb8e861c6f 100644 --- a/protocols/kad/src/record_priv.rs +++ b/protocols/kad/src/record_priv.rs @@ -66,8 +66,8 @@ impl From> for Key { } } -impl From for Key { - fn from(m: Multihash) -> Key { +impl From> for Key { + fn from(m: Multihash) -> Key { Key::from(m.to_bytes()) } } @@ -168,7 +168,7 @@ mod tests { impl Arbitrary for Key { fn arbitrary(g: &mut Gen) -> Key { let hash: [u8; 32] = core::array::from_fn(|_| u8::arbitrary(g)); - Key::from(Multihash::wrap(SHA_256_MH, &hash).unwrap()) + Key::from(Multihash::<64>::wrap(SHA_256_MH, &hash).unwrap()) } } diff --git a/protocols/kad/src/record_priv/store/memory.rs b/protocols/kad/src/record_priv/store/memory.rs index 1d4caab3bd7..edeae188ac6 100644 --- a/protocols/kad/src/record_priv/store/memory.rs +++ b/protocols/kad/src/record_priv/store/memory.rs @@ -221,7 +221,7 @@ mod tests { use quickcheck::*; use rand::Rng; - fn random_multihash() -> Multihash { + fn random_multihash() -> Multihash<64> { Multihash::wrap(SHA_256_MH, &rand::thread_rng().gen::<[u8; 32]>()).unwrap() } diff --git a/protocols/mdns/src/behaviour/iface/query.rs b/protocols/mdns/src/behaviour/iface/query.rs index 745926cf658..0185028f6ff 100644 --- a/protocols/mdns/src/behaviour/iface/query.rs +++ b/protocols/mdns/src/behaviour/iface/query.rs @@ -26,7 +26,7 @@ use libp2p_core::{ }; use libp2p_identity::PeerId; use std::time::Instant; -use std::{convert::TryFrom, fmt, net::SocketAddr, str, time::Duration}; +use std::{fmt, net::SocketAddr, str, time::Duration}; use trust_dns_proto::{ op::Message, rr::{Name, RData}, @@ -264,16 +264,12 @@ impl MdnsPeer { }; match addr.pop() { Some(Protocol::P2p(peer_id)) => { - if let Ok(peer_id) = PeerId::try_from(peer_id) { - if let Some(pid) = &my_peer_id { - if peer_id != *pid { - return None; - } - } else { - my_peer_id.replace(peer_id); + if let Some(pid) = &my_peer_id { + if peer_id != *pid { + return None; } } else { - return None; + my_peer_id.replace(peer_id); } } _ => return None, @@ -329,8 +325,8 @@ mod tests { let mut addr1: Multiaddr = "/ip4/1.2.3.4/tcp/5000".parse().expect("bad multiaddress"); let mut addr2: Multiaddr = "/ip6/::1/udp/10000".parse().expect("bad multiaddress"); - addr1.push(Protocol::P2p(peer_id.into())); - addr2.push(Protocol::P2p(peer_id.into())); + addr1.push(Protocol::P2p(peer_id)); + addr2.push(Protocol::P2p(peer_id)); let packets = build_query_response( 0xf8f8, diff --git a/protocols/relay/src/behaviour.rs b/protocols/relay/src/behaviour.rs index 7349c67ad7a..eb2f662581f 100644 --- a/protocols/relay/src/behaviour.rs +++ b/protocols/relay/src/behaviour.rs @@ -812,7 +812,7 @@ impl Action { // Add local peer ID in case it isn't present yet. .filter_map(|a| match a.iter().last()? { Protocol::P2p(_) => Some(a), - _ => Some(a.with(Protocol::P2p(local_peer_id.into()))), + _ => Some(a.with(Protocol::P2p(local_peer_id))), }) .collect(), }), diff --git a/protocols/relay/src/priv_client/handler.rs b/protocols/relay/src/priv_client/handler.rs index 414ec4fc8df..9613d7d6b3e 100644 --- a/protocols/relay/src/priv_client/handler.rs +++ b/protocols/relay/src/priv_client/handler.rs @@ -589,7 +589,7 @@ impl Reservation { .into_iter() .map(|a| { a.with(Protocol::P2pCircuit) - .with(Protocol::P2p(local_peer_id.into())) + .with(Protocol::P2p(local_peer_id)) }) .collect(), }, diff --git a/protocols/relay/src/priv_client/transport.rs b/protocols/relay/src/priv_client/transport.rs index aaaf760966f..c64c55d4407 100644 --- a/protocols/relay/src/priv_client/transport.rs +++ b/protocols/relay/src/priv_client/transport.rs @@ -267,9 +267,7 @@ fn parse_relayed_multiaddr(addr: Multiaddr) -> Result { - let peer_id = PeerId::from_multihash(hash).map_err(|_| Error::InvalidHash)?; - + Protocol::P2p(peer_id) => { if before_circuit { if relayed_multiaddr.relay_peer_id.is_some() { return Err(Error::MalformedMultiaddr.into()); @@ -378,7 +376,7 @@ impl Stream for Listener { upgrade: ready(Ok(stream)), listener_id, local_addr: relay_addr.with(Protocol::P2pCircuit), - send_back_addr: Protocol::P2p(src_peer_id.into()).into(), + send_back_addr: Protocol::P2p(src_peer_id).into(), }) } ToListenerMsg::Reservation(Err(())) => self.close(Err(Error::Reservation)), diff --git a/protocols/relay/tests/lib.rs b/protocols/relay/tests/lib.rs index f865b64856f..fa79ab67f4b 100644 --- a/protocols/relay/tests/lib.rs +++ b/protocols/relay/tests/lib.rs @@ -51,7 +51,7 @@ fn reservation() { spawn_swarm_on_pool(&pool, relay); let client_addr = relay_addr - .with(Protocol::P2p(relay_peer_id.into())) + .with(Protocol::P2p(relay_peer_id)) .with(Protocol::P2pCircuit); let mut client = build_client(); let client_peer_id = *client.local_peer_id(); @@ -64,9 +64,7 @@ fn reservation() { // Wait for initial reservation. pool.run_until(wait_for_reservation( &mut client, - client_addr - .clone() - .with(Protocol::P2p(client_peer_id.into())), + client_addr.clone().with(Protocol::P2p(client_peer_id)), relay_peer_id, false, // No renewal. )); @@ -74,7 +72,7 @@ fn reservation() { // Wait for renewal. pool.run_until(wait_for_reservation( &mut client, - client_addr.with(Protocol::P2p(client_peer_id.into())), + client_addr.with(Protocol::P2p(client_peer_id)), relay_peer_id, true, // Renewal. )); @@ -96,11 +94,9 @@ fn new_reservation_to_same_relay_replaces_old() { let mut client = build_client(); let client_peer_id = *client.local_peer_id(); let client_addr = relay_addr - .with(Protocol::P2p(relay_peer_id.into())) + .with(Protocol::P2p(relay_peer_id)) .with(Protocol::P2pCircuit); - let client_addr_with_peer_id = client_addr - .clone() - .with(Protocol::P2p(client_peer_id.into())); + let client_addr_with_peer_id = client_addr.clone().with(Protocol::P2p(client_peer_id)); let old_listener = client.listen_on(client_addr.clone()).unwrap(); @@ -189,9 +185,9 @@ fn connect() { let mut dst = build_client(); let dst_peer_id = *dst.local_peer_id(); let dst_addr = relay_addr - .with(Protocol::P2p(relay_peer_id.into())) + .with(Protocol::P2p(relay_peer_id)) .with(Protocol::P2pCircuit) - .with(Protocol::P2p(dst_peer_id.into())); + .with(Protocol::P2p(dst_peer_id)); dst.listen_on(dst_addr.clone()).unwrap(); @@ -242,8 +238,13 @@ async fn connection_established_to( if peer == relay_peer_id => {} SwarmEvent::ConnectionEstablished { peer_id, .. } if peer_id == other => break, SwarmEvent::IncomingConnection { send_back_addr, .. } => { - let peer_id_from_addr = - PeerId::try_from_multiaddr(&send_back_addr).expect("to have /p2p"); + let peer_id_from_addr = send_back_addr + .iter() + .find_map(|protocol| match protocol { + Protocol::P2p(peer_id) => Some(peer_id), + _ => None, + }) + .expect("to have /p2p"); assert_eq!(peer_id_from_addr, other) } @@ -263,9 +264,9 @@ fn handle_dial_failure() { let mut client = build_client(); let client_peer_id = *client.local_peer_id(); let client_addr = relay_addr - .with(Protocol::P2p(relay_peer_id.into())) + .with(Protocol::P2p(relay_peer_id)) .with(Protocol::P2pCircuit) - .with(Protocol::P2p(client_peer_id.into())); + .with(Protocol::P2p(client_peer_id)); client.listen_on(client_addr).unwrap(); assert!(!pool.run_until(wait_for_dial(&mut client, relay_peer_id))); @@ -286,7 +287,7 @@ fn reuse_connection() { let client_addr = relay_addr .clone() - .with(Protocol::P2p(relay_peer_id.into())) + .with(Protocol::P2p(relay_peer_id)) .with(Protocol::P2pCircuit); let mut client = build_client(); let client_peer_id = *client.local_peer_id(); @@ -298,7 +299,7 @@ fn reuse_connection() { pool.run_until(wait_for_reservation( &mut client, - client_addr.with(Protocol::P2p(client_peer_id.into())), + client_addr.with(Protocol::P2p(client_peer_id)), relay_peer_id, false, // No renewal. )); diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index a1d466d15c7..d8a9d08c9a3 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -2164,7 +2164,7 @@ mod tests { })); let other_id = PeerId::random(); - let other_addr = address.with(multiaddr::Protocol::P2p(other_id.into())); + let other_addr = address.with(multiaddr::Protocol::P2p(other_id)); swarm2.dial(other_addr.clone()).unwrap(); @@ -2313,7 +2313,7 @@ mod tests { let failed_addresses = errors.into_iter().map(|(addr, _)| addr).collect::>(); let expected_addresses = addresses .into_iter() - .map(|addr| addr.with(multiaddr::Protocol::P2p(target.into()))) + .map(|addr| addr.with(multiaddr::Protocol::P2p(target))) .collect::>(); assert_eq!(expected_addresses, failed_addresses); diff --git a/transports/webrtc/src/tokio/transport.rs b/transports/webrtc/src/tokio/transport.rs index 163bc7fe59f..6b678420e28 100644 --- a/transports/webrtc/src/tokio/transport.rs +++ b/transports/webrtc/src/tokio/transport.rs @@ -617,7 +617,10 @@ mod tests { assert!( matches!(listen_addr.iter().nth(1), Some(Protocol::Udp(port)) if port != 0) ); - assert!(matches!(listen_addr.iter().nth(2), Some(Protocol::WebRTC))); + assert!(matches!( + listen_addr.iter().nth(2), + Some(Protocol::WebRTCDirect) + )); } e => panic!("Unexpected event: {e:?}"), } From ca484a07766b1824b31f87050c52c4c28477c7cd Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 6 Jun 2023 19:53:26 +0200 Subject: [PATCH 13/20] Locally depend on `libp2p-identity` --- Cargo.lock | 88 ++++++++++++++++++++---------------------------------- Cargo.toml | 3 ++ 2 files changed, 35 insertions(+), 56 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5ee03d8ae25..0411142594d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2256,7 +2256,7 @@ dependencies = [ "base64 0.21.2", "clap", "libp2p-core", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "serde", "serde_json", "zeroize", @@ -2313,7 +2313,7 @@ dependencies = [ "libp2p-floodsub", "libp2p-gossipsub", "libp2p-identify", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "libp2p-kad", "libp2p-mdns", "libp2p-metrics", @@ -2344,7 +2344,7 @@ version = "0.2.0" dependencies = [ "async-std", "libp2p-core", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "libp2p-swarm", "libp2p-swarm-derive", "libp2p-swarm-test", @@ -2362,7 +2362,7 @@ dependencies = [ "futures-timer", "instant", "libp2p-core", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "libp2p-request-response", "libp2p-swarm", "libp2p-swarm-test", @@ -2378,7 +2378,7 @@ dependencies = [ "async-std", "libp2p-core", "libp2p-identify", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "libp2p-ping", "libp2p-swarm", "libp2p-swarm-derive", @@ -2398,7 +2398,7 @@ dependencies = [ "futures", "futures-timer", "instant", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "libp2p-mplex", "libp2p-noise", "log", @@ -2434,7 +2434,7 @@ dependencies = [ "libp2p-core", "libp2p-dns", "libp2p-identify", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "libp2p-noise", "libp2p-ping", "libp2p-plaintext", @@ -2474,7 +2474,7 @@ dependencies = [ "env_logger 0.10.0", "futures", "libp2p-core", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "log", "parking_lot", "smallvec", @@ -2491,7 +2491,7 @@ dependencies = [ "fnv", "futures", "libp2p-core", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "libp2p-swarm", "log", "quick-protobuf", @@ -2520,7 +2520,7 @@ dependencies = [ "hex_fmt", "instant", "libp2p-core", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "libp2p-noise", "libp2p-swarm", "libp2p-swarm-test", @@ -2550,7 +2550,7 @@ dependencies = [ "futures", "futures-timer", "libp2p-core", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "libp2p-swarm", "libp2p-swarm-test", "log", @@ -2590,30 +2590,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "libp2p-identity" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93a7b3534b84fe89985d8076246806c845e716d0cdac50925dcf65caf49ab3c0" -dependencies = [ - "asn1_der", - "bs58", - "ed25519-dalek", - "libsecp256k1", - "log", - "multihash", - "p256 0.13.2", - "quick-protobuf", - "rand 0.8.5", - "ring", - "sec1 0.7.1", - "serde", - "sha2 0.10.6", - "thiserror", - "void", - "zeroize", -] - [[package]] name = "libp2p-kad" version = "0.44.0" @@ -2630,7 +2606,7 @@ dependencies = [ "instant", "libp2p-core", "libp2p-identify", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "libp2p-noise", "libp2p-swarm", "libp2p-swarm-test", @@ -2659,7 +2635,7 @@ dependencies = [ "futures", "if-watch", "libp2p-core", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "libp2p-noise", "libp2p-swarm", "libp2p-swarm-test", @@ -2683,7 +2659,7 @@ dependencies = [ "libp2p-dcutr", "libp2p-gossipsub", "libp2p-identify", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "libp2p-kad", "libp2p-ping", "libp2p-relay", @@ -2703,7 +2679,7 @@ dependencies = [ "env_logger 0.10.0", "futures", "libp2p-core", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "libp2p-muxer-test-harness", "libp2p-plaintext", "libp2p-tcp", @@ -2737,7 +2713,7 @@ dependencies = [ "futures", "futures_ringbuf", "libp2p-core", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "log", "once_cell", "quick-protobuf", @@ -2763,7 +2739,7 @@ dependencies = [ "instant", "libp2p-core", "libp2p-dns", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "libp2p-quic", "libp2p-request-response", "libp2p-swarm", @@ -2791,7 +2767,7 @@ dependencies = [ "futures-timer", "instant", "libp2p-core", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "libp2p-swarm", "libp2p-swarm-test", "log", @@ -2810,7 +2786,7 @@ dependencies = [ "futures", "futures_ringbuf", "libp2p-core", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "log", "quick-protobuf", "quickcheck-ext", @@ -2824,7 +2800,7 @@ version = "0.23.0" dependencies = [ "futures", "libp2p-core", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "libp2p-noise", "libp2p-swarm", "libp2p-tcp", @@ -2850,7 +2826,7 @@ dependencies = [ "futures-timer", "if-watch", "libp2p-core", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "libp2p-muxer-test-harness", "libp2p-noise", "libp2p-tcp", @@ -2878,7 +2854,7 @@ dependencies = [ "futures-timer", "instant", "libp2p-core", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "libp2p-ping", "libp2p-plaintext", "libp2p-swarm", @@ -2906,7 +2882,7 @@ dependencies = [ "instant", "libp2p-core", "libp2p-identify", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "libp2p-noise", "libp2p-ping", "libp2p-swarm", @@ -2933,7 +2909,7 @@ dependencies = [ "futures_ringbuf", "instant", "libp2p-core", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "libp2p-noise", "libp2p-swarm", "libp2p-swarm-test", @@ -2962,7 +2938,7 @@ dependencies = [ "instant", "libp2p-core", "libp2p-identify", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "libp2p-kad", "libp2p-ping", "libp2p-plaintext", @@ -3000,7 +2976,7 @@ dependencies = [ "futures", "futures-timer", "libp2p-core", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "libp2p-plaintext", "libp2p-swarm", "libp2p-tcp", @@ -3021,7 +2997,7 @@ dependencies = [ "if-watch", "libc", "libp2p-core", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "log", "socket2 0.5.3", "tokio", @@ -3036,7 +3012,7 @@ dependencies = [ "hex", "hex-literal", "libp2p-core", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "libp2p-swarm", "libp2p-yamux", "rcgen 0.10.0", @@ -3088,7 +3064,7 @@ dependencies = [ "hex-literal", "if-watch", "libp2p-core", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "libp2p-noise", "libp2p-ping", "libp2p-swarm", @@ -3121,7 +3097,7 @@ dependencies = [ "futures-rustls 0.22.2", "libp2p-core", "libp2p-dns", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "libp2p-tcp", "log", "parking_lot", @@ -3336,7 +3312,7 @@ dependencies = [ "arrayref", "byteorder", "data-encoding", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "multibase", "multihash", "percent-encoding", @@ -3381,7 +3357,7 @@ dependencies = [ "futures", "futures_ringbuf", "libp2p-core", - "libp2p-identity 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identity", "libp2p-plaintext", "libp2p-swarm", "libp2p-yamux", diff --git a/Cargo.toml b/Cargo.toml index 3f57d5ba9fe..61ab61a7bdf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -101,3 +101,6 @@ quickcheck = { package = "quickcheck-ext", path = "misc/quickcheck-ext" } rw-stream-sink = { version = "0.4.0", path = "misc/rw-stream-sink" } multiaddr = { git = "https://github.com/thomaseizinger/rust-multiaddr", branch = "typesafe-p2p" } multihash = "0.19.0" + +[patch.crates-io] +libp2p-identity = { path = "identity" } From 6e3415e820df94379764cbdcfb2c999d6f4f3af5 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 6 Jun 2023 19:57:28 +0200 Subject: [PATCH 14/20] Document patch of `libp2p-identity` --- Cargo.toml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 61ab61a7bdf..2252309519b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -102,5 +102,12 @@ rw-stream-sink = { version = "0.4.0", path = "misc/rw-stream-sink" } multiaddr = { git = "https://github.com/thomaseizinger/rust-multiaddr", branch = "typesafe-p2p" } multihash = "0.19.0" + [patch.crates-io] + +# Patch away `libp2p-idnentity` in our dependency tree with the workspace version. +# `libp2p-identity` is a leaf dependency and used within `rust-multiaddr` which is **not** part of the workspace. +# As a result, we cannot just reference the workspace version in our crates because the types would mismatch with what +# we import via `rust-multiaddr`. +# This is expected to stay here until we move `libp2p-identity` to a separate repository which makes the dependency relationship more obvious. libp2p-identity = { path = "identity" } From bf613d90916d8057c84e439fcdab4636f1dad785 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 6 Jun 2023 20:23:16 +0200 Subject: [PATCH 15/20] Fix rustdoc errors --- transports/webrtc/src/tokio/fingerprint.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/transports/webrtc/src/tokio/fingerprint.rs b/transports/webrtc/src/tokio/fingerprint.rs index 3eb28645907..876ef25461a 100644 --- a/transports/webrtc/src/tokio/fingerprint.rs +++ b/transports/webrtc/src/tokio/fingerprint.rs @@ -56,7 +56,7 @@ impl Fingerprint { Some(Self(buf)) } - /// Converts [`Multihash`](MultihashGeneric) to [`Fingerprint`]. + /// Converts [`Multihash`](Multihash) to [`Fingerprint`]. pub fn try_from_multihash(hash: Multihash) -> Option { if hash.code() != MULTIHASH_SHA256_CODE { // Only support SHA256 for now. @@ -68,7 +68,7 @@ impl Fingerprint { Some(Self(bytes)) } - /// Converts this fingerprint to [`Multihash`](MultihashGeneric). + /// Converts this fingerprint to [`Multihash`](Multihash). pub fn to_multihash(self) -> Multihash { Multihash::wrap(MULTIHASH_SHA256_CODE, &self.0).expect("fingerprint's len to be 32 bytes") } From 1886e166c4c4d63294aec11fdc60c7af24508b59 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 6 Jun 2023 21:45:30 +0200 Subject: [PATCH 16/20] Don't activate default feature --- core/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Cargo.toml b/core/Cargo.toml index 9788626b3de..84621df556e 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -19,7 +19,7 @@ instant = "0.1.12" libp2p-identity = { workspace = true, features = ["peerid", "ed25519"] } log = "0.4" multiaddr = { workspace = true } -multihash = { workspace = true , features = ["std"] } +multihash = { workspace = true } multistream-select = { workspace = true } once_cell = "1.18.0" parking_lot = "0.12.0" From f61a0fc37cfd125864cff1b434ef6e743c0ec8cf Mon Sep 17 00:00:00 2001 From: Max Inden Date: Wed, 7 Jun 2023 19:31:27 +0900 Subject: [PATCH 17/20] Use released multiaddr v0.18.0 --- Cargo.lock | 3 ++- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ab441612d20..b4b3412a428 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3305,7 +3305,8 @@ dependencies = [ [[package]] name = "multiaddr" version = "0.18.0" -source = "git+https://github.com/thomaseizinger/rust-multiaddr?branch=typesafe-p2p#bdbef13c78962923199855e2ad92f7d103ae3779" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92a651988b3ed3ad1bc8c87d016bb92f6f395b84ed1db9b926b32b1fc5a2c8b5" dependencies = [ "arrayref", "byteorder", diff --git a/Cargo.toml b/Cargo.toml index 2252309519b..547dbabbeb9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -99,7 +99,7 @@ multistream-select = { version = "0.13.0", path = "misc/multistream-select" } quick-protobuf-codec = { version = "0.2.0", path = "misc/quick-protobuf-codec" } quickcheck = { package = "quickcheck-ext", path = "misc/quickcheck-ext" } rw-stream-sink = { version = "0.4.0", path = "misc/rw-stream-sink" } -multiaddr = { git = "https://github.com/thomaseizinger/rust-multiaddr", branch = "typesafe-p2p" } +multiaddr = "0.18.0" multihash = "0.19.0" From 062a47a29a0e490a2adb198ada5b7ddb6bf6a38b Mon Sep 17 00:00:00 2001 From: Max Inden Date: Thu, 8 Jun 2023 09:35:33 +0900 Subject: [PATCH 18/20] Remove superfluous multiaddr imports --- Cargo.lock | 4 ---- examples/distributed-key-value-store/Cargo.toml | 1 - examples/file-sharing/Cargo.toml | 1 - examples/ipfs-private/Cargo.toml | 1 - examples/ping-example/Cargo.toml | 1 - 5 files changed, 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b4b3412a428..39ee5d84cb5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1309,7 +1309,6 @@ dependencies = [ "env_logger 0.10.0", "futures", "libp2p", - "multiaddr", ] [[package]] @@ -1521,7 +1520,6 @@ dependencies = [ "env_logger 0.10.0", "futures", "libp2p", - "multiaddr", "serde", "void", ] @@ -2195,7 +2193,6 @@ dependencies = [ "env_logger 0.10.0", "futures", "libp2p", - "multiaddr", ] [[package]] @@ -3704,7 +3701,6 @@ dependencies = [ "async-trait", "futures", "libp2p", - "multiaddr", ] [[package]] diff --git a/examples/distributed-key-value-store/Cargo.toml b/examples/distributed-key-value-store/Cargo.toml index 23e3635db96..f8e0fd2339d 100644 --- a/examples/distributed-key-value-store/Cargo.toml +++ b/examples/distributed-key-value-store/Cargo.toml @@ -11,4 +11,3 @@ async-trait = "0.1" env_logger = "0.10" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "dns", "kad", "mdns", "noise", "macros", "tcp", "websocket", "yamux"] } -multiaddr = { workspace = true } diff --git a/examples/file-sharing/Cargo.toml b/examples/file-sharing/Cargo.toml index ff1f878c1bd..9bb2f622f63 100644 --- a/examples/file-sharing/Cargo.toml +++ b/examples/file-sharing/Cargo.toml @@ -13,5 +13,4 @@ either = "1.8" env_logger = "0.10" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "cbor", "dns", "kad", "noise", "macros", "request-response", "tcp", "websocket", "yamux"] } -multiaddr = { workspace = true } void = "1.0.2" diff --git a/examples/ipfs-private/Cargo.toml b/examples/ipfs-private/Cargo.toml index c778f1b6ebb..c1e860a08b3 100644 --- a/examples/ipfs-private/Cargo.toml +++ b/examples/ipfs-private/Cargo.toml @@ -12,4 +12,3 @@ either = "1.8" env_logger = "0.10" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "gossipsub", "dns", "identify", "kad", "macros", "noise", "ping", "pnet", "tcp", "websocket", "yamux"] } -multiaddr = { workspace = true } diff --git a/examples/ping-example/Cargo.toml b/examples/ping-example/Cargo.toml index 7a2d34ff22b..f1022b2dcd3 100644 --- a/examples/ping-example/Cargo.toml +++ b/examples/ping-example/Cargo.toml @@ -10,4 +10,3 @@ async-std = { version = "1.12", features = ["attributes"] } async-trait = "0.1" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "dns", "macros", "noise", "ping", "tcp", "websocket", "yamux"] } -multiaddr = { workspace = true } From 6872e90f0cc7e8359f3663b66b326a52a5597c6e Mon Sep 17 00:00:00 2001 From: Max Inden Date: Thu, 8 Jun 2023 09:39:24 +0900 Subject: [PATCH 19/20] Add swarm changelog item --- swarm/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index 6c3b2069b0d..d18629a0eb0 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -56,6 +56,9 @@ - Rename `ConnectionHandlerEvent::Custom` to `ConnectionHandlerEvent::NotifyBehaviour`. See [PR 3955]. +- Remove `DialError::InvalidPeerId` variant. With the move to `multiaddr` `v0.18.0` peer IDs in `/p2p` are type safe and thus usage of the contained peer ID can not result in a parsing error. + See [PR 4037]. + - Remove deprecated items. See [PR 3956]. [PR 3605]: https://github.com/libp2p/rust-libp2p/pull/3605 @@ -73,6 +76,7 @@ [PR 3927]: https://github.com/libp2p/rust-libp2p/pull/3927 [PR 3955]: https://github.com/libp2p/rust-libp2p/pull/3955 [PR 3956]: https://github.com/libp2p/rust-libp2p/pull/3956 +[PR 4037]: https://github.com/libp2p/rust-libp2p/pull/4037 ## 0.42.2 From b56613f779a49bee1f7a3edfd4dcfdc0620a72c9 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Thu, 8 Jun 2023 09:58:08 +0900 Subject: [PATCH 20/20] Fix multihash doc link --- transports/webrtc/src/tokio/fingerprint.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/transports/webrtc/src/tokio/fingerprint.rs b/transports/webrtc/src/tokio/fingerprint.rs index 876ef25461a..c3d58d64e72 100644 --- a/transports/webrtc/src/tokio/fingerprint.rs +++ b/transports/webrtc/src/tokio/fingerprint.rs @@ -56,7 +56,7 @@ impl Fingerprint { Some(Self(buf)) } - /// Converts [`Multihash`](Multihash) to [`Fingerprint`]. + /// Converts [`Multihash`](multihash::Multihash) to [`Fingerprint`]. pub fn try_from_multihash(hash: Multihash) -> Option { if hash.code() != MULTIHASH_SHA256_CODE { // Only support SHA256 for now. @@ -68,7 +68,7 @@ impl Fingerprint { Some(Self(bytes)) } - /// Converts this fingerprint to [`Multihash`](Multihash). + /// Converts this fingerprint to [`Multihash`](multihash::Multihash). pub fn to_multihash(self) -> Multihash { Multihash::wrap(MULTIHASH_SHA256_CODE, &self.0).expect("fingerprint's len to be 32 bytes") }