Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove multiaddr dependency from libp2p-identity #3656

Merged
merged 18 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
8 changes: 8 additions & 0 deletions identity/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
thomaseizinger marked this conversation as resolved.
Show resolved Hide resolved

# 0.1.1

- Add `From` impl for specific keypairs.
Expand Down
7 changes: 3 additions & 4 deletions identity/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -17,8 +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"
multiaddr = { version = "0.17.0", optional = true }
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"
Expand All @@ -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" }
Expand Down
40 changes: 0 additions & 40 deletions identity/src/peer_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -91,17 +90,6 @@ impl PeerId {
}
}

/// Tries to extract a [`PeerId`] from the given [`Multiaddr`].
///
/// In case the given [`Multiaddr`] ends with `/p2p/<peer-id>`, this function
/// will return the encapsulated [`PeerId`], otherwise it will return `None`.
pub fn try_from_multiaddr(address: &Multiaddr) -> Option<PeerId> {
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.
Expand Down Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion libp2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion misc/allow-block-list/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion misc/connection-limits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion misc/keygen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
2 changes: 1 addition & 1 deletion misc/metrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion muxers/mplex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion protocols/autonat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion protocols/dcutr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion protocols/floodsub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion protocols/gossipsub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion protocols/identify/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion protocols/kad/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion protocols/mdns/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion protocols/perf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
2 changes: 1 addition & 1 deletion protocols/ping/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion protocols/relay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion protocols/rendezvous/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion protocols/request-response/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion swarm-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
4 changes: 2 additions & 2 deletions swarm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion transports/dns/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion transports/noise/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion transports/plaintext/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
2 changes: 1 addition & 1 deletion transports/quic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
Loading