feat: leverage type-safe /p2p in multiaddr

This updates `multiaddr` to version `0.19`.

Depends-On: #3656.
Depends-On: https://github.com/multiformats/rust-multiaddr/pull/83.
Resolves: #4039.

Pull-Request: #4037.
This commit is contained in:
Thomas Eizinger
2023-06-08 03:38:18 +02:00
committed by GitHub
parent d2dab94b76
commit ed14630672
41 changed files with 172 additions and 348 deletions

View File

@ -72,7 +72,7 @@ jobs:
tool: tomlq tool: tomlq
- name: Enforce version in `workspace.dependencies` matches latest version - name: Enforce version in `workspace.dependencies` matches latest version
if: env.CRATE != 'libp2p' && env.CRATE != 'libp2p-identity' if: env.CRATE != 'libp2p'
run: | run: |
PACKAGE_VERSION=$(cargo metadata --format-version=1 --no-deps | jq -e -r '.packages[] | select(.name == "'"$CRATE"'") | .version') 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) SPECIFIED_VERSION=$(tomlq "workspace.dependencies.$CRATE.version" --file ./Cargo.toml)

234
Cargo.lock generated
View File

@ -617,12 +617,6 @@ dependencies = [
"futures-lite", "futures-lite",
] ]
[[package]]
name = "bs58"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3"
[[package]] [[package]]
name = "bs58" name = "bs58"
version = "0.5.0" version = "0.5.0"
@ -1315,7 +1309,6 @@ dependencies = [
"env_logger 0.10.0", "env_logger 0.10.0",
"futures", "futures",
"libp2p", "libp2p",
"multiaddr",
] ]
[[package]] [[package]]
@ -1336,18 +1329,6 @@ dependencies = [
"signature 1.6.4", "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]] [[package]]
name = "ecdsa" name = "ecdsa"
version = "0.16.6" version = "0.16.6"
@ -1539,7 +1520,6 @@ dependencies = [
"env_logger 0.10.0", "env_logger 0.10.0",
"futures", "futures",
"libp2p", "libp2p",
"multiaddr",
"serde", "serde",
"void", "void",
] ]
@ -2213,7 +2193,6 @@ dependencies = [
"env_logger 0.10.0", "env_logger 0.10.0",
"futures", "futures",
"libp2p", "libp2p",
"multiaddr",
] ]
[[package]] [[package]]
@ -2274,7 +2253,7 @@ dependencies = [
"base64 0.21.2", "base64 0.21.2",
"clap", "clap",
"libp2p-core", "libp2p-core",
"libp2p-identity 0.1.2", "libp2p-identity",
"serde", "serde",
"serde_json", "serde_json",
"zeroize", "zeroize",
@ -2331,7 +2310,7 @@ dependencies = [
"libp2p-floodsub", "libp2p-floodsub",
"libp2p-gossipsub", "libp2p-gossipsub",
"libp2p-identify", "libp2p-identify",
"libp2p-identity 0.1.2", "libp2p-identity",
"libp2p-kad", "libp2p-kad",
"libp2p-mdns", "libp2p-mdns",
"libp2p-metrics", "libp2p-metrics",
@ -2360,7 +2339,7 @@ version = "0.2.0"
dependencies = [ dependencies = [
"async-std", "async-std",
"libp2p-core", "libp2p-core",
"libp2p-identity 0.1.2", "libp2p-identity",
"libp2p-swarm", "libp2p-swarm",
"libp2p-swarm-derive", "libp2p-swarm-derive",
"libp2p-swarm-test", "libp2p-swarm-test",
@ -2378,7 +2357,7 @@ dependencies = [
"futures-timer", "futures-timer",
"instant", "instant",
"libp2p-core", "libp2p-core",
"libp2p-identity 0.1.2", "libp2p-identity",
"libp2p-request-response", "libp2p-request-response",
"libp2p-swarm", "libp2p-swarm",
"libp2p-swarm-test", "libp2p-swarm-test",
@ -2394,7 +2373,7 @@ dependencies = [
"async-std", "async-std",
"libp2p-core", "libp2p-core",
"libp2p-identify", "libp2p-identify",
"libp2p-identity 0.1.2", "libp2p-identity",
"libp2p-ping", "libp2p-ping",
"libp2p-swarm", "libp2p-swarm",
"libp2p-swarm-derive", "libp2p-swarm-derive",
@ -2414,12 +2393,12 @@ dependencies = [
"futures", "futures",
"futures-timer", "futures-timer",
"instant", "instant",
"libp2p-identity 0.1.2", "libp2p-identity",
"libp2p-mplex", "libp2p-mplex",
"libp2p-noise", "libp2p-noise",
"log", "log",
"multiaddr", "multiaddr",
"multihash 0.17.0", "multihash",
"multistream-select", "multistream-select",
"once_cell", "once_cell",
"parking_lot", "parking_lot",
@ -2450,7 +2429,7 @@ dependencies = [
"libp2p-core", "libp2p-core",
"libp2p-dns", "libp2p-dns",
"libp2p-identify", "libp2p-identify",
"libp2p-identity 0.1.2", "libp2p-identity",
"libp2p-noise", "libp2p-noise",
"libp2p-ping", "libp2p-ping",
"libp2p-plaintext", "libp2p-plaintext",
@ -2490,7 +2469,7 @@ dependencies = [
"env_logger 0.10.0", "env_logger 0.10.0",
"futures", "futures",
"libp2p-core", "libp2p-core",
"libp2p-identity 0.1.2", "libp2p-identity",
"log", "log",
"parking_lot", "parking_lot",
"smallvec", "smallvec",
@ -2507,7 +2486,7 @@ dependencies = [
"fnv", "fnv",
"futures", "futures",
"libp2p-core", "libp2p-core",
"libp2p-identity 0.1.2", "libp2p-identity",
"libp2p-swarm", "libp2p-swarm",
"log", "log",
"quick-protobuf", "quick-protobuf",
@ -2536,7 +2515,7 @@ dependencies = [
"hex_fmt", "hex_fmt",
"instant", "instant",
"libp2p-core", "libp2p-core",
"libp2p-identity 0.1.2", "libp2p-identity",
"libp2p-noise", "libp2p-noise",
"libp2p-swarm", "libp2p-swarm",
"libp2p-swarm-test", "libp2p-swarm-test",
@ -2566,7 +2545,7 @@ dependencies = [
"futures", "futures",
"futures-timer", "futures-timer",
"libp2p-core", "libp2p-core",
"libp2p-identity 0.1.2", "libp2p-identity",
"libp2p-swarm", "libp2p-swarm",
"libp2p-swarm-test", "libp2p-swarm-test",
"log", "log",
@ -2578,44 +2557,19 @@ dependencies = [
"void", "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]] [[package]]
name = "libp2p-identity" name = "libp2p-identity"
version = "0.2.0" version = "0.2.0"
dependencies = [ dependencies = [
"asn1_der", "asn1_der",
"base64 0.21.2", "base64 0.21.2",
"bs58 0.5.0", "bs58",
"criterion", "criterion",
"ed25519-dalek", "ed25519-dalek",
"hex-literal", "hex-literal",
"libsecp256k1", "libsecp256k1",
"log", "log",
"multihash 0.19.0", "multihash",
"p256 0.13.2", "p256 0.13.2",
"quick-protobuf", "quick-protobuf",
"quickcheck-ext", "quickcheck-ext",
@ -2647,7 +2601,7 @@ dependencies = [
"instant", "instant",
"libp2p-core", "libp2p-core",
"libp2p-identify", "libp2p-identify",
"libp2p-identity 0.1.2", "libp2p-identity",
"libp2p-noise", "libp2p-noise",
"libp2p-swarm", "libp2p-swarm",
"libp2p-swarm-test", "libp2p-swarm-test",
@ -2676,7 +2630,7 @@ dependencies = [
"futures", "futures",
"if-watch", "if-watch",
"libp2p-core", "libp2p-core",
"libp2p-identity 0.1.2", "libp2p-identity",
"libp2p-noise", "libp2p-noise",
"libp2p-swarm", "libp2p-swarm",
"libp2p-swarm-test", "libp2p-swarm-test",
@ -2700,7 +2654,7 @@ dependencies = [
"libp2p-dcutr", "libp2p-dcutr",
"libp2p-gossipsub", "libp2p-gossipsub",
"libp2p-identify", "libp2p-identify",
"libp2p-identity 0.1.2", "libp2p-identity",
"libp2p-kad", "libp2p-kad",
"libp2p-ping", "libp2p-ping",
"libp2p-relay", "libp2p-relay",
@ -2720,7 +2674,7 @@ dependencies = [
"env_logger 0.10.0", "env_logger 0.10.0",
"futures", "futures",
"libp2p-core", "libp2p-core",
"libp2p-identity 0.1.2", "libp2p-identity",
"libp2p-muxer-test-harness", "libp2p-muxer-test-harness",
"libp2p-plaintext", "libp2p-plaintext",
"libp2p-tcp", "libp2p-tcp",
@ -2754,7 +2708,7 @@ dependencies = [
"futures", "futures",
"futures_ringbuf", "futures_ringbuf",
"libp2p-core", "libp2p-core",
"libp2p-identity 0.1.2", "libp2p-identity",
"log", "log",
"once_cell", "once_cell",
"quick-protobuf", "quick-protobuf",
@ -2780,7 +2734,7 @@ dependencies = [
"instant", "instant",
"libp2p-core", "libp2p-core",
"libp2p-dns", "libp2p-dns",
"libp2p-identity 0.1.2", "libp2p-identity",
"libp2p-quic", "libp2p-quic",
"libp2p-request-response", "libp2p-request-response",
"libp2p-swarm", "libp2p-swarm",
@ -2808,7 +2762,7 @@ dependencies = [
"futures-timer", "futures-timer",
"instant", "instant",
"libp2p-core", "libp2p-core",
"libp2p-identity 0.1.2", "libp2p-identity",
"libp2p-swarm", "libp2p-swarm",
"libp2p-swarm-test", "libp2p-swarm-test",
"log", "log",
@ -2827,7 +2781,7 @@ dependencies = [
"futures", "futures",
"futures_ringbuf", "futures_ringbuf",
"libp2p-core", "libp2p-core",
"libp2p-identity 0.1.2", "libp2p-identity",
"log", "log",
"quick-protobuf", "quick-protobuf",
"quickcheck-ext", "quickcheck-ext",
@ -2841,7 +2795,7 @@ version = "0.23.0"
dependencies = [ dependencies = [
"futures", "futures",
"libp2p-core", "libp2p-core",
"libp2p-identity 0.1.2", "libp2p-identity",
"libp2p-noise", "libp2p-noise",
"libp2p-swarm", "libp2p-swarm",
"libp2p-tcp", "libp2p-tcp",
@ -2867,7 +2821,7 @@ dependencies = [
"futures-timer", "futures-timer",
"if-watch", "if-watch",
"libp2p-core", "libp2p-core",
"libp2p-identity 0.1.2", "libp2p-identity",
"libp2p-muxer-test-harness", "libp2p-muxer-test-harness",
"libp2p-noise", "libp2p-noise",
"libp2p-tcp", "libp2p-tcp",
@ -2895,7 +2849,7 @@ dependencies = [
"futures-timer", "futures-timer",
"instant", "instant",
"libp2p-core", "libp2p-core",
"libp2p-identity 0.1.2", "libp2p-identity",
"libp2p-ping", "libp2p-ping",
"libp2p-plaintext", "libp2p-plaintext",
"libp2p-swarm", "libp2p-swarm",
@ -2923,7 +2877,7 @@ dependencies = [
"instant", "instant",
"libp2p-core", "libp2p-core",
"libp2p-identify", "libp2p-identify",
"libp2p-identity 0.1.2", "libp2p-identity",
"libp2p-noise", "libp2p-noise",
"libp2p-ping", "libp2p-ping",
"libp2p-swarm", "libp2p-swarm",
@ -2950,7 +2904,7 @@ dependencies = [
"futures_ringbuf", "futures_ringbuf",
"instant", "instant",
"libp2p-core", "libp2p-core",
"libp2p-identity 0.1.2", "libp2p-identity",
"libp2p-noise", "libp2p-noise",
"libp2p-swarm", "libp2p-swarm",
"libp2p-swarm-test", "libp2p-swarm-test",
@ -2979,7 +2933,7 @@ dependencies = [
"instant", "instant",
"libp2p-core", "libp2p-core",
"libp2p-identify", "libp2p-identify",
"libp2p-identity 0.1.2", "libp2p-identity",
"libp2p-kad", "libp2p-kad",
"libp2p-ping", "libp2p-ping",
"libp2p-plaintext", "libp2p-plaintext",
@ -3017,7 +2971,7 @@ dependencies = [
"futures", "futures",
"futures-timer", "futures-timer",
"libp2p-core", "libp2p-core",
"libp2p-identity 0.1.2", "libp2p-identity",
"libp2p-plaintext", "libp2p-plaintext",
"libp2p-swarm", "libp2p-swarm",
"libp2p-tcp", "libp2p-tcp",
@ -3038,7 +2992,7 @@ dependencies = [
"if-watch", "if-watch",
"libc", "libc",
"libp2p-core", "libp2p-core",
"libp2p-identity 0.1.2", "libp2p-identity",
"log", "log",
"socket2 0.5.3", "socket2 0.5.3",
"tokio", "tokio",
@ -3053,7 +3007,7 @@ dependencies = [
"hex", "hex",
"hex-literal", "hex-literal",
"libp2p-core", "libp2p-core",
"libp2p-identity 0.1.2", "libp2p-identity",
"libp2p-swarm", "libp2p-swarm",
"libp2p-yamux", "libp2p-yamux",
"rcgen 0.10.0", "rcgen 0.10.0",
@ -3105,12 +3059,12 @@ dependencies = [
"hex-literal", "hex-literal",
"if-watch", "if-watch",
"libp2p-core", "libp2p-core",
"libp2p-identity 0.1.2", "libp2p-identity",
"libp2p-noise", "libp2p-noise",
"libp2p-ping", "libp2p-ping",
"libp2p-swarm", "libp2p-swarm",
"log", "log",
"multihash 0.17.0", "multihash",
"quick-protobuf", "quick-protobuf",
"quick-protobuf-codec", "quick-protobuf-codec",
"quickcheck", "quickcheck",
@ -3138,7 +3092,7 @@ dependencies = [
"futures-rustls 0.22.2", "futures-rustls 0.22.2",
"libp2p-core", "libp2p-core",
"libp2p-dns", "libp2p-dns",
"libp2p-identity 0.1.2", "libp2p-identity",
"libp2p-tcp", "libp2p-tcp",
"log", "log",
"parking_lot", "parking_lot",
@ -3347,16 +3301,16 @@ dependencies = [
[[package]] [[package]]
name = "multiaddr" name = "multiaddr"
version = "0.17.1" version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b36f567c7099511fa8612bbbb52dda2419ce0bdbacf31714e3a5ffdb766d3bd" checksum = "92a651988b3ed3ad1bc8c87d016bb92f6f395b84ed1db9b926b32b1fc5a2c8b5"
dependencies = [ dependencies = [
"arrayref", "arrayref",
"byteorder", "byteorder",
"data-encoding", "data-encoding",
"log", "libp2p-identity",
"multibase", "multibase",
"multihash 0.17.0", "multihash",
"percent-encoding", "percent-encoding",
"serde", "serde",
"static_assertions", "static_assertions",
@ -3375,46 +3329,20 @@ dependencies = [
"data-encoding-macro", "data-encoding-macro",
] ]
[[package]]
name = "multihash"
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",
]
[[package]] [[package]]
name = "multihash" name = "multihash"
version = "0.19.0" version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fd59dcc2bbe70baabeac52cd22ae52c55eefe6c38ff11a9439f16a350a939f2" checksum = "2fd59dcc2bbe70baabeac52cd22ae52c55eefe6c38ff11a9439f16a350a939f2"
dependencies = [ dependencies = [
"arbitrary",
"core2", "core2",
"quickcheck",
"rand 0.8.5",
"serde",
"unsigned-varint", "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]] [[package]]
name = "multistream-select" name = "multistream-select"
version = "0.13.0" version = "0.13.0"
@ -3425,7 +3353,7 @@ dependencies = [
"futures", "futures",
"futures_ringbuf", "futures_ringbuf",
"libp2p-core", "libp2p-core",
"libp2p-identity 0.1.2", "libp2p-identity",
"libp2p-plaintext", "libp2p-plaintext",
"libp2p-swarm", "libp2p-swarm",
"libp2p-yamux", "libp2p-yamux",
@ -3620,18 +3548,6 @@ dependencies = [
"sha2 0.10.6", "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]] [[package]]
name = "p256" name = "p256"
version = "0.13.2" version = "0.13.2"
@ -3640,7 +3556,7 @@ checksum = "c9863ad85fa8f4460f9c48cb909d38a0d689dba1f6f6988a5e3e0d31071bcd4b"
dependencies = [ dependencies = [
"ecdsa 0.16.6", "ecdsa 0.16.6",
"elliptic-curve 0.13.4", "elliptic-curve 0.13.4",
"primeorder 0.13.1", "primeorder",
"sha2 0.10.6", "sha2 0.10.6",
] ]
@ -3785,7 +3701,6 @@ dependencies = [
"async-trait", "async-trait",
"futures", "futures",
"libp2p", "libp2p",
"multiaddr",
] ]
[[package]] [[package]]
@ -3896,15 +3811,6 @@ version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" 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]] [[package]]
name = "primeorder" name = "primeorder"
version = "0.13.1" version = "0.13.1"
@ -3914,40 +3820,6 @@ dependencies = [
"elliptic-curve 0.13.4", "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]] [[package]]
name = "proc-macro-warning" name = "proc-macro-warning"
version = "0.4.1" version = "0.4.1"
@ -4603,15 +4475,6 @@ dependencies = [
"serde_derive", "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]] [[package]]
name = "serde_cbor" name = "serde_cbor"
version = "0.11.2" version = "0.11.2"
@ -5091,15 +4954,6 @@ dependencies = [
"tracing", "tracing",
] ]
[[package]]
name = "toml"
version = "0.5.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "tower-service" name = "tower-service"
version = "0.3.2" version = "0.3.2"

View File

@ -70,7 +70,7 @@ libp2p-dns = { version = "0.40.0", path = "transports/dns" }
libp2p-floodsub = { version = "0.43.0", path = "protocols/floodsub" } libp2p-floodsub = { version = "0.43.0", path = "protocols/floodsub" }
libp2p-gossipsub = { version = "0.45.0", path = "protocols/gossipsub" } libp2p-gossipsub = { version = "0.45.0", path = "protocols/gossipsub" }
libp2p-identify = { version = "0.43.0", path = "protocols/identify" } libp2p-identify = { version = "0.43.0", path = "protocols/identify" }
libp2p-identity = { version = "0.1.0" } libp2p-identity = { version = "0.2.0" }
libp2p-kad = { version = "0.44.0", path = "protocols/kad" } libp2p-kad = { version = "0.44.0", path = "protocols/kad" }
libp2p-mdns = { version = "0.44.0", path = "protocols/mdns" } libp2p-mdns = { version = "0.44.0", path = "protocols/mdns" }
libp2p-metrics = { version = "0.13.0", path = "misc/metrics" } libp2p-metrics = { version = "0.13.0", path = "misc/metrics" }
@ -99,3 +99,15 @@ multistream-select = { version = "0.13.0", path = "misc/multistream-select" }
quick-protobuf-codec = { version = "0.2.0", path = "misc/quick-protobuf-codec" } quick-protobuf-codec = { version = "0.2.0", path = "misc/quick-protobuf-codec" }
quickcheck = { package = "quickcheck-ext", path = "misc/quickcheck-ext" } quickcheck = { package = "quickcheck-ext", path = "misc/quickcheck-ext" }
rw-stream-sink = { version = "0.4.0", path = "misc/rw-stream-sink" } rw-stream-sink = { version = "0.4.0", path = "misc/rw-stream-sink" }
multiaddr = "0.18.0"
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" }

View File

@ -18,8 +18,8 @@ futures-timer = "3"
instant = "0.1.12" instant = "0.1.12"
libp2p-identity = { workspace = true, features = ["peerid", "ed25519"] } libp2p-identity = { workspace = true, features = ["peerid", "ed25519"] }
log = "0.4" log = "0.4"
multiaddr = { version = "0.17.1" } multiaddr = { workspace = true }
multihash = { version = "0.17.0", default-features = false, features = ["std"] } multihash = { workspace = true }
multistream-select = { workspace = true } multistream-select = { workspace = true }
once_cell = "1.18.0" once_cell = "1.18.0"
parking_lot = "0.12.0" parking_lot = "0.12.0"
@ -37,7 +37,7 @@ void = "1"
async-std = { version = "1.6.2", features = ["attributes"] } async-std = { version = "1.6.2", features = ["attributes"] }
libp2p-mplex = { workspace = true } libp2p-mplex = { workspace = true }
libp2p-noise = { workspace = true } libp2p-noise = { workspace = true }
multihash = { version = "0.17.0", default-features = false, features = ["arb"] } multihash = { workspace = true , features = ["arb"] }
quickcheck = { workspace = true } quickcheck = { workspace = true }
libp2p-identity = { workspace = true, features = ["ed25519"] } libp2p-identity = { workspace = true, features = ["ed25519"] }

View File

@ -138,7 +138,7 @@ pub enum FromEnvelopeError {
InvalidPeerRecord(#[from] DecodeError), InvalidPeerRecord(#[from] DecodeError),
/// Failed to decode the peer ID. /// Failed to decode the peer ID.
#[error("Failed to decode bytes as PeerId")] #[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. /// 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")] #[error("The signer of the envelope is different than the peer id in the record")]
MismatchedSignature, MismatchedSignature,

View File

@ -231,7 +231,7 @@ fn main() -> Result<(), Box<dyn Error>> {
.dial( .dial(
opts.relay_address opts.relay_address
.with(Protocol::P2pCircuit) .with(Protocol::P2pCircuit)
.with(Protocol::P2p(opts.remote_peer_id.unwrap().into())), .with(Protocol::P2p(opts.remote_peer_id.unwrap())),
) )
.unwrap(); .unwrap();
} }

View File

@ -11,4 +11,3 @@ async-trait = "0.1"
env_logger = "0.10" env_logger = "0.10"
futures = "0.3.28" futures = "0.3.28"
libp2p = { path = "../../libp2p", features = ["async-std", "dns", "kad", "mdns", "noise", "macros", "tcp", "websocket", "yamux"] } libp2p = { path = "../../libp2p", features = ["async-std", "dns", "kad", "mdns", "noise", "macros", "tcp", "websocket", "yamux"] }
multiaddr = { version = "0.17.1" }

View File

@ -13,5 +13,4 @@ either = "1.8"
env_logger = "0.10" env_logger = "0.10"
futures = "0.3.28" futures = "0.3.28"
libp2p = { path = "../../libp2p", features = ["async-std", "cbor", "dns", "kad", "noise", "macros", "request-response", "tcp", "websocket", "yamux"] } libp2p = { path = "../../libp2p", features = ["async-std", "cbor", "dns", "kad", "noise", "macros", "request-response", "tcp", "websocket", "yamux"] }
multiaddr = { version = "0.17.1" }
void = "1.0.2" void = "1.0.2"

View File

@ -27,7 +27,7 @@ use clap::Parser;
use futures::prelude::*; use futures::prelude::*;
use futures::StreamExt; use futures::StreamExt;
use libp2p::{core::Multiaddr, multiaddr::Protocol, PeerId}; use libp2p::{core::Multiaddr, multiaddr::Protocol};
use std::error::Error; use std::error::Error;
use std::io::Write; use std::io::Write;
use std::path::PathBuf; use std::path::PathBuf;
@ -60,7 +60,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
// In case the user provided an address of a peer on the CLI, dial it. // In case the user provided an address of a peer on the CLI, dial it.
if let Some(addr) = opt.peer { if let Some(addr) = opt.peer {
let peer_id = match addr.iter().last() { 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()), _ => return Err("Expect peer multiaddr to contain peer ID.".into()),
}; };
network_client network_client

View File

@ -302,7 +302,7 @@ impl EventLoop {
let local_peer_id = *self.swarm.local_peer_id(); let local_peer_id = *self.swarm.local_peer_id();
eprintln!( eprintln!(
"Local node is listening on {:?}", "Local node is listening on {:?}",
address.with(Protocol::P2p(local_peer_id.into())) address.with(Protocol::P2p(local_peer_id))
); );
} }
SwarmEvent::IncomingConnection { .. } => {} SwarmEvent::IncomingConnection { .. } => {}
@ -350,10 +350,7 @@ impl EventLoop {
.behaviour_mut() .behaviour_mut()
.kademlia .kademlia
.add_address(&peer_id, peer_addr.clone()); .add_address(&peer_id, peer_addr.clone());
match self match self.swarm.dial(peer_addr.with(Protocol::P2p(peer_id))) {
.swarm
.dial(peer_addr.with(Protocol::P2p(peer_id.into())))
{
Ok(()) => { Ok(()) => {
e.insert(sender); e.insert(sender);
} }

View File

@ -12,4 +12,3 @@ either = "1.8"
env_logger = "0.10" env_logger = "0.10"
futures = "0.3.28" futures = "0.3.28"
libp2p = { path = "../../libp2p", features = ["async-std", "gossipsub", "dns", "identify", "kad", "macros", "noise", "ping", "pnet", "tcp", "websocket", "yamux"] } libp2p = { path = "../../libp2p", features = ["async-std", "gossipsub", "dns", "identify", "kad", "macros", "noise", "ping", "pnet", "tcp", "websocket", "yamux"] }
multiaddr = { version = "0.17.1" }

View File

@ -10,4 +10,3 @@ async-std = { version = "1.12", features = ["attributes"] }
async-trait = "0.1" async-trait = "0.1"
futures = "0.3.28" futures = "0.3.28"
libp2p = { path = "../../libp2p", features = ["async-std", "dns", "macros", "noise", "ping", "tcp", "websocket", "yamux"] } libp2p = { path = "../../libp2p", features = ["async-std", "dns", "macros", "noise", "ping", "tcp", "websocket", "yamux"] }
multiaddr = { version = "0.17.1" }

View File

@ -91,7 +91,7 @@ async fn main() {
let peer = registration.record.peer_id(); let peer = registration.record.peer_id();
log::info!("Discovered peer {} at {}", peer, address); 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 = let address_with_p2p =
if !address.ends_with(&Multiaddr::empty().with(p2p_suffix.clone())) { if !address.ends_with(&Multiaddr::empty().with(p2p_suffix.clone())) {
address.clone().with(p2p_suffix) address.clone().with(p2p_suffix)

View File

@ -112,7 +112,7 @@ libp2p-swarm = { workspace = true }
libp2p-wasm-ext = { workspace = true, optional = true } libp2p-wasm-ext = { workspace = true, optional = true }
libp2p-yamux = { workspace = true, optional = true } libp2p-yamux = { workspace = true, optional = true }
multiaddr = { version = "0.17.0" } multiaddr = { workspace = true }
pin-project = "1.0.0" pin-project = "1.0.0"
[target.'cfg(not(target_arch = "wasm32"))'.dependencies] [target.'cfg(not(target_arch = "wasm32"))'.dependencies]

View File

@ -259,9 +259,6 @@ impl<TBvEv, THandleErr> super::Recorder<libp2p_swarm::SwarmEvent<TBvEv, THandleE
record(OutgoingConnectionError::DialPeerConditionFalse) record(OutgoingConnectionError::DialPeerConditionFalse)
} }
libp2p_swarm::DialError::Aborted => record(OutgoingConnectionError::Aborted), libp2p_swarm::DialError::Aborted => record(OutgoingConnectionError::Aborted),
libp2p_swarm::DialError::InvalidPeerId { .. } => {
record(OutgoingConnectionError::InvalidPeerId)
}
libp2p_swarm::DialError::WrongPeerId { .. } => { libp2p_swarm::DialError::WrongPeerId { .. } => {
record(OutgoingConnectionError::WrongPeerId) record(OutgoingConnectionError::WrongPeerId)
} }
@ -371,7 +368,6 @@ enum OutgoingConnectionError {
NoAddresses, NoAddresses,
DialPeerConditionFalse, DialPeerConditionFalse,
Aborted, Aborted,
InvalidPeerId,
WrongPeerId, WrongPeerId,
TransportMultiaddrNotSupported, TransportMultiaddrNotSupported,
TransportOther, TransportOther,

View File

@ -338,7 +338,7 @@ impl<'a> AsServer<'a> {
let is_valid = addr.iter().all(|proto| match proto { let is_valid = addr.iter().all(|proto| match proto {
Protocol::P2pCircuit => false, Protocol::P2pCircuit => false,
Protocol::P2p(hash) => hash == peer.into(), Protocol::P2p(peer_id) => peer_id == peer,
_ => true, _ => true,
}); });
@ -346,7 +346,7 @@ impl<'a> AsServer<'a> {
return None; return None;
} }
if !addr.iter().any(|p| matches!(p, Protocol::P2p(_))) { if !addr.iter().any(|p| matches!(p, Protocol::P2p(_))) {
addr.push(Protocol::P2p(peer.into())) addr.push(Protocol::P2p(peer))
} }
// Only collect distinct addresses. // Only collect distinct addresses.
distinct.insert(addr.clone()).then_some(addr) distinct.insert(addr.clone()).then_some(addr)
@ -380,26 +380,26 @@ mod test {
let observed_addr = Multiaddr::empty() let observed_addr = Multiaddr::empty()
.with(observed_ip.clone()) .with(observed_ip.clone())
.with(random_port()) .with(random_port())
.with(Protocol::P2p(peer_id.into())); .with(Protocol::P2p(peer_id));
// Valid address with matching peer-id // Valid address with matching peer-id
let demanded_1 = Multiaddr::empty() let demanded_1 = Multiaddr::empty()
.with(random_ip()) .with(random_ip())
.with(random_port()) .with(random_port())
.with(Protocol::P2p(peer_id.into())); .with(Protocol::P2p(peer_id));
// Invalid because peer_id does not match // Invalid because peer_id does not match
let demanded_2 = Multiaddr::empty() let demanded_2 = Multiaddr::empty()
.with(random_ip()) .with(random_ip())
.with(random_port()) .with(random_port())
.with(Protocol::P2p(PeerId::random().into())); .with(Protocol::P2p(PeerId::random()));
// Valid address without peer-id // Valid address without peer-id
let demanded_3 = Multiaddr::empty().with(random_ip()).with(random_port()); let demanded_3 = Multiaddr::empty().with(random_ip()).with(random_port());
// Invalid because relayed // Invalid because relayed
let demanded_4 = Multiaddr::empty() let demanded_4 = Multiaddr::empty()
.with(random_ip()) .with(random_ip())
.with(random_port()) .with(random_port())
.with(Protocol::P2p(PeerId::random().into())) .with(Protocol::P2p(PeerId::random()))
.with(Protocol::P2pCircuit) .with(Protocol::P2pCircuit)
.with(Protocol::P2p(peer_id.into())); .with(Protocol::P2p(peer_id));
let demanded = vec![ let demanded = vec![
demanded_1.clone(), demanded_1.clone(),
demanded_2, demanded_2,
@ -413,7 +413,7 @@ mod test {
let expected_2 = demanded_3 let expected_2 = demanded_3
.replace(0, |_| Some(observed_ip)) .replace(0, |_| Some(observed_ip))
.unwrap() .unwrap()
.with(Protocol::P2p(peer_id.into())); .with(Protocol::P2p(peer_id));
assert_eq!(filtered, vec![expected_1, expected_2]); assert_eq!(filtered, vec![expected_1, expected_2]);
} }
} }

View File

@ -69,7 +69,7 @@ async fn test_dial_back() {
let expect_addr = Multiaddr::empty() let expect_addr = Multiaddr::empty()
.with(Protocol::Ip4(observed_client_ip)) .with(Protocol::Ip4(observed_client_ip))
.with(Protocol::Tcp(client_port)) .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 { let request_probe_id = match server.next_behaviour_event().await {
Event::InboundProbe(InboundProbeEvent::Request { Event::InboundProbe(InboundProbeEvent::Request {
peer, peer,

View File

@ -105,7 +105,7 @@ impl Behaviour {
.iter() .iter()
.cloned() .cloned()
.filter(|a| !a.iter().any(|p| p == Protocol::P2pCircuit)) .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() .collect()
} }

View File

@ -49,9 +49,9 @@ async fn connect() {
async_std::task::spawn(relay.loop_on_next()); async_std::task::spawn(relay.loop_on_next());
let dst_relayed_addr = relay_addr let dst_relayed_addr = relay_addr
.with(Protocol::P2p(relay_peer_id.into())) .with(Protocol::P2p(relay_peer_id))
.with(Protocol::P2pCircuit) .with(Protocol::P2pCircuit)
.with(Protocol::P2p(dst_peer_id.into())); .with(Protocol::P2p(dst_peer_id));
dst.listen_on(dst_relayed_addr.clone()).unwrap(); dst.listen_on(dst_relayed_addr.clone()).unwrap();
wait_for_reservation( 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 { src.wait(move |e| match e {
SwarmEvent::ConnectionEstablished { endpoint, .. } => { SwarmEvent::ConnectionEstablished { endpoint, .. } => {

View File

@ -446,7 +446,7 @@ pub enum Event {
fn multiaddr_matches_peer_id(addr: &Multiaddr, peer_id: &PeerId) -> bool { fn multiaddr_matches_peer_id(addr: &Multiaddr, peer_id: &PeerId) -> bool {
let last_component = addr.iter().last(); let last_component = addr.iter().last();
if let Some(multiaddr::Protocol::P2p(multi_addr_peer_id)) = last_component { 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 true
} }
@ -504,8 +504,8 @@ mod tests {
let addr_without_peer_id: Multiaddr = addr.clone(); let addr_without_peer_id: Multiaddr = addr.clone();
let mut addr_with_other_peer_id = addr.clone(); let mut addr_with_other_peer_id = addr.clone();
addr.push(multiaddr::Protocol::P2p(peer_id.into())); addr.push(multiaddr::Protocol::P2p(peer_id));
addr_with_other_peer_id.push(multiaddr::Protocol::P2p(other_peer_id.into())); 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(&addr, &peer_id));
assert!(!multiaddr_matches_peer_id( assert!(!multiaddr_matches_peer_id(

View File

@ -56,7 +56,7 @@ async fn periodic_identify() {
s1_info.observed_addr, s1_info.observed_addr,
swarm1_memory_listen swarm1_memory_listen
.clone() .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_tcp_listen_addr));
assert!(s1_info.listen_addrs.contains(&swarm2_memory_listen)); assert!(s1_info.listen_addrs.contains(&swarm2_memory_listen));

View File

@ -1907,7 +1907,6 @@ where
match error { match error {
DialError::LocalPeerId { .. } DialError::LocalPeerId { .. }
| DialError::InvalidPeerId { .. }
| DialError::WrongPeerId { .. } | DialError::WrongPeerId { .. }
| DialError::Aborted | DialError::Aborted
| DialError::Denied { .. } | DialError::Denied { .. }

View File

@ -138,7 +138,7 @@ fn build_fully_connected_nodes_with_config(
swarms swarms
} }
fn random_multihash() -> Multihash { fn random_multihash() -> Multihash<64> {
Multihash::wrap(SHA_256_MH, &thread_rng().gen::<[u8; 32]>()).unwrap() 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 mut bob = build_node();
let key = Key::from( 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"), .expect("32 array to fit into 64 byte multihash"),
); );
let record_bob = Record::new(key.clone(), b"bob".to_vec()); let record_bob = Record::new(key.clone(), b"bob".to_vec());
@ -1254,7 +1254,7 @@ fn manual_bucket_inserts() {
.skip(2) .skip(2)
.map(|(a, s)| { .map(|(a, s)| {
let pid = *Swarm::local_peer_id(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) (addr, pid)
}) })
.collect::<HashMap<_, _>>(); .collect::<HashMap<_, _>>();

View File

@ -93,8 +93,8 @@ impl<T> From<Key<T>> for KeyBytes {
} }
} }
impl From<Multihash> for Key<Multihash> { impl<const S: usize> From<Multihash<S>> for Key<Multihash<S>> {
fn from(m: Multihash) -> Self { fn from(m: Multihash<S>) -> Self {
let bytes = KeyBytes(Sha256::digest(m.to_bytes())); let bytes = KeyBytes(Sha256::digest(m.to_bytes()));
Key { preimage: m, bytes } Key { preimage: m, bytes }
} }
@ -205,8 +205,8 @@ mod tests {
} }
} }
impl Arbitrary for Key<Multihash> { impl Arbitrary for Key<Multihash<64>> {
fn arbitrary(g: &mut Gen) -> Key<Multihash> { fn arbitrary(g: &mut Gen) -> Key<Multihash<64>> {
let hash: [u8; 32] = core::array::from_fn(|_| u8::arbitrary(g)); let hash: [u8; 32] = core::array::from_fn(|_| u8::arbitrary(g));
Key::from(Multihash::wrap(SHA_256_MH, &hash).unwrap()) Key::from(Multihash::wrap(SHA_256_MH, &hash).unwrap())
} }

View File

@ -66,8 +66,8 @@ impl From<Vec<u8>> for Key {
} }
} }
impl From<Multihash> for Key { impl<const S: usize> From<Multihash<S>> for Key {
fn from(m: Multihash) -> Key { fn from(m: Multihash<S>) -> Key {
Key::from(m.to_bytes()) Key::from(m.to_bytes())
} }
} }
@ -168,7 +168,7 @@ mod tests {
impl Arbitrary for Key { impl Arbitrary for Key {
fn arbitrary(g: &mut Gen) -> Key { fn arbitrary(g: &mut Gen) -> Key {
let hash: [u8; 32] = core::array::from_fn(|_| u8::arbitrary(g)); 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())
} }
} }

View File

@ -221,7 +221,7 @@ mod tests {
use quickcheck::*; use quickcheck::*;
use rand::Rng; use rand::Rng;
fn random_multihash() -> Multihash { fn random_multihash() -> Multihash<64> {
Multihash::wrap(SHA_256_MH, &rand::thread_rng().gen::<[u8; 32]>()).unwrap() Multihash::wrap(SHA_256_MH, &rand::thread_rng().gen::<[u8; 32]>()).unwrap()
} }

View File

@ -26,7 +26,7 @@ use libp2p_core::{
}; };
use libp2p_identity::PeerId; use libp2p_identity::PeerId;
use std::time::Instant; 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::{ use trust_dns_proto::{
op::Message, op::Message,
rr::{Name, RData}, rr::{Name, RData},
@ -264,16 +264,12 @@ impl MdnsPeer {
}; };
match addr.pop() { match addr.pop() {
Some(Protocol::P2p(peer_id)) => { Some(Protocol::P2p(peer_id)) => {
if let Ok(peer_id) = PeerId::try_from(peer_id) { if let Some(pid) = &my_peer_id {
if let Some(pid) = &my_peer_id { if peer_id != *pid {
if peer_id != *pid { return None;
return None;
}
} else {
my_peer_id.replace(peer_id);
} }
} else { } else {
return None; my_peer_id.replace(peer_id);
} }
} }
_ => return None, _ => 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 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"); let mut addr2: Multiaddr = "/ip6/::1/udp/10000".parse().expect("bad multiaddress");
addr1.push(Protocol::P2p(peer_id.into())); addr1.push(Protocol::P2p(peer_id));
addr2.push(Protocol::P2p(peer_id.into())); addr2.push(Protocol::P2p(peer_id));
let packets = build_query_response( let packets = build_query_response(
0xf8f8, 0xf8f8,

View File

@ -812,7 +812,7 @@ impl Action {
// Add local peer ID in case it isn't present yet. // Add local peer ID in case it isn't present yet.
.filter_map(|a| match a.iter().last()? { .filter_map(|a| match a.iter().last()? {
Protocol::P2p(_) => Some(a), Protocol::P2p(_) => Some(a),
_ => Some(a.with(Protocol::P2p(local_peer_id.into()))), _ => Some(a.with(Protocol::P2p(local_peer_id))),
}) })
.collect(), .collect(),
}), }),

View File

@ -589,7 +589,7 @@ impl Reservation {
.into_iter() .into_iter()
.map(|a| { .map(|a| {
a.with(Protocol::P2pCircuit) a.with(Protocol::P2pCircuit)
.with(Protocol::P2p(local_peer_id.into())) .with(Protocol::P2p(local_peer_id))
}) })
.collect(), .collect(),
}, },

View File

@ -269,9 +269,7 @@ fn parse_relayed_multiaddr(addr: Multiaddr) -> Result<RelayedMultiaddr, Transpor
return Err(Error::MultipleCircuitRelayProtocolsUnsupported.into()); return Err(Error::MultipleCircuitRelayProtocolsUnsupported.into());
} }
} }
Protocol::P2p(hash) => { Protocol::P2p(peer_id) => {
let peer_id = PeerId::from_multihash(hash).map_err(|_| Error::InvalidHash)?;
if before_circuit { if before_circuit {
if relayed_multiaddr.relay_peer_id.is_some() { if relayed_multiaddr.relay_peer_id.is_some() {
return Err(Error::MalformedMultiaddr.into()); return Err(Error::MalformedMultiaddr.into());
@ -380,7 +378,7 @@ impl Stream for Listener {
upgrade: ready(Ok(stream)), upgrade: ready(Ok(stream)),
listener_id, listener_id,
local_addr: relay_addr.with(Protocol::P2pCircuit), 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)), ToListenerMsg::Reservation(Err(())) => self.close(Err(Error::Reservation)),

View File

@ -51,7 +51,7 @@ fn reservation() {
spawn_swarm_on_pool(&pool, relay); spawn_swarm_on_pool(&pool, relay);
let client_addr = relay_addr let client_addr = relay_addr
.with(Protocol::P2p(relay_peer_id.into())) .with(Protocol::P2p(relay_peer_id))
.with(Protocol::P2pCircuit); .with(Protocol::P2pCircuit);
let mut client = build_client(); let mut client = build_client();
let client_peer_id = *client.local_peer_id(); let client_peer_id = *client.local_peer_id();
@ -64,9 +64,7 @@ fn reservation() {
// Wait for initial reservation. // Wait for initial reservation.
pool.run_until(wait_for_reservation( pool.run_until(wait_for_reservation(
&mut client, &mut client,
client_addr client_addr.clone().with(Protocol::P2p(client_peer_id)),
.clone()
.with(Protocol::P2p(client_peer_id.into())),
relay_peer_id, relay_peer_id,
false, // No renewal. false, // No renewal.
)); ));
@ -74,7 +72,7 @@ fn reservation() {
// Wait for renewal. // Wait for renewal.
pool.run_until(wait_for_reservation( pool.run_until(wait_for_reservation(
&mut client, &mut client,
client_addr.with(Protocol::P2p(client_peer_id.into())), client_addr.with(Protocol::P2p(client_peer_id)),
relay_peer_id, relay_peer_id,
true, // Renewal. true, // Renewal.
)); ));
@ -96,11 +94,9 @@ fn new_reservation_to_same_relay_replaces_old() {
let mut client = build_client(); let mut client = build_client();
let client_peer_id = *client.local_peer_id(); let client_peer_id = *client.local_peer_id();
let client_addr = relay_addr let client_addr = relay_addr
.with(Protocol::P2p(relay_peer_id.into())) .with(Protocol::P2p(relay_peer_id))
.with(Protocol::P2pCircuit); .with(Protocol::P2pCircuit);
let client_addr_with_peer_id = client_addr let client_addr_with_peer_id = client_addr.clone().with(Protocol::P2p(client_peer_id));
.clone()
.with(Protocol::P2p(client_peer_id.into()));
let old_listener = client.listen_on(client_addr.clone()).unwrap(); let old_listener = client.listen_on(client_addr.clone()).unwrap();
@ -189,9 +185,9 @@ fn connect() {
let mut dst = build_client(); let mut dst = build_client();
let dst_peer_id = *dst.local_peer_id(); let dst_peer_id = *dst.local_peer_id();
let dst_addr = relay_addr let dst_addr = relay_addr
.with(Protocol::P2p(relay_peer_id.into())) .with(Protocol::P2p(relay_peer_id))
.with(Protocol::P2pCircuit) .with(Protocol::P2pCircuit)
.with(Protocol::P2p(dst_peer_id.into())); .with(Protocol::P2p(dst_peer_id));
dst.listen_on(dst_addr.clone()).unwrap(); dst.listen_on(dst_addr.clone()).unwrap();
@ -242,8 +238,13 @@ async fn connection_established_to(
if peer == relay_peer_id => {} if peer == relay_peer_id => {}
SwarmEvent::ConnectionEstablished { peer_id, .. } if peer_id == other => break, SwarmEvent::ConnectionEstablished { peer_id, .. } if peer_id == other => break,
SwarmEvent::IncomingConnection { send_back_addr, .. } => { SwarmEvent::IncomingConnection { send_back_addr, .. } => {
let peer_id_from_addr = let peer_id_from_addr = send_back_addr
PeerId::try_from_multiaddr(&send_back_addr).expect("to have /p2p"); .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) assert_eq!(peer_id_from_addr, other)
} }
@ -263,9 +264,9 @@ fn handle_dial_failure() {
let mut client = build_client(); let mut client = build_client();
let client_peer_id = *client.local_peer_id(); let client_peer_id = *client.local_peer_id();
let client_addr = relay_addr let client_addr = relay_addr
.with(Protocol::P2p(relay_peer_id.into())) .with(Protocol::P2p(relay_peer_id))
.with(Protocol::P2pCircuit) .with(Protocol::P2pCircuit)
.with(Protocol::P2p(client_peer_id.into())); .with(Protocol::P2p(client_peer_id));
client.listen_on(client_addr).unwrap(); client.listen_on(client_addr).unwrap();
assert!(!pool.run_until(wait_for_dial(&mut client, relay_peer_id))); assert!(!pool.run_until(wait_for_dial(&mut client, relay_peer_id)));
@ -286,7 +287,7 @@ fn reuse_connection() {
let client_addr = relay_addr let client_addr = relay_addr
.clone() .clone()
.with(Protocol::P2p(relay_peer_id.into())) .with(Protocol::P2p(relay_peer_id))
.with(Protocol::P2pCircuit); .with(Protocol::P2pCircuit);
let mut client = build_client(); let mut client = build_client();
let client_peer_id = *client.local_peer_id(); let client_peer_id = *client.local_peer_id();
@ -298,7 +299,7 @@ fn reuse_connection() {
pool.run_until(wait_for_reservation( pool.run_until(wait_for_reservation(
&mut client, &mut client,
client_addr.with(Protocol::P2p(client_peer_id.into())), client_addr.with(Protocol::P2p(client_peer_id)),
relay_peer_id, relay_peer_id,
false, // No renewal. false, // No renewal.
)); ));

View File

@ -56,6 +56,9 @@
- Rename `ConnectionHandlerEvent::Custom` to `ConnectionHandlerEvent::NotifyBehaviour`. See [PR 3955]. - 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]. - Remove deprecated items. See [PR 3956].
[PR 3605]: https://github.com/libp2p/rust-libp2p/pull/3605 [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 3927]: https://github.com/libp2p/rust-libp2p/pull/3927
[PR 3955]: https://github.com/libp2p/rust-libp2p/pull/3955 [PR 3955]: https://github.com/libp2p/rust-libp2p/pull/3955
[PR 3956]: https://github.com/libp2p/rust-libp2p/pull/3956 [PR 3956]: https://github.com/libp2p/rust-libp2p/pull/3956
[PR 4037]: https://github.com/libp2p/rust-libp2p/pull/4037
## 0.42.2 ## 0.42.2

View File

@ -22,7 +22,6 @@
use crate::ConnectionId; use crate::ConnectionId;
use libp2p_core::connection::Endpoint; use libp2p_core::connection::Endpoint;
use libp2p_core::multiaddr::Protocol; use libp2p_core::multiaddr::Protocol;
use libp2p_core::multihash::Multihash;
use libp2p_core::Multiaddr; use libp2p_core::Multiaddr;
use libp2p_identity::PeerId; use libp2p_identity::PeerId;
use std::num::NonZeroU8; use std::num::NonZeroU8;
@ -81,9 +80,21 @@ impl DialOpts {
WithoutPeerId {} 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<PeerId> { pub fn get_peer_id(&self) -> Option<PeerId> {
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. /// Get the [`ConnectionId`] of this dial attempt.
@ -94,40 +105,6 @@ impl DialOpts {
self.connection_id 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 <https://github.com/multiformats/rust-multiaddr/issues/73>.
pub(crate) fn get_or_parse_peer_id(&self) -> Result<Option<PeerId>, 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<Multiaddr> { pub(crate) fn get_addresses(&self) -> Vec<Multiaddr> {
self.addresses.clone() self.addresses.clone()
} }

View File

@ -136,7 +136,6 @@ use futures::{prelude::*, stream::FusedStream};
use libp2p_core::{ use libp2p_core::{
connection::ConnectedPoint, connection::ConnectedPoint,
multiaddr, multiaddr,
multihash::Multihash,
muxing::StreamMuxerBox, muxing::StreamMuxerBox,
transport::{self, ListenerId, TransportError, TransportEvent}, transport::{self, ListenerId, TransportError, TransportEvent},
Endpoint, Multiaddr, Transport, Endpoint, Multiaddr, Transport,
@ -415,9 +414,7 @@ where
pub fn dial(&mut self, opts: impl Into<DialOpts>) -> Result<(), DialError> { pub fn dial(&mut self, opts: impl Into<DialOpts>) -> Result<(), DialError> {
let dial_opts = opts.into(); let dial_opts = opts.into();
let peer_id = dial_opts let peer_id = dial_opts.get_peer_id();
.get_or_parse_peer_id()
.map_err(DialError::InvalidPeerId)?;
let condition = dial_opts.peer_condition(); let condition = dial_opts.peer_condition();
let connection_id = dial_opts.connection_id(); let connection_id = dial_opts.connection_id();
@ -1008,11 +1005,11 @@ where
match event { match event {
ToSwarm::GenerateEvent(event) => return Some(SwarmEvent::Behaviour(event)), ToSwarm::GenerateEvent(event) => return Some(SwarmEvent::Behaviour(event)),
ToSwarm::Dial { opts } => { 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(); let connection_id = opts.connection_id();
if let Ok(()) = self.dial(opts) { if let Ok(()) = self.dial(opts) {
return Some(SwarmEvent::Dialing { return Some(SwarmEvent::Dialing {
peer_id: peer_id.ok().flatten(), peer_id,
connection_id, connection_id,
}); });
} }
@ -1519,8 +1516,6 @@ pub enum DialError {
DialPeerConditionFalse(dial_opts::PeerCondition), DialPeerConditionFalse(dial_opts::PeerCondition),
/// Pending connection attempt has been aborted. /// Pending connection attempt has been aborted.
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. /// The peer identity obtained on the connection did not match the one that was expected.
WrongPeerId { WrongPeerId {
obtained: PeerId, obtained: PeerId,
@ -1561,9 +1556,6 @@ impl fmt::Display for DialError {
f, f,
"Dial error: Pending connection attempt has been aborted." "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!( DialError::WrongPeerId { obtained, endpoint } => write!(
f, f,
"Dial error: Unexpected peer ID {obtained} at {endpoint:?}." "Dial error: Unexpected peer ID {obtained} at {endpoint:?}."
@ -1604,7 +1596,6 @@ impl error::Error for DialError {
DialError::NoAddresses => None, DialError::NoAddresses => None,
DialError::DialPeerConditionFalse(_) => None, DialError::DialPeerConditionFalse(_) => None,
DialError::Aborted => None, DialError::Aborted => None,
DialError::InvalidPeerId { .. } => None,
DialError::WrongPeerId { .. } => None, DialError::WrongPeerId { .. } => None,
DialError::Transport(_) => None, DialError::Transport(_) => None,
DialError::Denied { cause } => Some(cause), DialError::Denied { cause } => Some(cause),
@ -1763,14 +1754,15 @@ fn p2p_addr(peer: Option<PeerId>, addr: Multiaddr) -> Result<Multiaddr, Multiadd
None => return Ok(addr), None => return Ok(addr),
}; };
if let Some(multiaddr::Protocol::P2p(hash)) = addr.iter().last() { if let Some(multiaddr::Protocol::P2p(peer_id)) = addr.iter().last() {
if &hash != peer.as_ref() { if peer_id != peer {
return Err(addr); return Err(addr);
} }
Ok(addr)
} else { return Ok(addr);
Ok(addr.with(multiaddr::Protocol::P2p(peer.into())))
} }
Ok(addr.with(multiaddr::Protocol::P2p(peer)))
} }
#[cfg(test)] #[cfg(test)]
@ -2173,7 +2165,7 @@ mod tests {
})); }));
let other_id = PeerId::random(); 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(); swarm2.dial(other_addr.clone()).unwrap();
@ -2322,7 +2314,7 @@ mod tests {
let failed_addresses = errors.into_iter().map(|(addr, _)| addr).collect::<Vec<_>>(); let failed_addresses = errors.into_iter().map(|(addr, _)| addr).collect::<Vec<_>>();
let expected_addresses = addresses let expected_addresses = addresses
.into_iter() .into_iter()
.map(|addr| addr.with(multiaddr::Protocol::P2p(target.into()))) .map(|addr| addr.with(multiaddr::Protocol::P2p(target)))
.collect::<Vec<_>>(); .collect::<Vec<_>>();
assert_eq!(expected_addresses, failed_addresses); assert_eq!(expected_addresses, failed_addresses);

View File

@ -34,7 +34,7 @@ pub enum PlainTextError {
InvalidPublicKey(libp2p_identity::DecodingError), InvalidPublicKey(libp2p_identity::DecodingError),
/// Failed to parse the [`PeerId`](libp2p_identity::PeerId) from bytes in the protobuf message. /// Failed to parse the [`PeerId`](libp2p_identity::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. /// The peer id of the exchange isn't consistent with the remote public key.
PeerIdMismatch, PeerIdMismatch,
@ -99,8 +99,8 @@ impl From<libp2p_identity::DecodingError> for PlainTextError {
} }
} }
impl From<libp2p_core::multihash::Error> for PlainTextError { impl From<libp2p_identity::ParseError> for PlainTextError {
fn from(err: libp2p_core::multihash::Error) -> PlainTextError { fn from(err: libp2p_identity::ParseError) -> PlainTextError {
PlainTextError::InvalidPeerId(err) PlainTextError::InvalidPeerId(err)
} }
} }

View File

@ -215,7 +215,7 @@ async fn wrong_peerid() {
let (b_peer_id, mut b_transport) = create_default_transport::<quic::async_std::Provider>(); let (b_peer_id, mut b_transport) = create_default_transport::<quic::async_std::Provider>();
let a_addr = start_listening(&mut a_transport, "/ip6/::1/udp/0/quic-v1").await; 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, _)) = let ((a_connected, _, _), (b_connected, _)) =
connect(&mut a_transport, &mut b_transport, a_addr_random_peer).await; connect(&mut a_transport, &mut b_transport, a_addr_random_peer).await;

View File

@ -1280,7 +1280,7 @@ mod tests {
let tcp_observed_addr = Multiaddr::empty() let tcp_observed_addr = Multiaddr::empty()
.with(Protocol::Ip4(observed_ip)) .with(Protocol::Ip4(observed_ip))
.with(Protocol::Tcp(1)) .with(Protocol::Tcp(1))
.with(Protocol::P2p(PeerId::random().into())); .with(Protocol::P2p(PeerId::random()));
let translated = transport let translated = transport
.address_translation(&tcp_listen_addr, &tcp_observed_addr) .address_translation(&tcp_listen_addr, &tcp_observed_addr)

View File

@ -23,7 +23,7 @@ libp2p-noise = { workspace = true }
libp2p-identity = { workspace = true } libp2p-identity = { workspace = true }
log = "0.4" log = "0.4"
sha2 = "0.10.6" sha2 = "0.10.6"
multihash = { version = "0.17.0", default-features = false } multihash = { workspace = true }
quick-protobuf = "0.8" quick-protobuf = "0.8"
quick-protobuf-codec = { workspace = true } quick-protobuf-codec = { workspace = true }
rand = "0.8" rand = "0.8"

View File

@ -18,7 +18,6 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
use multihash::MultihashGeneric;
use sha2::Digest as _; use sha2::Digest as _;
use std::fmt; use std::fmt;
use webrtc::dtls_transport::dtls_fingerprint::RTCDtlsFingerprint; use webrtc::dtls_transport::dtls_fingerprint::RTCDtlsFingerprint;
@ -26,7 +25,7 @@ use webrtc::dtls_transport::dtls_fingerprint::RTCDtlsFingerprint;
const SHA256: &str = "sha-256"; const SHA256: &str = "sha-256";
const MULTIHASH_SHA256_CODE: u64 = 0x12; 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. /// A certificate fingerprint that is assumed to be created using the SHA256 hash algorithm.
#[derive(Eq, PartialEq, Copy, Clone)] #[derive(Eq, PartialEq, Copy, Clone)]
@ -57,7 +56,7 @@ impl Fingerprint {
Some(Self(buf)) Some(Self(buf))
} }
/// Converts [`Multihash`](MultihashGeneric) to [`Fingerprint`]. /// Converts [`Multihash`](multihash::Multihash) to [`Fingerprint`].
pub fn try_from_multihash(hash: Multihash) -> Option<Self> { pub fn try_from_multihash(hash: Multihash) -> Option<Self> {
if hash.code() != MULTIHASH_SHA256_CODE { if hash.code() != MULTIHASH_SHA256_CODE {
// Only support SHA256 for now. // Only support SHA256 for now.
@ -69,7 +68,7 @@ impl Fingerprint {
Some(Self(bytes)) Some(Self(bytes))
} }
/// Converts this fingerprint to [`Multihash`](MultihashGeneric). /// Converts this fingerprint to [`Multihash`](multihash::Multihash).
pub fn to_multihash(self) -> Multihash { pub fn to_multihash(self) -> Multihash {
Multihash::wrap(MULTIHASH_SHA256_CODE, &self.0).expect("fingerprint's len to be 32 bytes") Multihash::wrap(MULTIHASH_SHA256_CODE, &self.0).expect("fingerprint's len to be 32 bytes")
} }

View File

@ -393,7 +393,7 @@ fn socketaddr_to_multiaddr(socket_addr: &SocketAddr, certhash: Option<Fingerprin
let addr = Multiaddr::empty() let addr = Multiaddr::empty()
.with(socket_addr.ip().into()) .with(socket_addr.ip().into())
.with(Protocol::Udp(socket_addr.port())) .with(Protocol::Udp(socket_addr.port()))
.with(Protocol::WebRTC); .with(Protocol::WebRTCDirect);
if let Some(fp) = certhash { if let Some(fp) = certhash {
return addr.with(Protocol::Certhash(fp.to_multihash())); return addr.with(Protocol::Certhash(fp.to_multihash()));
@ -416,7 +416,7 @@ fn parse_webrtc_listen_addr(addr: &Multiaddr) -> Option<SocketAddr> {
let webrtc = iter.next()?; let webrtc = iter.next()?;
let port = match (port, webrtc) { let port = match (port, webrtc) {
(Protocol::Udp(port), Protocol::WebRTC) => port, (Protocol::Udp(port), Protocol::WebRTCDirect) => port,
_ => return None, _ => return None,
}; };
@ -442,7 +442,7 @@ fn parse_webrtc_dial_addr(addr: &Multiaddr) -> Option<(SocketAddr, Fingerprint)>
let certhash = iter.next()?; let certhash = iter.next()?;
let (port, fingerprint) = match (port, webrtc, certhash) { 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)?; let fingerprint = Fingerprint::try_from_multihash(cert_hash)?;
(port, fingerprint) (port, fingerprint)
@ -617,7 +617,10 @@ mod tests {
assert!( assert!(
matches!(listen_addr.iter().nth(1), Some(Protocol::Udp(port)) if port != 0) 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:?}"), e => panic!("Unexpected event: {e:?}"),
} }

View File

@ -338,7 +338,7 @@ mod tests {
let outbound = new_ws_config() let outbound = new_ws_config()
.boxed() .boxed()
.dial(addr.with(Protocol::P2p(PeerId::random().into()))) .dial(addr.with(Protocol::P2p(PeerId::random())))
.unwrap(); .unwrap();
let (a, b) = futures::join!(inbound, outbound); let (a, b) = futures::join!(inbound, outbound);