diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dcfb6bd21be..bf786abaa2f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -76,7 +76,10 @@ jobs: if: > github.event_name == 'pull_request' && !startsWith(github.event.pull_request.title, 'chore') && - !startsWith(github.event.pull_request.title, 'refactor') + !startsWith(github.event.pull_request.title, 'refactor') && + !startsWith(github.event.pull_request.title, 'deps') && + !startsWith(github.event.pull_request.title, 'docs') && + !contains(github.event.pull_request.labels.*.name, 'internal-change') run: | git fetch origin master:master ./scripts/ensure-version-bump-and-changelog.sh diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 322fb255b1c..b9cd82897c2 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -35,5 +35,10 @@ jobs: context: . file: ./misc/server/Dockerfile push: ${{ ! github.event.pull_request.head.repo.fork && github.actor != 'dependabot[bot]' }} # Only push image if we have the required permissions, i.e. not running from a fork + cache-from: ${{ ! github.event.pull_request.head.repo.fork && github.actor != 'dependabot[bot]' && type=s3,mode=max,bucket=libp2p-by-tf-aws-bootstrap,region=us-east-1,prefix=buildCache,name=rust-libp2p-server }} + cache-to: ${{ ! github.event.pull_request.head.repo.fork && github.actor != 'dependabot[bot]' && type=s3,mode=max,bucket=libp2p-by-tf-aws-bootstrap,region=us-east-1,prefix=buildCache,name=rust-libp2p-server }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + env: + AWS_ACCESS_KEY_ID: ${{ vars.TEST_PLANS_BUILD_CACHE_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.TEST_PLANS_BUILD_CACHE_KEY }} diff --git a/Cargo.lock b/Cargo.lock index 1c6eb748030..beae6736fad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -328,7 +328,7 @@ dependencies = [ "log", "parking", "polling", - "rustix 0.37.23", + "rustix 0.37.25", "slab", "socket2 0.4.9", "waker-fn", @@ -368,7 +368,7 @@ dependencies = [ "cfg-if", "event-listener", "futures-lite", - "rustix 0.37.23", + "rustix 0.37.25", "signal-hook", "windows-sys", ] @@ -1159,19 +1159,6 @@ dependencies = [ "rand 0.7.3", ] -[[package]] -name = "curve25519-dalek" -version = "3.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" -dependencies = [ - "byteorder", - "digest 0.9.0", - "rand_core 0.5.1", - "subtle", - "zeroize", -] - [[package]] name = "curve25519-dalek" version = "4.1.1" @@ -1363,7 +1350,7 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7277392b266383ef8396db7fdeb1e77b6c52fed775f5df15bb24f35b72156980" dependencies = [ - "curve25519-dalek 4.1.1", + "curve25519-dalek", "ed25519", "rand_core 0.6.4", "serde", @@ -2643,7 +2630,7 @@ dependencies = [ [[package]] name = "libp2p-identity" -version = "0.2.5" +version = "0.2.7" dependencies = [ "asn1_der", "base64 0.21.4", @@ -2804,10 +2791,10 @@ dependencies = [ [[package]] name = "libp2p-noise" -version = "0.43.1" +version = "0.43.2" dependencies = [ "bytes", - "curve25519-dalek 4.1.1", + "curve25519-dalek", "env_logger 0.10.0", "futures", "futures_ringbuf", @@ -2824,7 +2811,7 @@ dependencies = [ "snow", "static_assertions", "thiserror", - "x25519-dalek 1.1.1", + "x25519-dalek", "zeroize", ] @@ -2897,7 +2884,7 @@ dependencies = [ [[package]] name = "libp2p-pnet" -version = "0.23.0" +version = "0.23.1" dependencies = [ "futures", "libp2p-core", @@ -2947,7 +2934,7 @@ dependencies = [ [[package]] name = "libp2p-relay" -version = "0.16.1" +version = "0.16.2" dependencies = [ "asynchronous-codec", "bytes", @@ -3005,7 +2992,7 @@ dependencies = [ [[package]] name = "libp2p-request-response" -version = "0.25.1" +version = "0.25.2" dependencies = [ "async-std", "async-trait", @@ -3112,7 +3099,7 @@ dependencies = [ [[package]] name = "libp2p-tcp" -version = "0.40.0" +version = "0.40.1" dependencies = [ "async-io", "async-std", @@ -3242,7 +3229,7 @@ dependencies = [ [[package]] name = "libp2p-webrtc-websys" -version = "0.1.0-alpha" +version = "0.2.0-alpha" dependencies = [ "bytes", "futures", @@ -4511,14 +4498,14 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.0" +version = "1.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d119d7c7ca818f8a53c300863d4f87566aac09943aef5b355bb83969dae75d87" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" dependencies = [ "aho-corasick 1.0.2", "memchr", - "regex-automata 0.4.1", - "regex-syntax 0.8.0", + "regex-automata 0.4.3", + "regex-syntax 0.8.2", ] [[package]] @@ -4532,13 +4519,13 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.1" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "465c6fc0621e4abc4187a2bda0937bfd4f722c2730b29562e19689ea796c9a4b" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" dependencies = [ "aho-corasick 1.0.2", "memchr", - "regex-syntax 0.8.0", + "regex-syntax 0.8.2", ] [[package]] @@ -4549,9 +4536,9 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.8.0" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3cbb081b9784b07cceb8824c8583f86db4814d172ab043f3c23f7dc600bf83d" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "relay-server-example" @@ -4790,9 +4777,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.37.23" +version = "0.37.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d69718bf81c6127a49dc64e44a742e8bb9213c0ff8869a22c308f84c1d4ab06" +checksum = "d4eb579851244c2c03e7c24f501c3432bed80b8f720af1d6e5b0e0f01555a035" dependencies = [ "bitflags 1.3.2", "errno", @@ -5231,7 +5218,7 @@ dependencies = [ "aes-gcm 0.9.2", "blake2", "chacha20poly1305", - "curve25519-dalek 4.1.1", + "curve25519-dalek", "rand_core 0.6.4", "ring", "rustc_version", @@ -5694,11 +5681,10 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.37" +version = "0.1.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +checksum = "ee2ef2af84856a50c1d430afce2fdded0a4ec7eda868db86409b4543df0797f9" dependencies = [ - "cfg-if", "log", "pin-project-lite 0.2.12", "tracing-attributes", @@ -5707,9 +5693,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.26" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", @@ -5718,9 +5704,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.31" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", "valuable", @@ -6297,7 +6283,7 @@ dependencies = [ "thiserror", "tokio", "webrtc-util", - "x25519-dalek 2.0.0", + "x25519-dalek", "x509-parser", ] @@ -6562,24 +6548,13 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "x25519-dalek" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a0c105152107e3b96f6a00a65e86ce82d9b125230e1c4302940eca58ff71f4f" -dependencies = [ - "curve25519-dalek 3.2.0", - "rand_core 0.5.1", - "zeroize", -] - [[package]] name = "x25519-dalek" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb66477291e7e8d2b0ff1bcb900bf29489a9692816d79874bea351e7a8b6de96" dependencies = [ - "curve25519-dalek 4.1.1", + "curve25519-dalek", "rand_core 0.6.4", "serde", "zeroize", diff --git a/Cargo.toml b/Cargo.toml index cc84e2a710c..9d5690abf33 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -83,34 +83,34 @@ libp2p-dns = { version = "0.40.1", path = "transports/dns" } libp2p-floodsub = { version = "0.43.0", path = "protocols/floodsub" } libp2p-gossipsub = { version = "0.45.2", path = "protocols/gossipsub" } libp2p-identify = { version = "0.43.1", path = "protocols/identify" } -libp2p-identity = { version = "0.2.5" } +libp2p-identity = { version = "0.2.7" } libp2p-kad = { version = "0.44.6", path = "protocols/kad" } libp2p-mdns = { version = "0.44.0", path = "protocols/mdns" } libp2p-memory-connection-limits = { version = "0.1.0", path = "misc/memory-connection-limits" } libp2p-metrics = { version = "0.13.1", path = "misc/metrics" } libp2p-mplex = { version = "0.40.0", path = "muxers/mplex" } libp2p-muxer-test-harness = { path = "muxers/test-harness" } -libp2p-noise = { version = "0.43.1", path = "transports/noise" } +libp2p-noise = { version = "0.43.2", path = "transports/noise" } libp2p-perf = { version = "0.2.0", path = "protocols/perf" } libp2p-ping = { version = "0.43.1", path = "protocols/ping" } libp2p-plaintext = { version = "0.40.1", path = "transports/plaintext" } -libp2p-pnet = { version = "0.23.0", path = "transports/pnet" } +libp2p-pnet = { version = "0.23.1", path = "transports/pnet" } libp2p-quic = { version = "0.9.3", path = "transports/quic" } -libp2p-relay = { version = "0.16.1", path = "protocols/relay" } +libp2p-relay = { version = "0.16.2", path = "protocols/relay" } libp2p-rendezvous = { version = "0.13.1", path = "protocols/rendezvous" } libp2p-upnp = { version = "0.1.1", path = "protocols/upnp" } -libp2p-request-response = { version = "0.25.1", path = "protocols/request-response" } +libp2p-request-response = { version = "0.25.2", path = "protocols/request-response" } libp2p-server = { version = "0.12.3", path = "misc/server" } libp2p-swarm = { version = "0.44.0", path = "swarm" } libp2p-swarm-derive = { version = "0.34.0", path = "swarm-derive" } libp2p-swarm-test = { version = "0.2.0", path = "swarm-test" } -libp2p-tcp = { version = "0.40.0", path = "transports/tcp" } +libp2p-tcp = { version = "0.40.1", path = "transports/tcp" } libp2p-tls = { version = "0.2.1", path = "transports/tls" } libp2p-uds = { version = "0.39.0", path = "transports/uds" } libp2p-wasm-ext = { version = "0.40.0", path = "transports/wasm-ext" } libp2p-webrtc = { version = "0.6.1-alpha", path = "transports/webrtc" } libp2p-webrtc-utils = { version = "0.1.0", path = "misc/webrtc-utils" } -libp2p-webrtc-websys = { version = "0.1.0-alpha", path = "transports/webrtc-websys" } +libp2p-webrtc-websys = { version = "0.2.0-alpha", path = "transports/webrtc-websys" } libp2p-websocket = { version = "0.42.1", path = "transports/websocket" } libp2p-websocket-websys = { version = "0.2.0", path = "transports/websocket-websys" } libp2p-webtransport-websys = { version = "0.1.0", path = "transports/webtransport-websys" } diff --git a/README.md b/README.md index 6bd528fc680..62573353845 100644 --- a/README.md +++ b/README.md @@ -91,8 +91,8 @@ Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md). - [Forest](https://github.com/ChainSafe/forest) - An implementation of Filecoin written in Rust. - [fuel-core](https://github.com/FuelLabs/fuel-core) - A Rust implementation of the Fuel protocol. - [HotShot](https://github.com/EspressoSystems/HotShot) - Decentralized sequencer in Rust developed by [Espresso Systems](https://www.espressosys.com/). -- [ipfs-embed](https://github.com/ipfs-rust/ipfs-embed) - A small embeddable ipfs implementation -used and maintained by [Actyx](https://www.actyx.com). +- [ipfs-embed](https://github.com/ipfs-rust/ipfs-embed) - A small embeddable ipfs implementation used and maintained by [Actyx](https://www.actyx.com). +- [Homestar](https://github.com/ipvm-wg/homestar) - An InterPlanetary Virtual Machine (IPVM) implementation used and maintained by Fission. - [beetle](https://github.com/n0-computer/beetle) - Next-generation implementation of IPFS for Cloud & Mobile platforms. - [Lighthouse](https://github.com/sigp/lighthouse) - Ethereum consensus client in Rust. - [Locutus](https://github.com/freenet/locutus) - Global, observable, decentralized key-value store. @@ -103,4 +103,4 @@ used and maintained by [Actyx](https://www.actyx.com). - [Subspace](https://github.com/subspace/subspace) - Subspace Network reference implementation - [Substrate](https://github.com/paritytech/substrate) - Framework for blockchain innovation, used by [Polkadot](https://www.parity.io/technologies/polkadot/). -- [Taple](https://github.com/opencanarias/taple-core) - Sustainable DLT for asset and process traceability by [OpenCanarias](https://www.opencanarias.com/en/). \ No newline at end of file +- [Taple](https://github.com/opencanarias/taple-core) - Sustainable DLT for asset and process traceability by [OpenCanarias](https://www.opencanarias.com/en/). diff --git a/clippy.toml b/clippy.toml index f66cc0ac2da..fd38ead0202 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1,3 +1,4 @@ disallowed-methods = [ { path = "futures::channel::mpsc::unbounded", reason = "does not enforce backpressure" }, ] +avoid-breaking-exported-api = false diff --git a/core/Cargo.toml b/core/Cargo.toml index 15288a48d1c..b1fd644f379 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -39,7 +39,7 @@ libp2p-mplex = { path = "../muxers/mplex" } # Using `path` he libp2p-noise = { path = "../transports/noise" } # Using `path` here because this is a cyclic dev-dependency which otherwise breaks releasing. multihash = { workspace = true, features = ["arb"] } quickcheck = { workspace = true } -libp2p-identity = { workspace = true, features = ["ed25519"] } +libp2p-identity = { workspace = true, features = ["ed25519", "rand"] } [features] serde = ["multihash/serde-codec", "dep:serde", "libp2p-identity/serde"] diff --git a/docs/maintainer-handbook.md b/docs/maintainer-handbook.md index 8ec6e6e8c6a..6d36f6fe77c 100644 --- a/docs/maintainer-handbook.md +++ b/docs/maintainer-handbook.md @@ -26,6 +26,14 @@ Once a PR fulfills all merge requirements (approvals, passing CI, etc), applying In case of a trivial code change, maintainers may choose to apply the `trivial` label. This will have mergify approve your PR, thus fulfilling all requirements to automatically queue a PR for merging. +## Changelog entries + +Our CI checks that each crate which is modified gets a changelog entry. +Whilst this is a good default safety-wise, it creates a lot of false-positives for changes that are internal and don't need a changelog entry. + +For PRs that in the categories `chore`, `deps`, `refactor` and `docs`, this check is disabled automatically. +Any other PR needs to explicitly disable this check if desired by applying the `internal-change` label. + ## Dependencies We version our `Cargo.lock` file for better visibility into which dependencies are required for a functional build. diff --git a/examples/rendezvous/src/main.rs b/examples/rendezvous/src/main.rs index e40507c3fc3..a1b811f4f11 100644 --- a/examples/rendezvous/src/main.rs +++ b/examples/rendezvous/src/main.rs @@ -33,7 +33,11 @@ use std::time::Duration; async fn main() -> Result<(), Box> { env_logger::init(); - let mut swarm = libp2p::SwarmBuilder::with_new_identity() + // Results in PeerID 12D3KooWDpJ7As7BWAwRMfu1VU2WCqNjvq387JEYKDBj4kx6nXTN which is + // used as the rendezvous point by the other peer examples. + let keypair = libp2p::identity::Keypair::ed25519_from_bytes([0; 32]).unwrap(); + + let mut swarm = libp2p::SwarmBuilder::with_existing_identity(keypair) .with_tokio() .with_tcp( tcp::Config::default(), diff --git a/identity/CHANGELOG.md b/identity/CHANGELOG.md index 27873e88e01..fbc51fcb200 100644 --- a/identity/CHANGELOG.md +++ b/identity/CHANGELOG.md @@ -1,3 +1,14 @@ +## 0.2.7 + +- Add `rand` feature to gate methods requiring a random number generator, enabling use in restricted environments (e.g. smartcontracts). + This feature is not enabled by default. + See [PR 4349](https://github.com/libp2p/rust-libp2p/pull/4349). + +## 0.2.6 + +- Make `PeerId::to_bytes` and `PeerId::to_base58` take `self` by value to follow Rust convention of `Copy` types. + See [PR 4653](https://github.com/libp2p/rust-libp2p/pull/4653). + ## 0.2.5 - Fix usage of HKDF within `Keypair::derive_secret`. diff --git a/identity/Cargo.toml b/identity/Cargo.toml index 69f8bf55f02..0b9db73983d 100644 --- a/identity/Cargo.toml +++ b/identity/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "libp2p-identity" -version = "0.2.5" +version = "0.2.7" edition = "2021" description = "Data structures and algorithms for identifying peers in libp2p." rust-version = { workspace = true } @@ -14,7 +14,7 @@ categories = ["cryptography"] [dependencies] asn1_der = { version = "0.7.6", optional = true } bs58 = { version = "0.5.0", optional = true } -ed25519-dalek = { version = "2.0", optional = true, features = ["rand_core"] } +ed25519-dalek = { version = "2.0", optional = true } hkdf = { version = "0.12.3", optional = true } libsecp256k1 = { version = "0.7.0", optional = true } log = "0.4" @@ -33,11 +33,12 @@ zeroize = { version = "1.6", optional = true } ring = { version = "0.16.9", features = [ "alloc", "std"], default-features = false, optional = true } [features] -secp256k1 = ["dep:libsecp256k1", "dep:asn1_der", "dep:rand", "dep:sha2", "dep:hkdf", "dep:zeroize"] -ecdsa = ["dep:p256", "dep:rand", "dep:void", "dep:zeroize", "dep:sec1", "dep:sha2", "dep:hkdf"] +secp256k1 = ["dep:libsecp256k1", "dep:asn1_der", "dep:sha2", "dep:hkdf", "dep:zeroize"] +ecdsa = ["dep:p256", "dep:void", "dep:zeroize", "dep:sec1", "dep:sha2", "dep:hkdf"] rsa = ["dep:ring", "dep:asn1_der", "dep:rand", "dep:zeroize"] -ed25519 = ["dep:ed25519-dalek", "dep:rand", "dep:zeroize", "dep:sha2", "dep:hkdf"] -peerid = ["dep:multihash", "dep:bs58", "dep:rand", "dep:thiserror", "dep:sha2", "dep:hkdf" ] +ed25519 = ["dep:ed25519-dalek", "dep:zeroize", "dep:sha2", "dep:hkdf"] +peerid = ["dep:multihash", "dep:bs58", "dep:thiserror", "dep:sha2", "dep:hkdf"] +rand = ["dep:rand", "ed25519-dalek?/rand_core"] [dev-dependencies] quickcheck = { workspace = true } diff --git a/identity/src/ecdsa.rs b/identity/src/ecdsa.rs index 21970f2ffdc..f24410e038b 100644 --- a/identity/src/ecdsa.rs +++ b/identity/src/ecdsa.rs @@ -44,6 +44,7 @@ pub struct Keypair { impl Keypair { /// Generate a new random ECDSA keypair. + #[cfg(feature = "rand")] pub fn generate() -> Keypair { Keypair::from(SecretKey::generate()) } @@ -265,6 +266,7 @@ mod tests { use super::*; #[test] + #[cfg(feature = "rand")] fn sign_verify() { let pair = Keypair::generate(); let pk = pair.public(); diff --git a/identity/src/ed25519.rs b/identity/src/ed25519.rs index 8b6b9e0d1e0..529a4dddea1 100644 --- a/identity/src/ed25519.rs +++ b/identity/src/ed25519.rs @@ -34,6 +34,7 @@ pub struct Keypair(ed25519::SigningKey); impl Keypair { /// Generate a new random Ed25519 keypair. + #[cfg(feature = "rand")] pub fn generate() -> Keypair { Keypair::from(SecretKey::generate()) } @@ -181,6 +182,7 @@ impl fmt::Debug for SecretKey { impl SecretKey { /// Generate a new Ed25519 secret key. + #[cfg(feature = "rand")] pub fn generate() -> SecretKey { let signing = ed25519::SigningKey::generate(&mut rand::rngs::OsRng); SecretKey(signing.to_bytes()) @@ -213,6 +215,7 @@ mod tests { } #[test] + #[cfg(feature = "rand")] fn ed25519_keypair_encode_decode() { fn prop() -> bool { let kp1 = Keypair::generate(); @@ -224,6 +227,7 @@ mod tests { } #[test] + #[cfg(feature = "rand")] fn ed25519_keypair_from_secret() { fn prop() -> bool { let kp1 = Keypair::generate(); @@ -235,6 +239,7 @@ mod tests { } #[test] + #[cfg(feature = "rand")] fn ed25519_signature() { let kp = Keypair::generate(); let pk = kp.public(); diff --git a/identity/src/keypair.rs b/identity/src/keypair.rs index 198296fa4fa..41e2181d2a9 100644 --- a/identity/src/keypair.rs +++ b/identity/src/keypair.rs @@ -102,7 +102,7 @@ enum KeyPairInner { impl Keypair { /// Generate a new Ed25519 keypair. - #[cfg(feature = "ed25519")] + #[cfg(all(feature = "ed25519", feature = "rand"))] pub fn generate_ed25519() -> Keypair { Keypair { keypair: KeyPairInner::Ed25519(ed25519::Keypair::generate()), @@ -110,7 +110,7 @@ impl Keypair { } /// Generate a new Secp256k1 keypair. - #[cfg(feature = "secp256k1")] + #[cfg(all(feature = "secp256k1", feature = "rand"))] pub fn generate_secp256k1() -> Keypair { Keypair { keypair: KeyPairInner::Secp256k1(secp256k1::Keypair::generate()), @@ -118,7 +118,7 @@ impl Keypair { } /// Generate a new ECDSA keypair. - #[cfg(feature = "ecdsa")] + #[cfg(all(feature = "ecdsa", feature = "rand"))] pub fn generate_ecdsa() -> Keypair { Keypair { keypair: KeyPairInner::Ecdsa(ecdsa::Keypair::generate()), @@ -352,7 +352,6 @@ impl Keypair { /// ``` /// # fn main() { /// # use libp2p_identity as identity; - /// /// let key = identity::Keypair::generate_ed25519(); /// /// let new_key = key.derive_secret(b"my encryption key").expect("can derive secret for ed25519"); @@ -926,7 +925,7 @@ mod tests { } #[test] - #[cfg(feature = "ed25519")] + #[cfg(all(feature = "ed25519", feature = "rand"))] fn test_publickey_from_ed25519_public_key() { let pubkey = Keypair::generate_ed25519().public(); let ed25519_pubkey = pubkey @@ -941,7 +940,7 @@ mod tests { } #[test] - #[cfg(feature = "secp256k1")] + #[cfg(all(feature = "secp256k1", feature = "rand"))] fn test_publickey_from_secp256k1_public_key() { let pubkey = Keypair::generate_secp256k1().public(); let secp256k1_pubkey = pubkey @@ -955,7 +954,7 @@ mod tests { } #[test] - #[cfg(feature = "ecdsa")] + #[cfg(all(feature = "ecdsa", feature = "rand"))] fn test_publickey_from_ecdsa_public_key() { let pubkey = Keypair::generate_ecdsa().public(); let ecdsa_pubkey = pubkey.clone().try_into_ecdsa().expect("A ecdsa keypair"); diff --git a/identity/src/lib.rs b/identity/src/lib.rs index 9a6c42374f6..c78e68d1652 100644 --- a/identity/src/lib.rs +++ b/identity/src/lib.rs @@ -114,8 +114,9 @@ pub use keypair::{Keypair, PublicKey}; #[cfg(feature = "peerid")] pub use peer_id::{ParseError, PeerId}; -#[derive(Debug, PartialEq, Eq)] /// The type of key a `KeyPair` is holding. +#[derive(Debug, PartialEq, Eq)] +#[allow(clippy::upper_case_acronyms)] pub enum KeyType { Ed25519, RSA, diff --git a/identity/src/peer_id.rs b/identity/src/peer_id.rs index 60ded4ad37c..1d85fe66ffa 100644 --- a/identity/src/peer_id.rs +++ b/identity/src/peer_id.rs @@ -18,6 +18,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +#[cfg(feature = "rand")] use rand::Rng; use sha2::Digest as _; use std::{convert::TryFrom, fmt, str::FromStr}; @@ -101,6 +102,7 @@ impl PeerId { /// Generates a random peer ID from a cryptographically secure PRNG. /// /// This is useful for randomly walking on a DHT, or for testing purposes. + #[cfg(feature = "rand")] pub fn random() -> PeerId { let peer_id = rand::thread_rng().gen::<[u8; 32]>(); PeerId { @@ -109,12 +111,12 @@ impl PeerId { } /// Returns a raw bytes representation of this `PeerId`. - pub fn to_bytes(&self) -> Vec { + pub fn to_bytes(self) -> Vec { self.multihash.to_bytes() } /// Returns a base-58 encoded string of this `PeerId`. - pub fn to_base58(&self) -> String { + pub fn to_base58(self) -> String { bs58::encode(self.to_bytes()).into_string() } } @@ -247,7 +249,7 @@ mod tests { use super::*; #[test] - #[cfg(feature = "ed25519")] + #[cfg(all(feature = "ed25519", feature = "rand"))] fn peer_id_into_bytes_then_from_bytes() { let peer_id = crate::Keypair::generate_ed25519().public().to_peer_id(); let second = PeerId::from_bytes(&peer_id.to_bytes()).unwrap(); @@ -255,7 +257,7 @@ mod tests { } #[test] - #[cfg(feature = "ed25519")] + #[cfg(all(feature = "ed25519", feature = "rand"))] fn peer_id_to_base58_then_back() { let peer_id = crate::Keypair::generate_ed25519().public().to_peer_id(); let second: PeerId = peer_id.to_base58().parse().unwrap(); @@ -263,6 +265,7 @@ mod tests { } #[test] + #[cfg(feature = "rand")] fn random_peer_id_is_valid() { for _ in 0..5000 { let peer_id = PeerId::random(); diff --git a/identity/src/secp256k1.rs b/identity/src/secp256k1.rs index 94b9b917787..5e1fda2933b 100644 --- a/identity/src/secp256k1.rs +++ b/identity/src/secp256k1.rs @@ -38,6 +38,7 @@ pub struct Keypair { impl Keypair { /// Generate a new sec256k1 `Keypair`. + #[cfg(feature = "rand")] pub fn generate() -> Keypair { Keypair::from(SecretKey::generate()) } @@ -88,6 +89,7 @@ impl fmt::Debug for SecretKey { impl SecretKey { /// Generate a new random Secp256k1 secret key. + #[cfg(feature = "rand")] pub fn generate() -> SecretKey { SecretKey(libsecp256k1::SecretKey::random(&mut rand::thread_rng())) } @@ -226,6 +228,7 @@ mod tests { use super::*; #[test] + #[cfg(feature = "rand")] fn secp256k1_secret_from_bytes() { let sk1 = SecretKey::generate(); let mut sk_bytes = [0; 32]; diff --git a/libp2p/CHANGELOG.md b/libp2p/CHANGELOG.md index 085268c52dd..bd2bd4b40f8 100644 --- a/libp2p/CHANGELOG.md +++ b/libp2p/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.52.4 - unreleased +## 0.52.4 - Introduce `libp2p::websocket_websys` module behind `websocket-websys` feature flag. This supersedes the existing `libp2p::wasm_ext` module which is now deprecated. @@ -8,8 +8,13 @@ See `libp2p::SwarmBuilder` docs on how to use the new builder. Also see [PR 4120]. +- Update `libp2p-identity` version to 0.2.6. + Under the hood, we feature-flagged `libp2p-identity`'s `rand` dependency but it is enabled by default when using `libp2p`. + See [PR 4349]. + [PR 3679]: https://github.com/libp2p/rust-libp2p/pull/3679 [PR 4120]: https://github.com/libp2p/rust-libp2p/pull/4120 +[PR 4349]: https://github.com/libp2p/rust-libp2p/pull/4349 ## 0.52.3 diff --git a/libp2p/Cargo.toml b/libp2p/Cargo.toml index 36c987ee9f2..0e142261f46 100644 --- a/libp2p/Cargo.toml +++ b/libp2p/Cargo.toml @@ -113,7 +113,7 @@ libp2p-dcutr = { workspace = true, optional = true } libp2p-floodsub = { workspace = true, optional = true } libp2p-gossipsub = { workspace = true, optional = true } libp2p-identify = { workspace = true, optional = true } -libp2p-identity = { workspace = true } +libp2p-identity = { workspace = true, features = ["rand"] } libp2p-kad = { workspace = true, optional = true } libp2p-metrics = { workspace = true, optional = true } libp2p-noise = { workspace = true, optional = true } diff --git a/libp2p/src/builder.rs b/libp2p/src/builder.rs index 83541378667..0dbeaa7e2ee 100644 --- a/libp2p/src/builder.rs +++ b/libp2p/src/builder.rs @@ -42,15 +42,15 @@ mod select_security; /// .with_quic() /// .with_other_transport(|_key| DummyTransport::<(PeerId, StreamMuxerBox)>::new())? /// .with_dns()? -/// .with_relay_client( -/// (libp2p_tls::Config::new, libp2p_noise::Config::new), -/// libp2p_yamux::Config::default, -/// )? /// .with_websocket( /// (libp2p_tls::Config::new, libp2p_noise::Config::new), /// libp2p_yamux::Config::default, /// ) /// .await? +/// .with_relay_client( +/// (libp2p_tls::Config::new, libp2p_noise::Config::new), +/// libp2p_yamux::Config::default, +/// )? /// .with_behaviour(|_key, relay| MyBehaviour { relay })? /// .build(); /// # @@ -307,11 +307,11 @@ mod tests { .with_quic() .with_dns() .unwrap() - .with_relay_client(libp2p_tls::Config::new, libp2p_yamux::Config::default) - .unwrap() .with_websocket(libp2p_tls::Config::new, libp2p_yamux::Config::default) .await .unwrap() + .with_relay_client(libp2p_tls::Config::new, libp2p_yamux::Config::default) + .unwrap() .with_bandwidth_logging(); let _: Swarm = builder .with_behaviour(|_key, relay| MyBehaviour { relay }) diff --git a/libp2p/src/builder/phase/dns.rs b/libp2p/src/builder/phase/dns.rs index 1d20cacd26d..ebcb3af54a2 100644 --- a/libp2p/src/builder/phase/dns.rs +++ b/libp2p/src/builder/phase/dns.rs @@ -11,13 +11,16 @@ impl SwarmBuilder Result< - SwarmBuilder>, + SwarmBuilder< + super::provider::AsyncStd, + WebsocketPhase, + >, std::io::Error, > { Ok(SwarmBuilder { keypair: self.keypair, phantom: PhantomData, - phase: RelayPhase { + phase: WebsocketPhase { transport: libp2p_dns::async_std::Transport::system(self.phase.transport).await?, }, }) @@ -29,13 +32,16 @@ impl SwarmBuilder Result< - SwarmBuilder>, + SwarmBuilder< + super::provider::Tokio, + WebsocketPhase, + >, std::io::Error, > { Ok(SwarmBuilder { keypair: self.keypair, phantom: PhantomData, - phase: RelayPhase { + phase: WebsocketPhase { transport: libp2p_dns::tokio::Transport::system(self.phase.transport)?, }, }) @@ -43,11 +49,11 @@ impl SwarmBuilder SwarmBuilder> { - pub(crate) fn without_dns(self) -> SwarmBuilder> { + pub(crate) fn without_dns(self) -> SwarmBuilder> { SwarmBuilder { keypair: self.keypair, phantom: PhantomData, - phase: RelayPhase { + phase: WebsocketPhase { transport: self.phase.transport, }, } @@ -61,8 +67,8 @@ impl SwarmBuilder R, ) -> Result>, R::Error> { self.without_dns() - .without_relay() .without_websocket() + .without_relay() .with_behaviour(constructor) } } diff --git a/libp2p/src/builder/phase/other_transport.rs b/libp2p/src/builder/phase/other_transport.rs index 6a050f4f2de..1453d2d097b 100644 --- a/libp2p/src/builder/phase/other_transport.rs +++ b/libp2p/src/builder/phase/other_transport.rs @@ -74,7 +74,10 @@ impl pub async fn with_dns( self, ) -> Result< - SwarmBuilder>, + SwarmBuilder< + super::provider::AsyncStd, + WebsocketPhase, + >, std::io::Error, > { self.without_any_other_transports().with_dns().await @@ -87,7 +90,10 @@ impl pub fn with_dns( self, ) -> Result< - SwarmBuilder>, + SwarmBuilder< + super::provider::Tokio, + WebsocketPhase, + >, std::io::Error, > { self.without_any_other_transports().with_dns() @@ -105,7 +111,7 @@ impl ) -> Result< SwarmBuilder< Provider, - WebsocketPhase, + BandwidthLoggingPhase, >, SecUpgrade::Error, > where @@ -132,6 +138,7 @@ impl { self.without_any_other_transports() .without_dns() + .without_websocket() .with_relay_client(security_upgrade, multiplexer_upgrade) } } @@ -149,8 +156,8 @@ impl ) { self.without_any_other_transports() .without_dns() - .without_relay() .without_websocket() + .without_relay() .with_bandwidth_logging() } } @@ -163,8 +170,8 @@ impl ) -> Result>, R::Error> { self.without_any_other_transports() .without_dns() - .without_relay() .without_websocket() + .without_relay() .without_bandwidth_logging() .with_behaviour(constructor) } diff --git a/libp2p/src/builder/phase/quic.rs b/libp2p/src/builder/phase/quic.rs index e49b3b07135..47eec66b8d2 100644 --- a/libp2p/src/builder/phase/quic.rs +++ b/libp2p/src/builder/phase/quic.rs @@ -82,7 +82,7 @@ impl SwarmBuilder Result< SwarmBuilder< Provider, - super::websocket::WebsocketPhase, + BandwidthLoggingPhase, >, SecUpgrade::Error, > where @@ -108,6 +108,9 @@ impl SwarmBuilder>::Upgrade as UpgradeInfo>::Info: Send, { self.without_quic() + .without_any_other_transports() + .without_dns() + .without_websocket() .with_relay_client(security_upgrade, multiplexer_upgrade) } @@ -139,8 +142,8 @@ impl SwarmBuilder SwarmBuilder Result< - SwarmBuilder>, + SwarmBuilder< + super::provider::AsyncStd, + WebsocketPhase, + >, std::io::Error, > { self.without_quic() @@ -163,7 +169,10 @@ impl SwarmBuilder Result< - SwarmBuilder>, + SwarmBuilder< + super::provider::Tokio, + WebsocketPhase, + >, std::io::Error, > { self.without_quic() @@ -190,7 +199,7 @@ macro_rules! impl_quic_phase_with_websocket { ) -> Result< SwarmBuilder< $providerPascalCase, - BandwidthLoggingPhase, + RelayPhase, >, super::websocket::WebsocketError, > @@ -218,7 +227,6 @@ macro_rules! impl_quic_phase_with_websocket { self.without_quic() .without_any_other_transports() .without_dns() - .without_relay() .with_websocket(security_upgrade, multiplexer_upgrade) .await } @@ -250,8 +258,8 @@ impl SwarmBuilder SwarmBuilder Result< SwarmBuilder< Provider, - WebsocketPhase, + BandwidthLoggingPhase, >, SecUpgrade::Error, > where @@ -78,20 +78,17 @@ impl SwarmBuilder SwarmBuilder> { pub(crate) fn without_relay( self, - ) -> SwarmBuilder> { + ) -> SwarmBuilder> { SwarmBuilder { keypair: self.keypair, phantom: PhantomData, - phase: WebsocketPhase { + phase: BandwidthLoggingPhase { transport: self.phase.transport, relay_behaviour: NoRelayBehaviour, }, @@ -123,70 +120,6 @@ impl SwarmBuilder R, ) -> Result>, R::Error> { - self.without_relay() - .without_websocket() - .with_behaviour(constructor) + self.without_relay().with_behaviour(constructor) } } -macro_rules! impl_relay_phase_with_websocket { - ($providerKebabCase:literal, $providerPascalCase:ty, $websocketStream:ty) => { - #[cfg(all(feature = $providerKebabCase, not(target_arch = "wasm32"), feature = "websocket"))] - impl SwarmBuilder<$providerPascalCase, RelayPhase> { - pub async fn with_websocket < - SecUpgrade, - SecStream, - SecError, - MuxUpgrade, - MuxStream, - MuxError, - > ( - self, - security_upgrade: SecUpgrade, - multiplexer_upgrade: MuxUpgrade, - ) -> Result< - SwarmBuilder< - $providerPascalCase, - BandwidthLoggingPhase, - >, - super::websocket::WebsocketError, - > - where - SecStream: futures::AsyncRead + futures::AsyncWrite + Unpin + Send + 'static, - SecError: std::error::Error + Send + Sync + 'static, - SecUpgrade: IntoSecurityUpgrade<$websocketStream>, - SecUpgrade::Upgrade: InboundUpgrade, Output = (libp2p_identity::PeerId, SecStream), Error = SecError> + OutboundUpgrade, Output = (libp2p_identity::PeerId, SecStream), Error = SecError> + Clone + Send + 'static, - >>::Future: Send, - >>::Future: Send, - <<>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send, - <>::Upgrade as UpgradeInfo>::Info: Send, - - MuxStream: StreamMuxer + Send + 'static, - MuxStream::Substream: Send + 'static, - MuxStream::Error: Send + Sync + 'static, - MuxUpgrade: IntoMultiplexerUpgrade, - MuxUpgrade::Upgrade: InboundUpgrade, Output = MuxStream, Error = MuxError> + OutboundUpgrade, Output = MuxStream, Error = MuxError> + Clone + Send + 'static, - >>::Future: Send, - >>::Future: Send, - MuxError: std::error::Error + Send + Sync + 'static, - <<>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send, - <>::Upgrade as UpgradeInfo>::Info: Send, - { - self.without_relay() - .with_websocket(security_upgrade, multiplexer_upgrade) - .await - } - } - } -} -impl_relay_phase_with_websocket!( - "async-std", - super::provider::AsyncStd, - rw_stream_sink::RwStreamSink< - libp2p_websocket::BytesConnection, - > -); -impl_relay_phase_with_websocket!( - "tokio", - super::provider::Tokio, - rw_stream_sink::RwStreamSink> -); diff --git a/libp2p/src/builder/phase/tcp.rs b/libp2p/src/builder/phase/tcp.rs index d2b69798252..aee786c869d 100644 --- a/libp2p/src/builder/phase/tcp.rs +++ b/libp2p/src/builder/phase/tcp.rs @@ -176,7 +176,7 @@ macro_rules! impl_tcp_phase_with_websocket { ) -> Result< SwarmBuilder< $providerPascalCase, - BandwidthLoggingPhase, + RelayPhase, >, WebsocketError, > @@ -205,7 +205,6 @@ macro_rules! impl_tcp_phase_with_websocket { .without_quic() .without_any_other_transports() .without_dns() - .without_relay() .with_websocket(security_upgrade, multiplexer_upgrade) .await } diff --git a/libp2p/src/builder/phase/websocket.rs b/libp2p/src/builder/phase/websocket.rs index bc536b4a7d1..0415b3a3b4d 100644 --- a/libp2p/src/builder/phase/websocket.rs +++ b/libp2p/src/builder/phase/websocket.rs @@ -4,15 +4,20 @@ use crate::SwarmBuilder; use libp2p_core::muxing::{StreamMuxer, StreamMuxerBox}; #[cfg(all(not(target_arch = "wasm32"), feature = "websocket"))] use libp2p_core::Transport; -#[cfg(all(not(target_arch = "wasm32"), feature = "websocket"))] +#[cfg(any( + all(not(target_arch = "wasm32"), feature = "websocket"), + feature = "relay" +))] use libp2p_core::{InboundUpgrade, Negotiated, OutboundUpgrade, UpgradeInfo}; -#[cfg(all(not(target_arch = "wasm32"), feature = "websocket"))] +#[cfg(any( + all(not(target_arch = "wasm32"), feature = "websocket"), + feature = "relay" +))] use libp2p_identity::PeerId; use std::marker::PhantomData; -pub struct WebsocketPhase { +pub struct WebsocketPhase { pub(crate) transport: T, - pub(crate) relay_behaviour: R, } macro_rules! impl_websocket_builder { @@ -39,7 +44,7 @@ macro_rules! impl_websocket_builder { /// # } /// ``` #[cfg(all(not(target_arch = "wasm32"), feature = $providerKebabCase, feature = "websocket"))] - impl SwarmBuilder<$providerPascalCase, WebsocketPhase> { + impl SwarmBuilder<$providerPascalCase, WebsocketPhase> { pub async fn with_websocket< SecUpgrade, SecStream, @@ -54,7 +59,7 @@ macro_rules! impl_websocket_builder { ) -> Result< SwarmBuilder< $providerPascalCase, - BandwidthLoggingPhase, + RelayPhase, >, WebsocketError, > @@ -96,11 +101,10 @@ macro_rules! impl_websocket_builder { Ok(SwarmBuilder { keypair: self.keypair, phantom: PhantomData, - phase: BandwidthLoggingPhase { + phase: RelayPhase { transport: websocket_transport .or_transport(self.phase.transport) .map(|either, _| either.into_inner()), - relay_behaviour: self.phase.relay_behaviour, }, }) } @@ -129,15 +133,12 @@ impl_websocket_builder!( rw_stream_sink::RwStreamSink> ); -impl - SwarmBuilder> -{ - pub(crate) fn without_websocket(self) -> SwarmBuilder> { +impl SwarmBuilder> { + pub(crate) fn without_websocket(self) -> SwarmBuilder> { SwarmBuilder { keypair: self.keypair, phantom: PhantomData, - phase: BandwidthLoggingPhase { - relay_behaviour: self.phase.relay_behaviour, + phase: RelayPhase { transport: self.phase.transport, }, } @@ -146,27 +147,51 @@ impl // Shortcuts #[cfg(feature = "relay")] -impl - SwarmBuilder> -{ - pub fn with_behaviour>( +impl SwarmBuilder> { + /// See [`SwarmBuilder::with_relay_client`]. + pub fn with_relay_client( self, - constructor: impl FnOnce(&libp2p_identity::Keypair, libp2p_relay::client::Behaviour) -> R, - ) -> Result>, R::Error> { + security_upgrade: SecUpgrade, + multiplexer_upgrade: MuxUpgrade, + ) -> Result< + SwarmBuilder< + Provider, + BandwidthLoggingPhase, + >, + SecUpgrade::Error, + > where + + SecStream: futures::AsyncRead + futures::AsyncWrite + Unpin + Send + 'static, + SecError: std::error::Error + Send + Sync + 'static, + SecUpgrade: IntoSecurityUpgrade, + SecUpgrade::Upgrade: InboundUpgrade, Output = (PeerId, SecStream), Error = SecError> + OutboundUpgrade, Output = (PeerId, SecStream), Error = SecError> + Clone + Send + 'static, + >>::Future: Send, + >>::Future: Send, + <<>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send, + <>::Upgrade as UpgradeInfo>::Info: Send, + + MuxStream: libp2p_core::muxing::StreamMuxer + Send + 'static, + MuxStream::Substream: Send + 'static, + MuxStream::Error: Send + Sync + 'static, + MuxUpgrade: IntoMultiplexerUpgrade, + MuxUpgrade::Upgrade: InboundUpgrade, Output = MuxStream, Error = MuxError> + OutboundUpgrade, Output = MuxStream, Error = MuxError> + Clone + Send + 'static, + >>::Future: Send, + >>::Future: Send, + MuxError: std::error::Error + Send + Sync + 'static, + <<>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send, + <>::Upgrade as UpgradeInfo>::Info: Send, + { self.without_websocket() - .without_bandwidth_logging() - .with_behaviour(constructor) + .with_relay_client(security_upgrade, multiplexer_upgrade) } } - -impl - SwarmBuilder> -{ +impl SwarmBuilder> { pub fn with_behaviour>( self, constructor: impl FnOnce(&libp2p_identity::Keypair) -> R, ) -> Result>, R::Error> { self.without_websocket() + .without_relay() .without_bandwidth_logging() .with_behaviour(constructor) } diff --git a/misc/metrics/Cargo.toml b/misc/metrics/Cargo.toml index 0cb9840955b..661774dcc8f 100644 --- a/misc/metrics/Cargo.toml +++ b/misc/metrics/Cargo.toml @@ -32,6 +32,9 @@ libp2p-swarm = { workspace = true } once_cell = "1.18.0" prometheus-client = { version = "0.21.2"} +[dev-dependencies] +libp2p-identity = { workspace = true, features = ["rand"] } + # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling [package.metadata.docs.rs] diff --git a/misc/server/Dockerfile b/misc/server/Dockerfile index 72641cc3b2e..90e504f4b11 100644 --- a/misc/server/Dockerfile +++ b/misc/server/Dockerfile @@ -1,19 +1,20 @@ -FROM rust:1.72-bullseye as builder -WORKDIR /usr/src/rust-libp2p-server +# syntax=docker/dockerfile:1.5-labs +FROM rust:1.67.0 as chef +RUN wget -q -O- https://github.com/LukeMathWalker/cargo-chef/releases/download/v0.1.62/cargo-chef-x86_64-unknown-linux-gnu.tar.gz | tar -zx -C /usr/local/bin +RUN cargo install --locked --root /usr/local libp2p-lookup --version 0.6.4 +WORKDIR /app -# Run with access to the target cache to speed up builds -WORKDIR /workspace +FROM chef AS planner +COPY . . +RUN cargo chef prepare --recipe-path recipe.json -RUN --mount=type=cache,target=/usr/local/cargo/registry \ - cargo install --locked --root /usr/local libp2p-lookup --version 0.6.4 - -ADD . . -RUN --mount=type=cache,target=./target \ - --mount=type=cache,target=/usr/local/cargo/registry \ - cargo build --release --package libp2p-server - -RUN --mount=type=cache,target=./target \ - mv ./target/release/libp2p-server /usr/local/bin/libp2p-server +FROM chef AS builder +COPY --from=planner /app/recipe.json recipe.json +# Build dependencies - this is the caching Docker layer! +RUN cargo chef cook --release --package libp2p-server --recipe-path recipe.json +# Build application +COPY . . +RUN cargo build --release --package libp2p-server FROM gcr.io/distroless/cc COPY --from=builder /usr/local/bin/libp2p-server /usr/local/bin/libp2p-lookup /usr/local/bin/ diff --git a/muxers/mplex/Cargo.toml b/muxers/mplex/Cargo.toml index aca3ec6eadf..4501546adc1 100644 --- a/muxers/mplex/Cargo.toml +++ b/muxers/mplex/Cargo.toml @@ -28,6 +28,7 @@ async-std = { version = "1.7.0", features = ["attributes"] } criterion = "0.5" env_logger = "0.10" futures = "0.3" +libp2p-identity = { workspace = true, features = ["rand"] } libp2p-muxer-test-harness = { path = "../test-harness" } libp2p-plaintext = { workspace = true } libp2p-tcp = { workspace = true, features = ["async-io"] } diff --git a/protocols/gossipsub/CHANGELOG.md b/protocols/gossipsub/CHANGELOG.md index e8e216e29ca..0e070804082 100644 --- a/protocols/gossipsub/CHANGELOG.md +++ b/protocols/gossipsub/CHANGELOG.md @@ -1,10 +1,22 @@ -## 0.45.2 - unreleased +## 0.45.2 - Deprecate `gossipsub::Config::idle_timeout` in favor of `SwarmBuilder::idle_connection_timeout`. See [PR 4648]. + + [PR 4648]: (https://github.com/libp2p/rust-libp2p/pull/4648) + + ## 0.45.1 - Add getter function to obtain `TopicScoreParams`. diff --git a/protocols/gossipsub/Cargo.toml b/protocols/gossipsub/Cargo.toml index 7a983d66c99..941efc47aea 100644 --- a/protocols/gossipsub/Cargo.toml +++ b/protocols/gossipsub/Cargo.toml @@ -26,13 +26,13 @@ getrandom = "0.2.9" hex_fmt = "0.3.0" instant = "0.1.12" libp2p-core = { workspace = true } -libp2p-identity = { workspace = true } +libp2p-identity = { workspace = true, features = ["rand"] } libp2p-swarm = { workspace = true } log = "0.4.20" quick-protobuf = "0.8" quick-protobuf-codec = { workspace = true } rand = "0.8" -regex = "1.10.0" +regex = "1.10.2" serde = { version = "1", optional = true, features = ["derive"] } sha2 = "0.10.8" smallvec = "1.11.1" diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index 98f1a71efdf..6f5c14e5b67 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -2787,7 +2787,7 @@ where let signature = { let message = proto::Message { - from: Some(author.clone().to_bytes()), + from: Some(author.to_bytes()), data: Some(data.clone()), seqno: Some(sequence_number.to_be_bytes().to_vec()), topic: topic.clone().into_string(), diff --git a/protocols/gossipsub/src/handler.rs b/protocols/gossipsub/src/handler.rs index 8508e026cee..f152b51ba14 100644 --- a/protocols/gossipsub/src/handler.rs +++ b/protocols/gossipsub/src/handler.rs @@ -444,6 +444,7 @@ impl ConnectionHandler for Handler { return KeepAlive::Yes; } + #[allow(deprecated)] KeepAlive::Until(handler.last_io_activity + handler.idle_timeout) } Handler::Disabled(_) => KeepAlive::No, diff --git a/protocols/identify/CHANGELOG.md b/protocols/identify/CHANGELOG.md index 0e8812b1b42..2b0488441c9 100644 --- a/protocols/identify/CHANGELOG.md +++ b/protocols/identify/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.43.1 - unreleased +## 0.43.1 - Handle partial push messages. Previously, push messages with partial information were ignored. diff --git a/protocols/kad/CHANGELOG.md b/protocols/kad/CHANGELOG.md index cfc0f325308..55a40b914e6 100644 --- a/protocols/kad/CHANGELOG.md +++ b/protocols/kad/CHANGELOG.md @@ -1,12 +1,23 @@ -## 0.44.6 - unreleased +## 0.44.6 -- Rename `Kademlia` symbols to follow naming convention. +- Rename `Kademlia` symbols to follow naming convention. See [PR 4547]. - - Fix a bug where we didn't detect a remote peer moving into client-state. See [PR 4639](https://github.com/libp2p/rust-libp2p/pull/4639). +- Re-export `NodeStatus`. + See [PR 4645]. +- Deprecate `kad::Config::set_connection_idle_timeout` in favor of `SwarmBuilder::idle_connection_timeout`. + See [PR 4675]. [PR 4547]: https://github.com/libp2p/rust-libp2p/pull/4547 +[PR 4645]: https://github.com/libp2p/rust-libp2p/pull/4645 +[PR 4675]: https://github.com/libp2p/rust-libp2p/pull/4675 + + ## 0.44.5 - Migrate to `quick-protobuf-codec` crate for codec logic. diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index f97f4ba03ad..7e8b67b7cc2 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -22,7 +22,7 @@ libp2p-core = { workspace = true } libp2p-swarm = { workspace = true } quick-protobuf = "0.8" quick-protobuf-codec = { workspace = true } -libp2p-identity = { workspace = true } +libp2p-identity = { workspace = true, features = ["rand"] } rand = "0.8" sha2 = "0.10.8" smallvec = "1.11.1" diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs index a655d360af7..54dd32ca09f 100644 --- a/protocols/kad/src/behaviour.rs +++ b/protocols/kad/src/behaviour.rs @@ -43,9 +43,9 @@ use libp2p_swarm::behaviour::{ }; use libp2p_swarm::{ dial_opts::{self, DialOpts}, - ConnectionDenied, ConnectionId, DialError, ExternalAddresses, ListenAddresses, - NetworkBehaviour, NotifyHandler, PollParameters, StreamProtocol, THandler, THandlerInEvent, - THandlerOutEvent, ToSwarm, + ConnectionDenied, ConnectionHandler, ConnectionId, DialError, ExternalAddresses, + ListenAddresses, NetworkBehaviour, NotifyHandler, PollParameters, StreamProtocol, THandler, + THandlerInEvent, THandlerOutEvent, ToSwarm, }; use log::{debug, info, warn}; use smallvec::SmallVec; @@ -372,6 +372,9 @@ impl Config { } /// Sets the amount of time to keep connections alive when they're idle. + #[deprecated( + note = "Set a global idle connection timeout via `SwarmBuilder::idle_connection_timeout` instead." + )] pub fn set_connection_idle_timeout(&mut self, duration: Duration) -> &mut Self { self.connection_idle_timeout = duration; self @@ -1903,29 +1906,8 @@ where self.address_failed(peer_id, addr); } - // When a connection is established, we don't know yet whether the - // remote supports the configured protocol name. Only once a connection - // handler reports [`HandlerEvent::ProtocolConfirmed`] do we - // update the local routing table. - // Peer's first connection. if other_established == 0 { - // Queue events for sending pending RPCs to the connected peer. - // There can be only one pending RPC for a particular peer and query per definition. - for (peer_id, event) in self.queries.iter_mut().filter_map(|q| { - q.inner - .pending_rpcs - .iter() - .position(|(p, _)| p == &peer_id) - .map(|p| q.inner.pending_rpcs.remove(p)) - }) { - self.queued_events.push_back(ToSwarm::NotifyHandler { - peer_id, - event, - handler: NotifyHandler::Any, - }); - } - self.connected_peers.insert(peer_id); } } @@ -2043,6 +2025,27 @@ where self.connected_peers.remove(&peer_id); } } + + /// Preloads a new [`Handler`] with requests that are waiting to be sent to the newly connected peer. + fn preload_new_handler( + &mut self, + handler: &mut Handler, + connection_id: ConnectionId, + peer: PeerId, + ) { + self.connections.insert(connection_id, peer); + // Queue events for sending pending RPCs to the connected peer. + // There can be only one pending RPC for a particular peer and query per definition. + for (_peer_id, event) in self.queries.iter_mut().filter_map(|q| { + q.inner + .pending_rpcs + .iter() + .position(|(p, _)| p == &peer) + .map(|p| q.inner.pending_rpcs.remove(p)) + }) { + handler.on_behaviour_event(event) + } + } } /// Exponentially decrease the given duration (base 2). @@ -2068,16 +2071,17 @@ where local_addr: local_addr.clone(), send_back_addr: remote_addr.clone(), }; - self.connections.insert(connection_id, peer); - - Ok(Handler::new( + let mut handler = Handler::new( self.protocol_config.clone(), self.connection_idle_timeout, connected_point, peer, self.mode, connection_id, - )) + ); + self.preload_new_handler(&mut handler, connection_id, peer); + + Ok(handler) } fn handle_established_outbound_connection( @@ -2091,16 +2095,17 @@ where address: addr.clone(), role_override, }; - self.connections.insert(connection_id, peer); - - Ok(Handler::new( + let mut handler = Handler::new( self.protocol_config.clone(), self.connection_idle_timeout, connected_point, peer, self.mode, connection_id, - )) + ); + self.preload_new_handler(&mut handler, connection_id, peer); + + Ok(handler) } fn handle_pending_outbound_connection( diff --git a/protocols/kad/src/handler.rs b/protocols/kad/src/handler.rs index 3695c74c50a..fdb927836c7 100644 --- a/protocols/kad/src/handler.rs +++ b/protocols/kad/src/handler.rs @@ -484,6 +484,7 @@ impl Handler { } } + #[allow(deprecated)] let keep_alive = KeepAlive::Until(Instant::now() + idle_timeout); Handler { @@ -769,13 +770,17 @@ impl ConnectionHandler for Handler { } let no_streams = self.outbound_substreams.is_empty() && self.inbound_substreams.is_empty(); - self.keep_alive = match (no_streams, self.keep_alive) { - // No open streams. Preserve the existing idle timeout. - (true, k @ KeepAlive::Until(_)) => k, - // No open streams. Set idle timeout. - (true, _) => KeepAlive::Until(Instant::now() + self.idle_timeout), - // Keep alive for open streams. - (false, _) => KeepAlive::Yes, + + self.keep_alive = { + #[allow(deprecated)] + match (no_streams, self.keep_alive) { + // No open streams. Preserve the existing idle timeout. + (true, k @ KeepAlive::Until(_)) => k, + // No open streams. Set idle timeout. + (true, _) => KeepAlive::Until(Instant::now() + self.idle_timeout), + // Keep alive for open streams. + (false, _) => KeepAlive::Yes, + } }; Poll::Pending diff --git a/protocols/kad/src/kbucket.rs b/protocols/kad/src/kbucket.rs index 08dd3ed4560..b42806fcf3c 100644 --- a/protocols/kad/src/kbucket.rs +++ b/protocols/kad/src/kbucket.rs @@ -72,6 +72,7 @@ mod entry; #[allow(clippy::assign_op_pattern)] mod key; +pub use bucket::NodeStatus; pub use entry::*; use arrayvec::{self, ArrayVec}; diff --git a/protocols/kad/src/lib.rs b/protocols/kad/src/lib.rs index 4f1c7f0f7ec..01ec625de5a 100644 --- a/protocols/kad/src/lib.rs +++ b/protocols/kad/src/lib.rs @@ -72,7 +72,9 @@ pub use behaviour::{ pub use behaviour::{ Behaviour, BucketInserts, Caching, Config, Event, ProgressStep, Quorum, StoreInserts, }; -pub use kbucket::{Distance as KBucketDistance, EntryView, KBucketRef, Key as KBucketKey}; +pub use kbucket::{ + Distance as KBucketDistance, EntryView, KBucketRef, Key as KBucketKey, NodeStatus, +}; pub use protocol::ConnectionType; pub use query::QueryId; pub use record_priv::{store, Key as RecordKey, ProviderRecord, Record}; diff --git a/protocols/perf/Cargo.toml b/protocols/perf/Cargo.toml index c61deb37c29..3a40b0de25d 100644 --- a/protocols/perf/Cargo.toml +++ b/protocols/perf/Cargo.toml @@ -19,7 +19,7 @@ futures = "0.3.28" instant = "0.1.12" libp2p-core = { workspace = true } libp2p-dns = { workspace = true, features = ["tokio"] } -libp2p-identity = { workspace = true } +libp2p-identity = { workspace = true, features = ["rand"] } libp2p-tls = { workspace = true } libp2p-quic = { workspace = true, features = ["tokio"] } libp2p-request-response = { workspace = true } diff --git a/protocols/perf/src/bin/perf.rs b/protocols/perf/src/bin/perf.rs index 418c7fef97f..42c6a182a57 100644 --- a/protocols/perf/src/bin/perf.rs +++ b/protocols/perf/src/bin/perf.rs @@ -419,7 +419,8 @@ async fn swarm() -> Result> { Default::default(), local_peer_id, Config::with_tokio_executor() - .with_substream_upgrade_protocol_override(upgrade::Version::V1Lazy), + .with_substream_upgrade_protocol_override(upgrade::Version::V1Lazy) + .with_idle_connection_timeout(Duration::from_secs(60 * 5)), ); Ok(swarm) diff --git a/protocols/perf/src/client.rs b/protocols/perf/src/client.rs index 03cfe1e117f..0667fb9456a 100644 --- a/protocols/perf/src/client.rs +++ b/protocols/perf/src/client.rs @@ -59,7 +59,6 @@ pub struct Behaviour { impl Default for Behaviour { fn default() -> Self { let mut req_resp_config = request_response::Config::default(); - req_resp_config.set_connection_keep_alive(Duration::from_secs(60 * 5)); req_resp_config.set_request_timeout(Duration::from_secs(60 * 5)); Self { connected: Default::default(), diff --git a/protocols/perf/src/server.rs b/protocols/perf/src/server.rs index a23f188bbc8..b1bca07e507 100644 --- a/protocols/perf/src/server.rs +++ b/protocols/perf/src/server.rs @@ -38,7 +38,6 @@ pub struct Behaviour { impl Default for Behaviour { fn default() -> Self { let mut req_resp_config = request_response::Config::default(); - req_resp_config.set_connection_keep_alive(Duration::from_secs(60 * 5)); req_resp_config.set_request_timeout(Duration::from_secs(60 * 5)); Self { diff --git a/protocols/relay/CHANGELOG.md b/protocols/relay/CHANGELOG.md index 6af89e25d71..a14617102c8 100644 --- a/protocols/relay/CHANGELOG.md +++ b/protocols/relay/CHANGELOG.md @@ -1,3 +1,11 @@ +## 0.16.2 + + + ## 0.16.1 - Export `RateLimiter` type. diff --git a/protocols/relay/Cargo.toml b/protocols/relay/Cargo.toml index 03799a8c77c..3d01a6af09c 100644 --- a/protocols/relay/Cargo.toml +++ b/protocols/relay/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-relay" edition = "2021" rust-version = { workspace = true } description = "Communications relaying for libp2p" -version = "0.16.1" +version = "0.16.2" authors = ["Parity Technologies ", "Max Inden "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -31,6 +31,7 @@ void = "1" [dev-dependencies] env_logger = "0.10.0" +libp2p-identity = { workspace = true, features = ["rand"] } libp2p-ping = { workspace = true } libp2p-plaintext = { workspace = true } libp2p-swarm = { workspace = true, features = ["macros", "async-std"] } diff --git a/protocols/relay/src/behaviour/handler.rs b/protocols/relay/src/behaviour/handler.rs index 895228e807b..fc822e78ce5 100644 --- a/protocols/relay/src/behaviour/handler.rs +++ b/protocols/relay/src/behaviour/handler.rs @@ -883,6 +883,7 @@ impl ConnectionHandler for Handler { && self.circuits.is_empty() && self.active_reservation.is_none() { + #[allow(deprecated)] match self.keep_alive { KeepAlive::Yes => { self.keep_alive = KeepAlive::Until(Instant::now() + Duration::from_secs(10)); diff --git a/protocols/relay/src/priv_client/handler.rs b/protocols/relay/src/priv_client/handler.rs index 25488ac3041..41ac85cfdd2 100644 --- a/protocols/relay/src/priv_client/handler.rs +++ b/protocols/relay/src/priv_client/handler.rs @@ -489,21 +489,24 @@ impl ConnectionHandler for Handler { } // Update keep-alive handling. - if matches!(self.reservation, Reservation::None) - && self.alive_lend_out_substreams.is_empty() - && self.circuit_deny_futs.is_empty() + #[allow(deprecated)] { - match self.keep_alive { - KeepAlive::Yes => { - self.keep_alive = KeepAlive::Until(Instant::now() + Duration::from_secs(10)); + if matches!(self.reservation, Reservation::None) + && self.alive_lend_out_substreams.is_empty() + && self.circuit_deny_futs.is_empty() + { + match self.keep_alive { + KeepAlive::Yes => { + self.keep_alive = + KeepAlive::Until(Instant::now() + Duration::from_secs(10)); + } + KeepAlive::Until(_) => {} + KeepAlive::No => panic!("Handler never sets KeepAlive::No."), } - KeepAlive::Until(_) => {} - KeepAlive::No => panic!("Handler never sets KeepAlive::No."), + } else { + self.keep_alive = KeepAlive::Yes; } - } else { - self.keep_alive = KeepAlive::Yes; } - Poll::Pending } diff --git a/protocols/rendezvous/CHANGELOG.md b/protocols/rendezvous/CHANGELOG.md index 7f204c1c07b..76517d29ce2 100644 --- a/protocols/rendezvous/CHANGELOG.md +++ b/protocols/rendezvous/CHANGELOG.md @@ -1,10 +1,10 @@ -## 0.13.1 - unreleased +## 0.13.1 - Refresh registration upon a change in external addresses. See [PR 4629]. [PR 4629]: https://github.com/libp2p/rust-libp2p/pull/4629 -## 0.13.0 +## 0.13.0 - Changed the signature of the function `client::Behavior::register()`, it returns `Result<(), RegisterError>` now. diff --git a/protocols/request-response/CHANGELOG.md b/protocols/request-response/CHANGELOG.md index 693145c6f72..73f3918a6d8 100644 --- a/protocols/request-response/CHANGELOG.md +++ b/protocols/request-response/CHANGELOG.md @@ -1,3 +1,14 @@ +## 0.25.2 + +- Deprecate `request_response::Config::set_connection_keep_alive` in favor of `SwarmBuilder::idle_connection_timeout`. + See [PR 4029](https://github.com/libp2p/rust-libp2p/pull/4029). + + + ## 0.25.1 - Replace unmaintained `serde_cbor` dependency with `cbor4ii`. diff --git a/protocols/request-response/Cargo.toml b/protocols/request-response/Cargo.toml index b87048bb629..ee1049a96e3 100644 --- a/protocols/request-response/Cargo.toml +++ b/protocols/request-response/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-request-response" edition = "2021" rust-version = { workspace = true } description = "Generic Request/Response Protocols" -version = "0.25.1" +version = "0.25.2" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/protocols/request-response/src/handler.rs b/protocols/request-response/src/handler.rs index 35a2db98bdc..86f036365b8 100644 --- a/protocols/request-response/src/handler.rs +++ b/protocols/request-response/src/handler.rs @@ -336,6 +336,7 @@ where self.outbound.shrink_to_fit(); } + #[allow(deprecated)] if self.inbound.is_empty() && self.keep_alive.is_yes() { // No new inbound or outbound requests. However, we may just have // started the latest inbound or outbound upgrade(s), so make sure diff --git a/protocols/request-response/src/lib.rs b/protocols/request-response/src/lib.rs index 725f469d92f..e54fe01c289 100644 --- a/protocols/request-response/src/lib.rs +++ b/protocols/request-response/src/lib.rs @@ -82,10 +82,10 @@ use handler::Handler; use libp2p_core::{ConnectedPoint, Endpoint, Multiaddr}; use libp2p_identity::PeerId; use libp2p_swarm::{ - behaviour::{AddressChange, ConnectionClosed, ConnectionEstablished, DialFailure, FromSwarm}, + behaviour::{AddressChange, ConnectionClosed, DialFailure, FromSwarm}, dial_opts::DialOpts, - ConnectionDenied, ConnectionId, NetworkBehaviour, NotifyHandler, PollParameters, THandler, - THandlerInEvent, THandlerOutEvent, ToSwarm, + ConnectionDenied, ConnectionHandler, ConnectionId, NetworkBehaviour, NotifyHandler, + PollParameters, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, }; use smallvec::SmallVec; use std::{ @@ -298,6 +298,9 @@ impl Default for Config { impl Config { /// Sets the keep-alive timeout of idle connections. + #[deprecated( + note = "Set a global idle connection timeout via `SwarmBuilder::idle_connection_timeout` instead." + )] pub fn set_connection_keep_alive(&mut self, v: Duration) -> &mut Self { self.connection_keep_alive = v; self @@ -605,36 +608,7 @@ where .iter_mut() .find(|c| c.id == connection_id) .expect("Address change can only happen on an established connection."); - connection.address = new_address; - } - - fn on_connection_established( - &mut self, - ConnectionEstablished { - peer_id, - connection_id, - endpoint, - other_established, - .. - }: ConnectionEstablished, - ) { - let address = match endpoint { - ConnectedPoint::Dialer { address, .. } => Some(address.clone()), - ConnectedPoint::Listener { .. } => None, - }; - self.connected - .entry(peer_id) - .or_default() - .push(Connection::new(connection_id, address)); - - if other_established == 0 { - if let Some(pending) = self.pending_outbound_requests.remove(&peer_id) { - for request in pending { - let request = self.try_send_request(&peer_id, request); - assert!(request.is_none()); - } - } - } + connection.remote_address = new_address; } fn on_connection_closed( @@ -701,6 +675,28 @@ where } } } + + /// Preloads a new [`Handler`] with requests that are waiting to be sent to the newly connected peer. + fn preload_new_handler( + &mut self, + handler: &mut Handler, + peer: PeerId, + connection_id: ConnectionId, + remote_address: Option, + ) { + let mut connection = Connection::new(connection_id, remote_address); + + if let Some(pending_requests) = self.pending_outbound_requests.remove(&peer) { + for request in pending_requests { + connection + .pending_inbound_responses + .insert(request.request_id); + handler.on_behaviour_event(request); + } + } + + self.connected.entry(peer).or_default().push(connection); + } } impl NetworkBehaviour for Behaviour @@ -712,18 +708,22 @@ where fn handle_established_inbound_connection( &mut self, - _: ConnectionId, - _: PeerId, + connection_id: ConnectionId, + peer: PeerId, _: &Multiaddr, _: &Multiaddr, ) -> Result, ConnectionDenied> { - Ok(Handler::new( + let mut handler = Handler::new( self.inbound_protocols.clone(), self.codec.clone(), - self.config.connection_keep_alive, self.config.request_timeout, + self.config.connection_keep_alive, self.next_inbound_id.clone(), - )) + ); + + self.preload_new_handler(&mut handler, peer, connection_id, None); + + Ok(handler) } fn handle_pending_outbound_connection( @@ -740,7 +740,7 @@ where let mut addresses = Vec::new(); if let Some(connections) = self.connected.get(&peer) { - addresses.extend(connections.iter().filter_map(|c| c.address.clone())) + addresses.extend(connections.iter().filter_map(|c| c.remote_address.clone())) } if let Some(more) = self.addresses.get(&peer) { addresses.extend(more.into_iter().cloned()); @@ -751,25 +751,32 @@ where fn handle_established_outbound_connection( &mut self, - _: ConnectionId, - _: PeerId, - _: &Multiaddr, + connection_id: ConnectionId, + peer: PeerId, + remote_address: &Multiaddr, _: Endpoint, ) -> Result, ConnectionDenied> { - Ok(Handler::new( + let mut handler = Handler::new( self.inbound_protocols.clone(), self.codec.clone(), - self.config.connection_keep_alive, self.config.request_timeout, + self.config.connection_keep_alive, self.next_inbound_id.clone(), - )) + ); + + self.preload_new_handler( + &mut handler, + peer, + connection_id, + Some(remote_address.clone()), + ); + + Ok(handler) } fn on_swarm_event(&mut self, event: FromSwarm) { match event { - FromSwarm::ConnectionEstablished(connection_established) => { - self.on_connection_established(connection_established) - } + FromSwarm::ConnectionEstablished(_) => {} FromSwarm::ConnectionClosed(connection_closed) => { self.on_connection_closed(connection_closed) } @@ -924,7 +931,7 @@ const EMPTY_QUEUE_SHRINK_THRESHOLD: usize = 100; /// Internal information tracked for an established connection. struct Connection { id: ConnectionId, - address: Option, + remote_address: Option, /// Pending outbound responses where corresponding inbound requests have /// been received on this connection and emitted via `poll` but have not yet /// been answered. @@ -935,10 +942,10 @@ struct Connection { } impl Connection { - fn new(id: ConnectionId, address: Option) -> Self { + fn new(id: ConnectionId, remote_address: Option) -> Self { Self { id, - address, + remote_address, pending_outbound_responses: Default::default(), pending_inbound_responses: Default::default(), } diff --git a/protocols/upnp/CHANGELOG.md b/protocols/upnp/CHANGELOG.md index 8ebea5e728e..84af542cfd0 100644 --- a/protocols/upnp/CHANGELOG.md +++ b/protocols/upnp/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.1.1 - unreleased +## 0.1.1 - Fix high CPU usage due to repeated generation of failure events. See [PR 4569](https://github.com/libp2p/rust-libp2p/pull/4569). diff --git a/swarm-test/Cargo.toml b/swarm-test/Cargo.toml index eb62b1b06cf..c3d2a993cb9 100644 --- a/swarm-test/Cargo.toml +++ b/swarm-test/Cargo.toml @@ -14,7 +14,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] async-trait = "0.1.73" libp2p-core = { workspace = true } -libp2p-identity = { workspace = true } +libp2p-identity = { workspace = true, features = ["rand"] } libp2p-plaintext = { workspace = true } libp2p-swarm = { workspace = true, features = ["async-std"] } libp2p-tcp = { workspace = true, features = ["async-io"] } diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index b4352d7a022..db43f7845be 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -4,7 +4,7 @@ If you need to transfer state from a `ConnectionHandler` to its `NetworkBehaviour` when a connection closes, use `ConnectionHandler::poll_close`. See [PR 4076](https://github.com/libp2p/rust-libp2p/pull/4076). -## 0.43.6 - unreleased +## 0.43.6 - Deprecate `libp2p::swarm::SwarmBuilder`. Most users should use `libp2p::SwarmBuilder`. @@ -12,6 +12,14 @@ See [PR 4120]. - Make the `Debug` implementation of `StreamProtocol` more concise. See [PR 4631](https://github.com/libp2p/rust-libp2p/pull/4631). +- Fix overflow in `KeepAlive` computation that could occur panic at `Delay::new` if `SwarmBuilder::idle_connection_timeout` is configured too large. + See [PR 4644](https://github.com/libp2p/rust-libp2p/pull/4644). +- Deprecate `KeepAlive::Until`. + Individual protocols should not keep connections alive for longer than necessary. + Users should use `swarm::Config::idle_connection_timeout` instead. + See [PR 4656](https://github.com/libp2p/rust-libp2p/pull/4656). +- Deprecate `keep_alive_timeout` in `OneShotHandlerConfig`. + See [PR 4680](https://github.com/libp2p/rust-libp2p/pull/4680). [PR 4120]: https://github.com/libp2p/rust-libp2p/pull/4120 diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index 3f753f28306..abc08318563 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -357,48 +357,12 @@ where } } - // Ask the handler whether it wants the connection (and the handler itself) - // to be kept alive, which determines the planned shutdown, if any. - let keep_alive = handler.connection_keep_alive(); - match (&mut *shutdown, keep_alive) { - (Shutdown::Later(timer, deadline), KeepAlive::Until(t)) => { - if *deadline != t { - *deadline = t; - if let Some(new_duration) = deadline.checked_duration_since(Instant::now()) - { - let effective_keep_alive = max(new_duration, *idle_timeout); - - timer.reset(effective_keep_alive) - } - } - } - (_, KeepAlive::Until(earliest_shutdown)) => { - let now = Instant::now(); - - if let Some(requested) = earliest_shutdown.checked_duration_since(now) { - let effective_keep_alive = max(requested, *idle_timeout); - - let safe_keep_alive = checked_add_fraction(now, effective_keep_alive); - - // Important: We store the _original_ `Instant` given by the `ConnectionHandler` in the `Later` instance to ensure we can compare it in the above branch. - // This is quite subtle but will hopefully become simpler soon once `KeepAlive::Until` is fully deprecated. See / - *shutdown = Shutdown::Later(Delay::new(safe_keep_alive), earliest_shutdown) - } - } - (_, KeepAlive::No) if idle_timeout == &Duration::ZERO => { - *shutdown = Shutdown::Asap; - } - (Shutdown::Later(_, _), KeepAlive::No) => { - // Do nothing, i.e. let the shutdown timer continue to tick. - } - (_, KeepAlive::No) => { - let now = Instant::now(); - let safe_keep_alive = checked_add_fraction(now, *idle_timeout); - - *shutdown = Shutdown::Later(Delay::new(safe_keep_alive), now + safe_keep_alive); - } - (_, KeepAlive::Yes) => *shutdown = Shutdown::None, - }; + // Compute new shutdown + if let Some(new_shutdown) = + compute_new_shutdown(handler.connection_keep_alive(), shutdown, *idle_timeout) + { + *shutdown = new_shutdown; + } // Check if the connection (and handler) should be shut down. // As long as we're still negotiating substreams, shutdown is always postponed. @@ -494,6 +458,62 @@ fn gather_supported_protocols(handler: &impl ConnectionHandler) -> HashSet Option { + #[allow(deprecated)] + match (current_shutdown, handler_keep_alive) { + (Shutdown::Later(_, deadline), KeepAlive::Until(t)) => { + let now = Instant::now(); + + if *deadline != t { + let deadline = t; + if let Some(new_duration) = deadline.checked_duration_since(Instant::now()) { + let effective_keep_alive = max(new_duration, idle_timeout); + + let safe_keep_alive = checked_add_fraction(now, effective_keep_alive); + return Some(Shutdown::Later(Delay::new(safe_keep_alive), deadline)); + } + } + None + } + (_, KeepAlive::Until(earliest_shutdown)) => { + let now = Instant::now(); + + if let Some(requested) = earliest_shutdown.checked_duration_since(now) { + let effective_keep_alive = max(requested, idle_timeout); + + let safe_keep_alive = checked_add_fraction(now, effective_keep_alive); + + // Important: We store the _original_ `Instant` given by the `ConnectionHandler` in the `Later` instance to ensure we can compare it in the above branch. + // This is quite subtle but will hopefully become simpler soon once `KeepAlive::Until` is fully deprecated. See / + return Some(Shutdown::Later( + Delay::new(safe_keep_alive), + earliest_shutdown, + )); + } + None + } + (_, KeepAlive::No) if idle_timeout == Duration::ZERO => Some(Shutdown::Asap), + (Shutdown::Later(_, _), KeepAlive::No) => { + // Do nothing, i.e. let the shutdown timer continue to tick. + None + } + (_, KeepAlive::No) => { + let now = Instant::now(); + let safe_keep_alive = checked_add_fraction(now, idle_timeout); + + Some(Shutdown::Later( + Delay::new(safe_keep_alive), + now + safe_keep_alive, + )) + } + (_, KeepAlive::Yes) => Some(Shutdown::None), + } +} + /// Repeatedly halves and adds the [`Duration`] to the [`Instant`] until [`Instant::checked_add`] succeeds. /// /// [`Instant`] depends on the underlying platform and has a limit of which points in time it can represent. @@ -998,6 +1018,59 @@ mod tests { assert!(start.checked_add(duration).is_some()) } + #[test] + fn compute_new_shutdown_does_not_panic() { + let _ = env_logger::try_init(); + + #[derive(Debug)] + struct ArbitraryShutdown(Shutdown); + + impl Clone for ArbitraryShutdown { + fn clone(&self) -> Self { + let shutdown = match self.0 { + Shutdown::None => Shutdown::None, + Shutdown::Asap => Shutdown::Asap, + Shutdown::Later(_, instant) => Shutdown::Later( + // compute_new_shutdown does not touch the delay. Delay does not + // implement Clone. Thus use a placeholder delay. + Delay::new(Duration::from_secs(1)), + instant, + ), + }; + + ArbitraryShutdown(shutdown) + } + } + + impl Arbitrary for ArbitraryShutdown { + fn arbitrary(g: &mut Gen) -> Self { + let shutdown = match g.gen_range(1u8..4) { + 1 => Shutdown::None, + 2 => Shutdown::Asap, + 3 => Shutdown::Later( + Delay::new(Duration::from_secs(u32::arbitrary(g) as u64)), + Instant::now() + .checked_add(Duration::arbitrary(g)) + .unwrap_or(Instant::now()), + ), + _ => unreachable!(), + }; + + Self(shutdown) + } + } + + fn prop( + handler_keep_alive: KeepAlive, + current_shutdown: ArbitraryShutdown, + idle_timeout: Duration, + ) { + compute_new_shutdown(handler_keep_alive, ¤t_shutdown.0, idle_timeout); + } + + QuickCheck::new().quickcheck(prop as fn(_, _, _)); + } + struct KeepAliveUntilConnectionHandler { until: Instant, } @@ -1018,6 +1091,7 @@ mod tests { } fn connection_keep_alive(&self) -> KeepAlive { + #[allow(deprecated)] KeepAlive::Until(self.until) } diff --git a/swarm/src/handler.rs b/swarm/src/handler.rs index 0ac77379299..f3d57f96e7b 100644 --- a/swarm/src/handler.rs +++ b/swarm/src/handler.rs @@ -739,6 +739,9 @@ where #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum KeepAlive { /// If nothing new happens, the connection should be closed at the given `Instant`. + #[deprecated( + note = "Use `swarm::Config::with_idle_connection_timeout` instead. See for details." + )] Until(Instant), /// Keep the connection alive. Yes, @@ -759,6 +762,7 @@ impl PartialOrd for KeepAlive { } } +#[allow(deprecated)] impl Ord for KeepAlive { fn cmp(&self, other: &KeepAlive) -> Ordering { use self::KeepAlive::*; @@ -772,6 +776,26 @@ impl Ord for KeepAlive { } } +#[cfg(test)] +impl quickcheck::Arbitrary for KeepAlive { + fn arbitrary(g: &mut quickcheck::Gen) -> Self { + match quickcheck::GenRange::gen_range(g, 1u8..4) { + 1 => + { + #[allow(deprecated)] + KeepAlive::Until( + Instant::now() + .checked_add(Duration::arbitrary(g)) + .unwrap_or(Instant::now()), + ) + } + 2 => KeepAlive::Yes, + 3 => KeepAlive::No, + _ => unreachable!(), + } + } +} + /// A statically declared, empty [`HashSet`] allows us to work around borrow-checker rules for /// [`ProtocolsAdded::from_set`]. The lifetimes don't work unless we have a [`HashSet`] with a `'static' lifetime. static EMPTY_HASHSET: Lazy> = Lazy::new(HashSet::new); diff --git a/swarm/src/handler/one_shot.rs b/swarm/src/handler/one_shot.rs index 439d3f47ee3..473aa50798c 100644 --- a/swarm/src/handler/one_shot.rs +++ b/swarm/src/handler/one_shot.rs @@ -176,6 +176,7 @@ where } else { self.dial_queue.shrink_to_fit(); + #[allow(deprecated)] if self.dial_negotiated == 0 && self.keep_alive.is_yes() { self.keep_alive = KeepAlive::Until(Instant::now() + self.config.keep_alive_timeout); } @@ -199,6 +200,7 @@ where .. }) => { // If we're shutting down the connection for inactivity, reset the timeout. + #[allow(deprecated)] if !self.keep_alive.is_yes() { self.keep_alive = KeepAlive::Until(Instant::now() + self.config.keep_alive_timeout); @@ -231,6 +233,9 @@ where #[derive(Debug)] pub struct OneShotHandlerConfig { /// Keep-alive timeout for idle connections. + #[deprecated( + note = "Set a global idle connection timeout via `SwarmBuilder::idle_connection_timeout` instead." + )] pub keep_alive_timeout: Duration, /// Timeout for outbound substream upgrades. pub outbound_substream_timeout: Duration, @@ -239,6 +244,7 @@ pub struct OneShotHandlerConfig { } impl Default for OneShotHandlerConfig { + #[allow(deprecated)] fn default() -> Self { OneShotHandlerConfig { keep_alive_timeout: Duration::from_secs(10), @@ -258,6 +264,7 @@ mod tests { use void::Void; #[test] + #[allow(deprecated)] fn do_not_keep_idle_connection_alive() { let mut handler: OneShotHandler<_, DeniedUpgrade, Void> = OneShotHandler::new( SubstreamProtocol::new(DeniedUpgrade {}, ()), diff --git a/transports/deflate/CHANGELOG.md b/transports/deflate/CHANGELOG.md index bb1b85d64db..d3c3f99575d 100644 --- a/transports/deflate/CHANGELOG.md +++ b/transports/deflate/CHANGELOG.md @@ -1,10 +1,10 @@ -## 0.40.1 - unreleased +## 0.40.1 - Deprecate in preparation for removal from the workspace. See [issue 4522](https://github.com/libp2p/rust-libp2p/issues/4522) for details. See [PR 4540](https://github.com/libp2p/rust-libp2p/pull/4540). -## 0.40.0 +## 0.40.0 - Raise MSRV to 1.65. See [PR 3715]. diff --git a/transports/dns/CHANGELOG.md b/transports/dns/CHANGELOG.md index 29b5ac4403a..053cb7e591c 100644 --- a/transports/dns/CHANGELOG.md +++ b/transports/dns/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.40.1 - unreleased +## 0.40.1 - Remove `Dns` prefix from types like `TokioDnsConfig` and `DnsConfig` in favor of modules that describe the different variants. Users are encouraged to import the `libp2p::dns` module and refer to types as `dns::tokio::Transport` and `dns::async_std::Transport`. @@ -6,7 +6,7 @@ [PR 4505]: https://github.com/libp2p/rust-libp2p/pull/4505 -## 0.40.0 +## 0.40.0 - Raise MSRV to 1.65. See [PR 3715]. diff --git a/transports/dns/Cargo.toml b/transports/dns/Cargo.toml index 1d5fb1bc7f9..947feb16b26 100644 --- a/transports/dns/Cargo.toml +++ b/transports/dns/Cargo.toml @@ -23,6 +23,7 @@ smallvec = "1.11.1" [dev-dependencies] env_logger = "0.10" +libp2p-identity = { workspace = true, features = ["rand"] } tokio-crate = { package = "tokio", version = "1.0", default-features = false, features = ["rt", "time"] } async-std-crate = { package = "async-std", version = "1.6" } diff --git a/transports/noise/CHANGELOG.md b/transports/noise/CHANGELOG.md index 2a0c31c96a8..63fad1357d7 100644 --- a/transports/noise/CHANGELOG.md +++ b/transports/noise/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.43.2 + +- Update x25519-dalek to 2.0.0. + ## 0.43.1 - Update dependencies. diff --git a/transports/noise/Cargo.toml b/transports/noise/Cargo.toml index 876a3cd34d5..80ab28fd81d 100644 --- a/transports/noise/Cargo.toml +++ b/transports/noise/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-noise" edition = "2021" rust-version = { workspace = true } description = "Cryptographic handshake protocol using the noise framework." -version = "0.43.1" +version = "0.43.2" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -23,7 +23,7 @@ rand = "0.8.3" sha2 = "0.10.8" static_assertions = "1" thiserror = "1.0.49" -x25519-dalek = "1.1.0" +x25519-dalek = "2" zeroize = "1" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] @@ -36,6 +36,7 @@ snow = { version = "0.9.2", features = ["default-resolver"], default-features = env_logger = "0.10.0" futures_ringbuf = "0.4.0" quickcheck = { workspace = true } +libp2p-identity = { workspace = true, features = ["rand"] } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/transports/plaintext/CHANGELOG.md b/transports/plaintext/CHANGELOG.md index dbbc04b5003..cb5a9e238c6 100644 --- a/transports/plaintext/CHANGELOG.md +++ b/transports/plaintext/CHANGELOG.md @@ -1,9 +1,9 @@ -## 0.40.1 - unreleased +## 0.40.1 - Rename `Plaintext2Config` to `Config` to follow naming conventions across repository. See [PR 4535](https://github.com/libp2p/rust-libp2p/pull/4535). -## 0.40.0 +## 0.40.0 - Raise MSRV to 1.65. See [PR 3715]. diff --git a/transports/plaintext/Cargo.toml b/transports/plaintext/Cargo.toml index f58fefb44ca..14c5fd71ae9 100644 --- a/transports/plaintext/Cargo.toml +++ b/transports/plaintext/Cargo.toml @@ -22,7 +22,7 @@ unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] } [dev-dependencies] env_logger = "0.10.0" -libp2p-identity = { workspace = true, features = ["ed25519"] } +libp2p-identity = { workspace = true, features = ["ed25519", "rand"] } quickcheck = { workspace = true } rand = "0.8" futures_ringbuf = "0.4.0" diff --git a/transports/pnet/CHANGELOG.md b/transports/pnet/CHANGELOG.md index 3b425d85dcd..58588823a2f 100644 --- a/transports/pnet/CHANGELOG.md +++ b/transports/pnet/CHANGELOG.md @@ -1,4 +1,12 @@ -## 0.23.0 +## 0.23.1 + + + +## 0.23.0 - Raise MSRV to 1.65. See [PR 3715]. diff --git a/transports/pnet/Cargo.toml b/transports/pnet/Cargo.toml index c6dd93f661a..53b7fe52211 100644 --- a/transports/pnet/Cargo.toml +++ b/transports/pnet/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-pnet" edition = "2021" rust-version = { workspace = true } description = "Private swarm support for libp2p" -version = "0.23.0" +version = "0.23.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -20,7 +20,7 @@ pin-project = "1.1.3" [dev-dependencies] libp2p-core = { workspace = true } -libp2p-identity = { workspace = true, features = ["ed25519", "rsa", "ecdsa","secp256k1"] } +libp2p-identity = { workspace = true, features = ["ed25519", "rsa", "ecdsa","secp256k1", "rand"] } libp2p-noise = { workspace = true } libp2p-swarm = { workspace = true, features = ["tokio"] } libp2p-tcp = { workspace = true, features = ["tokio"] } diff --git a/transports/pnet/src/lib.rs b/transports/pnet/src/lib.rs index 15f42556c62..d8aac22eecd 100644 --- a/transports/pnet/src/lib.rs +++ b/transports/pnet/src/lib.rs @@ -159,6 +159,7 @@ impl fmt::Display for Fingerprint { /// Error when parsing a PreSharedKey #[derive(Clone, Debug, PartialEq, Eq)] +#[allow(clippy::enum_variant_names)] // Maybe fix at some stage, not important now. pub enum KeyParseError { /// file does not have the expected structure InvalidKeyFile, diff --git a/transports/quic/CHANGELOG.md b/transports/quic/CHANGELOG.md index fdd8c24b2a5..e13488cff49 100644 --- a/transports/quic/CHANGELOG.md +++ b/transports/quic/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.9.3 - unreleased +## 0.9.3 - No longer report error when explicit closing of a QUIC endpoint succeeds. See [PR 4621]. diff --git a/transports/quic/Cargo.toml b/transports/quic/Cargo.toml index b7d3537eb4b..b73f33bc669 100644 --- a/transports/quic/Cargo.toml +++ b/transports/quic/Cargo.toml @@ -41,6 +41,7 @@ rustc-args = ["--cfg", "docsrs"] [dev-dependencies] async-std = { version = "1.12.0", features = ["attributes"] } env_logger = "0.10.0" +libp2p-identity = { workspace = true, features = ["rand"] } libp2p-muxer-test-harness = { path = "../../muxers/test-harness" } libp2p-noise = { workspace = true } libp2p-tcp = { workspace = true, features = ["async-io"] } diff --git a/transports/tcp/CHANGELOG.md b/transports/tcp/CHANGELOG.md index f0164b342e5..13134b661c5 100644 --- a/transports/tcp/CHANGELOG.md +++ b/transports/tcp/CHANGELOG.md @@ -1,4 +1,9 @@ -## 0.40.0 +## 0.40.1 + +- Expose `async_io::TcpStream`. + See [PR 4683](https://github.com/libp2p/rust-libp2p/pull/4683). + +## 0.40.0 - Raise MSRV to 1.65. See [PR 3715]. diff --git a/transports/tcp/Cargo.toml b/transports/tcp/Cargo.toml index 0b475ce31d4..8e0f37302ea 100644 --- a/transports/tcp/Cargo.toml +++ b/transports/tcp/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-tcp" edition = "2021" rust-version = { workspace = true } description = "TCP/IP transport protocol for libp2p" -version = "0.40.0" +version = "0.40.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -28,6 +28,7 @@ async-io = ["dep:async-io", "if-watch/smol"] [dev-dependencies] async-std = { version = "1.6.5", features = ["attributes"] } +libp2p-identity = { workspace = true, features = ["rand"] } tokio = { version = "1.33.0", default-features = false, features = ["full"] } env_logger = "0.10.0" diff --git a/transports/tls/Cargo.toml b/transports/tls/Cargo.toml index 7c0ea41b2a0..29928cc21fc 100644 --- a/transports/tls/Cargo.toml +++ b/transports/tls/Cargo.toml @@ -30,7 +30,7 @@ features = ["dangerous_configuration"] # Must enable this to allow for custom ve hex = "0.4.3" hex-literal = "0.4.1" libp2p-core = { workspace = true } -libp2p-identity = { workspace = true, features = ["ed25519", "rsa", "secp256k1", "ecdsa"] } +libp2p-identity = { workspace = true, features = ["ed25519", "rsa", "secp256k1", "ecdsa", "rand"] } libp2p-swarm = { workspace = true, features = ["tokio"] } libp2p-yamux = { workspace = true } tokio = { version = "1.33.0", features = ["full"] } diff --git a/transports/webrtc-websys/CHANGELOG.md b/transports/webrtc-websys/CHANGELOG.md index 7c40c08f1f6..3cc263e2ce5 100644 --- a/transports/webrtc-websys/CHANGELOG.md +++ b/transports/webrtc-websys/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.2.0-alpha + +- Rename `Error::JsError` to `Error::Js`. + See [PR 4653](https://github.com/libp2p/rust-libp2p/pull/4653) + ## 0.1.0-alpha - Initial alpha release. diff --git a/transports/webrtc-websys/Cargo.toml b/transports/webrtc-websys/Cargo.toml index cb90573b1fe..847e54abbd5 100644 --- a/transports/webrtc-websys/Cargo.toml +++ b/transports/webrtc-websys/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT" name = "libp2p-webrtc-websys" repository = "https://github.com/libp2p/rust-libp2p" rust-version = { workspace = true } -version = "0.1.0-alpha" +version = "0.2.0-alpha" publish = true [dependencies] diff --git a/transports/webrtc-websys/src/connection.rs b/transports/webrtc-websys/src/connection.rs index dfdebbc98c0..b026aec0b40 100644 --- a/transports/webrtc-websys/src/connection.rs +++ b/transports/webrtc-websys/src/connection.rs @@ -252,11 +252,11 @@ impl RtcPeerConnection { let sdp = &self .inner .local_description() - .ok_or_else(|| Error::JsError("No local description".to_string()))? + .ok_or_else(|| Error::Js("No local description".to_string()))? .sdp(); - let fingerprint = parse_fingerprint(sdp) - .ok_or_else(|| Error::JsError("No fingerprint in SDP".to_string()))?; + let fingerprint = + parse_fingerprint(sdp).ok_or_else(|| Error::Js("No fingerprint in SDP".to_string()))?; Ok(fingerprint) } diff --git a/transports/webrtc-websys/src/error.rs b/transports/webrtc-websys/src/error.rs index e226dea8069..c95b1caf49b 100644 --- a/transports/webrtc-websys/src/error.rs +++ b/transports/webrtc-websys/src/error.rs @@ -8,7 +8,7 @@ pub enum Error { InvalidMultiaddr(&'static str), #[error("JavaScript error: {0}")] - JsError(String), + Js(String), #[error("JavaScript typecasting failed")] JsCastFailed, @@ -34,7 +34,7 @@ impl Error { "Unknown error".to_string() }; - Error::JsError(s) + Error::Js(s) } } @@ -46,12 +46,12 @@ impl std::convert::From for Error { impl From for Error { fn from(value: String) -> Self { - Error::JsError(value) + Error::Js(value) } } impl From for Error { fn from(value: std::io::Error) -> Self { - Error::JsError(value.to_string()) + Error::Js(value.to_string()) } } diff --git a/transports/webrtc/Cargo.toml b/transports/webrtc/Cargo.toml index 641a966b9f0..d562826c637 100644 --- a/transports/webrtc/Cargo.toml +++ b/transports/webrtc/Cargo.toml @@ -39,6 +39,7 @@ pem = ["webrtc?/pem"] [dev-dependencies] env_logger = "0.10" +libp2p-identity = { workspace = true, features = ["rand"] } tokio = { version = "1.33", features = ["full"] } quickcheck = "1.0.3" diff --git a/transports/websocket-websys/CHANGELOG.md b/transports/websocket-websys/CHANGELOG.md index 1eb27b83071..e9b4cb9d2b3 100644 --- a/transports/websocket-websys/CHANGELOG.md +++ b/transports/websocket-websys/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.2.0 - unreleased +## 0.2.0 - Add Websys Websocket transport. diff --git a/transports/websocket-websys/Cargo.toml b/transports/websocket-websys/Cargo.toml index 985896ad85b..3f7b5d76886 100644 --- a/transports/websocket-websys/Cargo.toml +++ b/transports/websocket-websys/Cargo.toml @@ -32,4 +32,4 @@ rustc-args = ["--cfg", "docsrs"] [dev-dependencies] libp2p-yamux = { workspace = true } libp2p-noise = { workspace = true } -libp2p-identity = { workspace = true } +libp2p-identity = { workspace = true, features = ["rand"] } diff --git a/transports/websocket/Cargo.toml b/transports/websocket/Cargo.toml index 62a5129cbfa..3dc3a710567 100644 --- a/transports/websocket/Cargo.toml +++ b/transports/websocket/Cargo.toml @@ -27,6 +27,7 @@ webpki-roots = "0.25" [dev-dependencies] libp2p-tcp = { workspace = true, features = ["async-io"] } libp2p-dns = { workspace = true, features = ["async-std"] } +libp2p-identity = { workspace = true, features = ["rand"] } async-std = { version = "1.6.5", features = ["attributes"] } rcgen = "0.10.0" diff --git a/wasm-tests/webtransport-tests/Cargo.toml b/wasm-tests/webtransport-tests/Cargo.toml index 8d3f756ecb7..fb3e5db9ba6 100644 --- a/wasm-tests/webtransport-tests/Cargo.toml +++ b/wasm-tests/webtransport-tests/Cargo.toml @@ -9,7 +9,7 @@ publish = false futures = "0.3.28" getrandom = { version = "0.2.9", features = ["js"] } libp2p-core = { workspace = true } -libp2p-identity = { workspace = true } +libp2p-identity = { workspace = true, features = ["rand"] } libp2p-noise = { workspace = true } libp2p-webtransport-websys = { workspace = true } multiaddr = { workspace = true }