From 4643128b3666657ddb30325ca577058ddeaaac71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?19=E5=B9=B4=E6=A2=A6=E9=86=92?= <3949379+getong@users.noreply.github.com> Date: Thu, 13 Mar 2025 23:44:18 +0800 Subject: [PATCH 1/3] update rand to 0.9 --- Cargo.lock | 387 ++++++++++++------ Cargo.toml | 2 +- core/Cargo.toml | 2 +- examples/autonatv2/Cargo.toml | 2 +- examples/browser-webrtc/Cargo.toml | 2 +- examples/browser-webrtc/src/main.rs | 4 +- examples/stream/Cargo.toml | 2 +- examples/stream/src/main.rs | 2 +- identity/Cargo.toml | 2 +- identity/src/ecdsa.rs | 2 +- identity/src/peer_id.rs | 2 +- identity/src/secp256k1.rs | 2 +- interop-tests/Cargo.toml | 2 +- interop-tests/src/arch.rs | 2 +- libp2p/Cargo.toml | 2 +- misc/connection-limits/Cargo.toml | 2 +- misc/connection-limits/src/lib.rs | 2 +- misc/webrtc-utils/Cargo.toml | 2 +- misc/webrtc-utils/src/sdp.rs | 4 +- muxers/mplex/Cargo.toml | 2 +- protocols/autonat/Cargo.toml | 4 +- .../autonat/src/v1/behaviour/as_client.rs | 4 +- protocols/floodsub/Cargo.toml | 2 +- protocols/gossipsub/Cargo.toml | 4 +- protocols/gossipsub/src/behaviour.rs | 12 +- protocols/gossipsub/src/behaviour/tests.rs | 2 +- protocols/gossipsub/src/rpc_proto.rs | 24 +- protocols/kad/Cargo.toml | 2 +- protocols/kad/src/behaviour/test.rs | 8 +- protocols/kad/src/jobs.rs | 4 +- protocols/kad/src/kbucket.rs | 4 +- protocols/kad/src/record/store/memory.rs | 2 +- protocols/mdns/Cargo.toml | 2 +- protocols/mdns/src/behaviour/iface.rs | 2 +- protocols/mdns/src/behaviour/iface/dns.rs | 8 +- protocols/ping/Cargo.toml | 2 +- protocols/ping/src/protocol.rs | 4 +- protocols/relay/Cargo.toml | 2 +- protocols/rendezvous/Cargo.toml | 4 +- protocols/rendezvous/src/codec.rs | 2 +- protocols/request-response/Cargo.toml | 4 +- protocols/request-response/tests/ping.rs | 2 +- protocols/stream/Cargo.toml | 2 +- protocols/stream/src/shared.rs | 2 +- swarm/Cargo.toml | 4 +- swarm/src/behaviour/external_addresses.rs | 2 +- swarm/src/handler/multi.rs | 2 +- transports/noise/Cargo.toml | 2 +- transports/noise/src/protocol.rs | 2 +- transports/pnet/Cargo.toml | 2 +- transports/pnet/src/lib.rs | 2 +- transports/quic/Cargo.toml | 2 +- transports/quic/src/hole_punching.rs | 4 +- transports/quic/tests/smoke.rs | 2 +- transports/webrtc-websys/Cargo.toml | 2 +- transports/webrtc/Cargo.toml | 2 +- transports/webrtc/src/tokio/certificate.rs | 6 +- transports/webrtc/src/tokio/transport.rs | 8 +- transports/webrtc/tests/smoke.rs | 6 +- wasm-tests/webtransport-tests/Cargo.toml | 2 +- 60 files changed, 354 insertions(+), 233 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c82fdec4223..1f981a33fdd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -542,7 +542,7 @@ dependencies = [ "libp2p", "opentelemetry-jaeger", "opentelemetry_sdk 0.21.2", - "rand 0.8.5", + "rand 0.9.0", "tokio", "tracing", "tracing-opentelemetry 0.22.0", @@ -559,7 +559,7 @@ dependencies = [ "axum-core", "bytes", "futures-util", - "http 1.2.0", + "http 1.3.1", "http-body", "http-body-util", "hyper", @@ -592,7 +592,7 @@ dependencies = [ "async-trait", "bytes", "futures-util", - "http 1.2.0", + "http 1.3.1", "http-body", "http-body-util", "mime", @@ -651,9 +651,9 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "base64ct" -version = "1.6.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +checksum = "bb97d56060ee67d285efb8001fec9d2a4c710c32efd2e14b5cbb5ba71930fc2d" [[package]] name = "bimap" @@ -743,7 +743,7 @@ dependencies = [ "libp2p-webrtc", "libp2p-webrtc-websys", "mime_guess", - "rand 0.8.5", + "rand 0.9.0", "rust-embed", "tokio", "tokio-util", @@ -928,9 +928,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.31" +version = "4.5.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "027bb0d98429ae334a8698531da7077bdf906419543a35a55c2cb1b66437d767" +checksum = "6088f3ae8c3608d19260cd7445411865a485688711b78b5be70d78cd96136f83" dependencies = [ "clap_builder", "clap_derive", @@ -938,9 +938,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.31" +version = "4.5.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5589e0cba072e0f3d23791efac0fd8627b49c829c196a492e88168e6a669d863" +checksum = "22a7ef7f676155edfb82daa97f99441f3ebf4a58d5e32f295a56259f1b6facc8" dependencies = [ "anstream", "anstyle", @@ -950,9 +950,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.28" +version = "4.5.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf4ced95c6f4a675af3da73304b9ac4ed991640c36374e4b46795c49e17cf1ed" +checksum = "09176aae279615badda0765c0c0b3f6ed53f4709118af73cf4655d85d1530cd7" dependencies = [ "heck", "proc-macro2", @@ -1483,14 +1483,14 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.11.6" +version = "0.11.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcaee3d8e3cfc3fd92428d477bc97fc29ec8716d180c0d74c643bb26166660e0" +checksum = "c3716d7a920fb4fac5d84e9d4bce8ceb321e9414b4409da61b07b75c1e3d0697" dependencies = [ "anstream", "anstyle", "env_filter", - "humantime", + "jiff", "log", ] @@ -1894,8 +1894,8 @@ dependencies = [ "fnv", "futures-core", "futures-sink", - "http 1.2.0", - "indexmap 2.7.1", + "http 1.3.1", + "indexmap 2.8.0", "slab", "tokio", "tokio-util", @@ -2081,7 +2081,7 @@ version = "0.1.0" dependencies = [ "anyhow", "either", - "env_logger 0.11.6", + "env_logger 0.11.7", "futures", "libp2p", "redis", @@ -2093,13 +2093,13 @@ dependencies = [ [[package]] name = "hostname" -version = "0.3.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3e867" +checksum = "f9c7c7c8ac16c798734b8a24560c1362120597c40d5e1459f09498f8f6c8f2ba" dependencies = [ + "cfg-if", "libc", - "match_cfg", - "winapi", + "windows 0.52.0", ] [[package]] @@ -2115,9 +2115,9 @@ dependencies = [ [[package]] name = "http" -version = "1.2.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f16ca2af56261c99fba8bac40a10251ce8188205a4c448fbb745a2e4daa76fea" +checksum = "f4a85d31aea989eead29a3aaf9e1115a180df8282431156e533de47660892565" dependencies = [ "bytes", "fnv", @@ -2131,18 +2131,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ "bytes", - "http 1.2.0", + "http 1.3.1", ] [[package]] name = "http-body-util" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" dependencies = [ "bytes", - "futures-util", - "http 1.2.0", + "futures-core", + "http 1.3.1", "http-body", "pin-project-lite", ] @@ -2165,12 +2165,6 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - [[package]] name = "hyper" version = "1.6.0" @@ -2181,7 +2175,7 @@ dependencies = [ "futures-channel", "futures-util", "h2", - "http 1.2.0", + "http 1.3.1", "http-body", "httparse", "httpdate", @@ -2199,7 +2193,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d191583f3da1305256f22463b9bb0471acad48a4e534a5218b9963e9c1f59b2" dependencies = [ "futures-util", - "http 1.2.0", + "http 1.3.1", "hyper", "hyper-util", "rustls 0.23.23", @@ -2248,7 +2242,7 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "http 1.2.0", + "http 1.3.1", "http-body", "hyper", "pin-project-lite", @@ -2451,7 +2445,7 @@ dependencies = [ "attohttpc", "bytes", "futures", - "http 1.2.0", + "http 1.3.1", "http-body-util", "hyper", "hyper-util", @@ -2474,9 +2468,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.7.1" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c9c992b02b5b4c94ea26e32fe5bccb7aa7d9f390ab5c1221ff895bc7ea8b652" +checksum = "3954d50fe15b02142bf25d3b8bdadb634ec3948f103d04ffe3031bc8fe9d7058" dependencies = [ "equivalent", "hashbrown 0.15.2", @@ -2533,7 +2527,7 @@ dependencies = [ "libp2p-webrtc", "libp2p-webrtc-websys", "mime_guess", - "rand 0.8.5", + "rand 0.9.0", "redis", "reqwest", "rust-embed", @@ -2632,6 +2626,30 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" +[[package]] +name = "jiff" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d699bc6dfc879fb1bf9bdff0d4c56f0884fc6f0d0eb0fba397a6d00cd9a6b85e" +dependencies = [ + "jiff-static", + "log", + "portable-atomic", + "portable-atomic-util", + "serde", +] + +[[package]] +name = "jiff-static" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d16e75759ee0aa64c57a56acbf43916987b20c77373cb7e808979e02b93c9f9" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.100", +] + [[package]] name = "js-sys" version = "0.3.77" @@ -2680,9 +2698,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.170" +version = "0.2.171" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "875b3680cb2f8f71bdcf9a30f38d48282f5d3c95cbf9b3fa57269bb5d5c06828" +checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6" [[package]] name = "libp2p" @@ -2693,7 +2711,7 @@ dependencies = [ "either", "futures", "futures-timer", - "getrandom 0.2.15", + "getrandom 0.3.1", "libp2p-allow-block-list", "libp2p-autonat", "libp2p-connection-limits", @@ -2766,8 +2784,8 @@ dependencies = [ "libp2p-swarm-test", "quick-protobuf", "quick-protobuf-codec", - "rand 0.8.5", - "rand_core 0.6.4", + "rand 0.9.0", + "rand_core 0.9.3", "thiserror 2.0.12", "tokio", "tracing", @@ -2787,7 +2805,7 @@ dependencies = [ "libp2p-swarm-derive", "libp2p-swarm-test", "quickcheck-ext", - "rand 0.8.5", + "rand 0.9.0", "tokio", ] @@ -2808,7 +2826,7 @@ dependencies = [ "parking_lot", "pin-project", "quick-protobuf", - "rand 0.8.5", + "rand 0.9.0", "rw-stream-sink", "thiserror 2.0.12", "tokio", @@ -2877,7 +2895,7 @@ dependencies = [ "libp2p-swarm", "quick-protobuf", "quick-protobuf-codec", - "rand 0.8.5", + "rand 0.9.0", "smallvec", "thiserror 2.0.12", "tracing", @@ -2896,7 +2914,7 @@ dependencies = [ "fnv", "futures", "futures-timer", - "getrandom 0.2.15", + "getrandom 0.3.1", "hashlink", "hex_fmt", "libp2p-core", @@ -2907,7 +2925,7 @@ dependencies = [ "quick-protobuf", "quick-protobuf-codec", "quickcheck-ext", - "rand 0.8.5", + "rand 0.9.0", "regex", "serde", "sha2 0.10.8", @@ -2954,8 +2972,8 @@ dependencies = [ "p256", "quick-protobuf", "quickcheck-ext", - "rand 0.8.5", - "ring 0.17.13", + "rand 0.9.0", + "ring 0.17.14", "rmp-serde", "sec1", "serde", @@ -2987,7 +3005,7 @@ dependencies = [ "quick-protobuf", "quick-protobuf-codec", "quickcheck-ext", - "rand 0.8.5", + "rand 0.9.0", "serde", "sha2 0.10.8", "smallvec", @@ -3012,7 +3030,7 @@ dependencies = [ "libp2p-identity", "libp2p-swarm", "libp2p-swarm-test", - "rand 0.8.5", + "rand 0.9.0", "smallvec", "socket2", "tokio", @@ -3071,7 +3089,7 @@ dependencies = [ "nohash-hasher", "parking_lot", "quickcheck-ext", - "rand 0.8.5", + "rand 0.9.0", "smallvec", "tracing", "tracing-subscriber", @@ -3103,7 +3121,7 @@ dependencies = [ "multihash", "quick-protobuf", "quickcheck-ext", - "rand 0.8.5", + "rand 0.9.0", "snow", "static_assertions", "thiserror 2.0.12", @@ -3164,7 +3182,7 @@ dependencies = [ "libp2p-swarm", "libp2p-swarm-test", "quickcheck-ext", - "rand 0.8.5", + "rand 0.9.0", "tokio", "tracing", "web-time 1.1.0", @@ -3201,7 +3219,7 @@ dependencies = [ "libp2p-yamux", "pin-project", "quickcheck-ext", - "rand 0.8.5", + "rand 0.9.0", "salsa20", "sha3", "tokio", @@ -3225,8 +3243,8 @@ dependencies = [ "libp2p-yamux", "quickcheck", "quinn", - "rand 0.8.5", - "ring 0.17.13", + "rand 0.9.0", + "ring 0.17.14", "rustls 0.23.23", "socket2", "thiserror 2.0.12", @@ -3255,7 +3273,7 @@ dependencies = [ "quick-protobuf", "quick-protobuf-codec", "quickcheck-ext", - "rand 0.8.5", + "rand 0.9.0", "static_assertions", "thiserror 2.0.12", "tracing", @@ -3279,7 +3297,7 @@ dependencies = [ "libp2p-swarm-test", "quick-protobuf", "quick-protobuf-codec", - "rand 0.8.5", + "rand 0.9.0", "thiserror 2.0.12", "tokio", "tracing", @@ -3302,7 +3320,7 @@ dependencies = [ "libp2p-identity", "libp2p-swarm", "libp2p-swarm-test", - "rand 0.8.5", + "rand 0.9.0", "serde", "serde_json", "smallvec", @@ -3337,7 +3355,7 @@ dependencies = [ "libp2p-identity", "libp2p-swarm", "libp2p-swarm-test", - "rand 0.8.5", + "rand 0.9.0", "tokio", "tracing", "tracing-subscriber", @@ -3353,7 +3371,7 @@ dependencies = [ "fnv", "futures", "futures-timer", - "getrandom 0.2.15", + "getrandom 0.3.1", "libp2p-core", "libp2p-identify", "libp2p-identity", @@ -3366,7 +3384,7 @@ dependencies = [ "lru", "multistream-select", "quickcheck-ext", - "rand 0.8.5", + "rand 0.9.0", "smallvec", "tokio", "tracing", @@ -3430,7 +3448,7 @@ dependencies = [ "libp2p-swarm", "libp2p-yamux", "rcgen 0.13.2", - "ring 0.17.13", + "ring 0.17.14", "rustls 0.23.23", "rustls-webpki 0.101.7", "thiserror 2.0.12", @@ -3479,7 +3497,7 @@ dependencies = [ "libp2p-webrtc-utils", "multihash", "quickcheck", - "rand 0.8.5", + "rand 0.9.0", "rcgen 0.11.3", "stun 0.7.0", "thiserror 2.0.12", @@ -3505,7 +3523,7 @@ dependencies = [ "libp2p-noise", "quick-protobuf", "quick-protobuf-codec", - "rand 0.8.5", + "rand 0.9.0", "serde", "sha2 0.10.8", "tinytemplate", @@ -3518,7 +3536,7 @@ version = "0.4.0" dependencies = [ "bytes", "futures", - "getrandom 0.2.15", + "getrandom 0.3.1", "hex", "js-sys", "libp2p-core", @@ -3725,12 +3743,6 @@ dependencies = [ "hashbrown 0.15.2", ] -[[package]] -name = "match_cfg" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" - [[package]] name = "matchers" version = "0.1.0" @@ -4133,9 +4145,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.20.3" +version = "1.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "945462a4b81e43c4e3ba96bd7b49d834c6f61198356aa858733bc4acf3cbe62e" +checksum = "cde51589ab56b20a6f686b2c68f7a0bd6add753d697abf720d63f8db3ab7b1ad" [[package]] name = "oorandom" @@ -4201,7 +4213,7 @@ checksum = "1e32339a5dc40459130b3bd269e9892439f55b33e772d2a9d402a789baaf4e8a" dependencies = [ "futures-core", "futures-sink", - "indexmap 2.7.1", + "indexmap 2.8.0", "js-sys", "once_cell", "pin-project-lite", @@ -4247,7 +4259,7 @@ checksum = "91cf61a1868dacc576bf2b2a1c3e9ab150af7272909e80085c3173384fe11f76" dependencies = [ "async-trait", "futures-core", - "http 1.2.0", + "http 1.3.1", "opentelemetry 0.27.1", "opentelemetry-proto", "opentelemetry_sdk 0.27.1", @@ -4577,6 +4589,15 @@ version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e" +[[package]] +name = "portable-atomic-util" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8a2f0d8d040d7848a709caf78912debcc3f33ee4b3cac47d73d1e1069e83507" +dependencies = [ + "portable-atomic", +] + [[package]] name = "powerfmt" version = "0.2.0" @@ -4656,12 +4677,6 @@ dependencies = [ "syn 2.0.100", ] -[[package]] -name = "quick-error" -version = "1.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" - [[package]] name = "quick-protobuf" version = "0.8.1" @@ -4734,7 +4749,7 @@ dependencies = [ "bytes", "getrandom 0.2.15", "rand 0.8.5", - "ring 0.17.13", + "ring 0.17.14", "rustc-hash", "rustls 0.23.23", "rustls-pki-types", @@ -4761,9 +4776,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.39" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1f1914ce909e1658d9907913b4b91947430c7d9be598b15a1912935b8c04801" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" dependencies = [ "proc-macro2", ] @@ -4909,7 +4924,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75e669e5202259b5314d1ea5397316ad400819437857b90861765f24c4cf80a2" dependencies = [ "pem", - "ring 0.17.13", + "ring 0.17.14", "rustls-pki-types", "time", "yasna", @@ -5022,9 +5037,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.12.12" +version = "0.12.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43e734407157c3c2034e0258f5e4473ddb361b1e85f95a66690d67264d7cd1da" +checksum = "989e327e510263980e231de548a33e63d34962d29ae61b467389a1a09627a254" dependencies = [ "base64 0.22.1", "bytes", @@ -5032,7 +5047,7 @@ dependencies = [ "futures-core", "futures-util", "h2", - "http 1.2.0", + "http 1.3.1", "http-body", "http-body-util", "hyper", @@ -5071,12 +5086,11 @@ dependencies = [ [[package]] name = "resolv-conf" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52e44394d2086d010551b14b53b1f24e31647570cd1deb0379e2c21b329aba00" +checksum = "48375394603e3dd4b2d64371f7148fd8c7baa2680e28741f2cb8d23b59e3d4c4" dependencies = [ "hostname", - "quick-error", ] [[package]] @@ -5106,9 +5120,9 @@ dependencies = [ [[package]] name = "ring" -version = "0.17.13" +version = "0.17.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ac5d832aa16abd7d1def883a8545280c20a60f523a370aa3a9617c2b8550ee" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" dependencies = [ "cc", "cfg-if", @@ -5286,9 +5300,9 @@ dependencies = [ [[package]] name = "rustix" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dade4812df5c384711475be5fcd8c162555352945401aed22a35bffeab61f657" +checksum = "f7178faa4b75a30e269c71e61c353ce2748cf3d76f0c44c393f4e60abf49b825" dependencies = [ "bitflags 2.9.0", "errno", @@ -5304,7 +5318,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" dependencies = [ "log", - "ring 0.17.13", + "ring 0.17.14", "rustls-webpki 0.101.7", "sct", ] @@ -5316,7 +5330,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "47796c98c480fce5406ef69d1c76378375492c3b0a0de587be0c1d9feb12f395" dependencies = [ "once_cell", - "ring 0.17.13", + "ring 0.17.14", "rustls-pki-types", "rustls-webpki 0.102.8", "subtle", @@ -5347,7 +5361,7 @@ version = "0.101.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" dependencies = [ - "ring 0.17.13", + "ring 0.17.14", "untrusted 0.9.0", ] @@ -5357,7 +5371,7 @@ version = "0.102.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" dependencies = [ - "ring 0.17.13", + "ring 0.17.14", "rustls-pki-types", "untrusted 0.9.0", ] @@ -5429,7 +5443,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" dependencies = [ - "ring 0.17.13", + "ring 0.17.14", "untrusted 0.9.0", ] @@ -5529,7 +5543,7 @@ version = "1.0.140" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" dependencies = [ - "indexmap 2.7.1", + "indexmap 2.8.0", "itoa", "memchr", "ryu", @@ -5718,7 +5732,7 @@ dependencies = [ "chacha20poly1305", "curve25519-dalek", "rand_core 0.6.4", - "ring 0.17.13", + "ring 0.17.14", "rustc_version", "sha2 0.10.8", "subtle", @@ -5785,7 +5799,7 @@ dependencies = [ "futures", "libp2p", "libp2p-stream", - "rand 0.8.5", + "rand 0.9.0", "tokio", "tracing", "tracing-subscriber", @@ -5839,7 +5853,7 @@ dependencies = [ "lazy_static", "md-5", "rand 0.8.5", - "ring 0.17.13", + "ring 0.17.14", "subtle", "thiserror 1.0.69", "tokio", @@ -5858,7 +5872,7 @@ dependencies = [ "lazy_static", "md-5", "rand 0.8.5", - "ring 0.17.13", + "ring 0.17.14", "subtle", "thiserror 1.0.69", "tokio", @@ -5992,7 +6006,7 @@ dependencies = [ "fastrand", "getrandom 0.3.1", "once_cell", - "rustix 1.0.1", + "rustix 1.0.2", "windows-sys 0.59.0", ] @@ -6014,8 +6028,8 @@ dependencies = [ "async-trait", "base64 0.22.1", "futures", - "http 1.2.0", - "indexmap 2.7.1", + "http 1.3.1", + "indexmap 2.8.0", "parking_lot", "paste", "reqwest", @@ -6182,9 +6196,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.44.0" +version = "1.44.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9975ea0f48b5aa3972bf2d888c238182458437cc2a19374b81b25cdf1023fb3a" +checksum = "f382da615b842244d4b8738c82ed1275e6c5dd90c459a30941cd07080b06c91a" dependencies = [ "backtrace", "bytes", @@ -6242,9 +6256,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.13" +version = "0.7.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7fcaa8d55a2bdd6b83ace262b016eca0d79ee02818c5c1bcdf0305114081078" +checksum = "6b9590b93e6fcc1739458317cccd391ad3955e2bde8913edf6f95f9e65a8f034" dependencies = [ "bytes", "futures-core", @@ -6281,7 +6295,7 @@ version = "0.22.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17b4795ff5edd201c7cd6dca065ae59972ce77d1b80fa0a84d94950ece7d1474" dependencies = [ - "indexmap 2.7.1", + "indexmap 2.8.0", "serde", "serde_spanned", "toml_datetime", @@ -6300,7 +6314,7 @@ dependencies = [ "base64 0.22.1", "bytes", "h2", - "http 1.2.0", + "http 1.3.1", "http-body", "http-body-util", "hyper", @@ -6363,7 +6377,7 @@ dependencies = [ "bitflags 2.9.0", "bytes", "futures-util", - "http 1.2.0", + "http 1.3.1", "http-body", "http-body-util", "http-range-header", @@ -6533,7 +6547,7 @@ dependencies = [ "log", "md-5", "rand 0.8.5", - "ring 0.17.13", + "ring 0.17.14", "stun 0.5.1", "thiserror 1.0.69", "tokio", @@ -7118,7 +7132,7 @@ name = "webtransport-tests" version = "0.1.0" dependencies = [ "futures", - "getrandom 0.2.15", + "getrandom 0.3.1", "libp2p-core", "libp2p-identity", "libp2p-noise", @@ -7168,6 +7182,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" +dependencies = [ + "windows-core 0.52.0", + "windows-targets 0.52.6", +] + [[package]] name = "windows" version = "0.53.0" @@ -7198,6 +7222,15 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-core" version = "0.53.0" @@ -7229,7 +7262,7 @@ dependencies = [ "windows-implement 0.58.0", "windows-interface 0.58.0", "windows-result 0.2.0", - "windows-strings", + "windows-strings 0.1.0", "windows-targets 0.52.6", ] @@ -7277,15 +7310,21 @@ dependencies = [ "syn 2.0.100", ] +[[package]] +name = "windows-link" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dccfd733ce2b1753b03b6d3c65edf020262ea35e20ccdf3e288043e6dd620e3" + [[package]] name = "windows-registry" -version = "0.2.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +checksum = "4286ad90ddb45071efd1a66dfa43eb02dd0dfbae1545ad6cc3c51cf34d7e8ba3" dependencies = [ - "windows-result 0.2.0", - "windows-strings", - "windows-targets 0.52.6", + "windows-result 0.3.1", + "windows-strings 0.3.1", + "windows-targets 0.53.0", ] [[package]] @@ -7306,6 +7345,15 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-result" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06374efe858fab7e4f881500e6e86ec8bc28f9462c47e5a9941a0142ad86b189" +dependencies = [ + "windows-link", +] + [[package]] name = "windows-strings" version = "0.1.0" @@ -7316,6 +7364,15 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-strings" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87fa48cc5d406560701792be122a10132491cff9d0aeb23583cc2dcafc847319" +dependencies = [ + "windows-link", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -7367,13 +7424,29 @@ dependencies = [ "windows_aarch64_gnullvm 0.52.6", "windows_aarch64_msvc 0.52.6", "windows_i686_gnu 0.52.6", - "windows_i686_gnullvm", + "windows_i686_gnullvm 0.52.6", "windows_i686_msvc 0.52.6", "windows_x86_64_gnu 0.52.6", "windows_x86_64_gnullvm 0.52.6", "windows_x86_64_msvc 0.52.6", ] +[[package]] +name = "windows-targets" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1e4c7e8ceaaf9cb7d7507c974735728ab453b67ef8f18febdd7c11fe59dca8b" +dependencies = [ + "windows_aarch64_gnullvm 0.53.0", + "windows_aarch64_msvc 0.53.0", + "windows_i686_gnu 0.53.0", + "windows_i686_gnullvm 0.53.0", + "windows_i686_msvc 0.53.0", + "windows_x86_64_gnu 0.53.0", + "windows_x86_64_gnullvm 0.53.0", + "windows_x86_64_msvc 0.53.0", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.48.5" @@ -7386,6 +7459,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" + [[package]] name = "windows_aarch64_msvc" version = "0.48.5" @@ -7398,6 +7477,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" + [[package]] name = "windows_i686_gnu" version = "0.48.5" @@ -7410,12 +7495,24 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" +[[package]] +name = "windows_i686_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3" + [[package]] name = "windows_i686_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" + [[package]] name = "windows_i686_msvc" version = "0.48.5" @@ -7428,6 +7525,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +[[package]] +name = "windows_i686_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" + [[package]] name = "windows_x86_64_gnu" version = "0.48.5" @@ -7440,6 +7543,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" @@ -7452,6 +7561,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" + [[package]] name = "windows_x86_64_msvc" version = "0.48.5" @@ -7464,11 +7579,17 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" + [[package]] name = "winnow" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e7f4ea97f6f78012141bcdb6a216b2609f0979ada50b20ca5b52dde2eac2bb1" +checksum = "0e97b544156e9bebe1a0ffbc03484fc1ffe3100cbce3ffb17eac35f7cdd7ab36" dependencies = [ "memchr", ] diff --git a/Cargo.toml b/Cargo.toml index 289106cc5f0..4b410e3a2cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -124,7 +124,7 @@ env_logger = "0.11" futures = "0.3.30" futures-bounded = { version = "0.2.4" } futures-rustls = { version = "0.26.0", default-features = false } -getrandom = "0.2" +getrandom = "0.3" if-watch = "3.2.1" hickory-proto = { version = "0.25.0-alpha.4", default-features = false } hickory-resolver = { version = "0.25.0-alpha.4", default-features = false } diff --git a/core/Cargo.toml b/core/Cargo.toml index 8c6018adb16..5640c0bfeb2 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -23,7 +23,7 @@ multistream-select = { workspace = true } parking_lot = "0.12.3" pin-project = "1.1.5" quick-protobuf = "0.8" -rand = "0.8" +rand = "0.9" rw-stream-sink = { workspace = true } thiserror = { workspace = true } tracing = { workspace = true } diff --git a/examples/autonatv2/Cargo.toml b/examples/autonatv2/Cargo.toml index ff686116a23..7f2313e9033 100644 --- a/examples/autonatv2/Cargo.toml +++ b/examples/autonatv2/Cargo.toml @@ -20,7 +20,7 @@ clap = { version = "4.4.18", features = ["derive"] } tokio = { version = "1.35.1", features = ["macros", "rt-multi-thread"] } tracing = "0.1.40" tracing-subscriber = { workspace = true, features = ["env-filter"] } -rand = "0.8.5" +rand = "0.9" opentelemetry_sdk = { version = "0.21.1", optional = true, features = ["rt-tokio"] } tracing-opentelemetry = { version = "0.22.0", optional = true } opentelemetry-jaeger = { version = "0.20.0", optional = true, features = ["rt-tokio"] } diff --git a/examples/browser-webrtc/Cargo.toml b/examples/browser-webrtc/Cargo.toml index 1b838bb1b42..006787742b6 100644 --- a/examples/browser-webrtc/Cargo.toml +++ b/examples/browser-webrtc/Cargo.toml @@ -18,7 +18,7 @@ crate-type = ["cdylib"] [dependencies] anyhow = "1.0.86" futures = { workspace = true } -rand = "0.8" +rand = "0.9" tracing = { workspace = true } tracing-subscriber = { workspace = true, features = ["env-filter"] } diff --git a/examples/browser-webrtc/src/main.rs b/examples/browser-webrtc/src/main.rs index 52222dc882b..ac1a204e2d4 100644 --- a/examples/browser-webrtc/src/main.rs +++ b/examples/browser-webrtc/src/main.rs @@ -18,7 +18,7 @@ use libp2p::{ swarm::SwarmEvent, }; use libp2p_webrtc as webrtc; -use rand::thread_rng; +use rand::rng; use tokio::net::TcpListener; use tower_http::cors::{Any, CorsLayer}; @@ -33,7 +33,7 @@ async fn main() -> anyhow::Result<()> { .with_other_transport(|id_keys| { Ok(webrtc::tokio::Transport::new( id_keys.clone(), - webrtc::tokio::Certificate::generate(&mut thread_rng())?, + webrtc::tokio::Certificate::generate(&mut rng())?, ) .map(|(peer_id, conn), _| (peer_id, StreamMuxerBox::new(conn)))) })? diff --git a/examples/stream/Cargo.toml b/examples/stream/Cargo.toml index 77b5ad9c1b1..8ca44c5d0a6 100644 --- a/examples/stream/Cargo.toml +++ b/examples/stream/Cargo.toml @@ -13,7 +13,7 @@ anyhow = "1" futures = { workspace = true } libp2p = { path = "../../libp2p", features = [ "tokio", "quic"] } libp2p-stream = { path = "../../protocols/stream", version = "0.3.0-alpha" } -rand = "0.8" +rand = "0.9" tokio = { workspace = true, features = ["full"] } tracing = { workspace = true } tracing-subscriber = { workspace = true, features = ["env-filter"] } diff --git a/examples/stream/src/main.rs b/examples/stream/src/main.rs index 71d2d2fcc76..6ce41e495b4 100644 --- a/examples/stream/src/main.rs +++ b/examples/stream/src/main.rs @@ -140,7 +140,7 @@ async fn send(mut stream: Stream) -> io::Result<()> { let num_bytes = rand::random::() % 1000; let mut bytes = vec![0; num_bytes]; - rand::thread_rng().fill_bytes(&mut bytes); + rand::rng().fill_bytes(&mut bytes); stream.write_all(&bytes).await?; diff --git a/identity/Cargo.toml b/identity/Cargo.toml index 67f2b3f459d..11b988ef9d8 100644 --- a/identity/Cargo.toml +++ b/identity/Cargo.toml @@ -21,7 +21,7 @@ tracing = { workspace = true } multihash = { version = "0.19.1", optional = true } p256 = { version = "0.13", default-features = false, features = ["ecdsa", "std", "pem"], optional = true } quick-protobuf = "0.8.1" -rand = { version = "0.8", optional = true } +rand = { version = "0.9", optional = true } sec1 = { version = "0.7", default-features = false, optional = true } serde = { version = "1", optional = true, features = ["derive"] } sha2 = { version = "0.10.8", optional = true } diff --git a/identity/src/ecdsa.rs b/identity/src/ecdsa.rs index 11cdaced795..e81cf923f80 100644 --- a/identity/src/ecdsa.rs +++ b/identity/src/ecdsa.rs @@ -96,7 +96,7 @@ impl SecretKey { /// Generate a new random ECDSA secret key. #[cfg(feature = "rand")] pub fn generate() -> SecretKey { - SecretKey(SigningKey::random(&mut rand::thread_rng())) + SecretKey(SigningKey::random(&mut rand::rng())) } /// Sign a message with this secret key, producing a DER-encoded ECDSA signature. diff --git a/identity/src/peer_id.rs b/identity/src/peer_id.rs index 7f6d1f44eab..27802391ae2 100644 --- a/identity/src/peer_id.rs +++ b/identity/src/peer_id.rs @@ -106,7 +106,7 @@ impl PeerId { /// 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]>(); + let peer_id = rand::rng().random::<[u8; 32]>(); PeerId { multihash: Multihash::wrap(0x0, &peer_id).expect("The digest size is never too large"), } diff --git a/identity/src/secp256k1.rs b/identity/src/secp256k1.rs index e884cf1385d..6626bf41511 100644 --- a/identity/src/secp256k1.rs +++ b/identity/src/secp256k1.rs @@ -91,7 +91,7 @@ impl SecretKey { /// Generate a new random Secp256k1 secret key. #[cfg(feature = "rand")] pub fn generate() -> SecretKey { - SecretKey(libsecp256k1::SecretKey::random(&mut rand::thread_rng())) + SecretKey(libsecp256k1::SecretKey::random(&mut rand::rng())) } /// Create a secret key from a byte slice, zeroing the slice on success. diff --git a/interop-tests/Cargo.toml b/interop-tests/Cargo.toml index ca0eb221bd3..49ebdb8e5d7 100644 --- a/interop-tests/Cargo.toml +++ b/interop-tests/Cargo.toml @@ -14,7 +14,7 @@ crate-type = ["cdylib", "rlib"] [dependencies] anyhow = "1" futures = { workspace = true } -rand = "0.8.5" +rand = "0.9" serde = { version = "1", features = ["derive"] } tracing = { workspace = true } tracing-subscriber = { workspace = true, features = ["env-filter"] } diff --git a/interop-tests/src/arch.rs b/interop-tests/src/arch.rs index 88c4c5767de..b9e498bcb83 100644 --- a/interop-tests/src/arch.rs +++ b/interop-tests/src/arch.rs @@ -142,7 +142,7 @@ pub(crate) mod native { .with_other_transport(|key| { Ok(webrtc::tokio::Transport::new( key.clone(), - webrtc::tokio::Certificate::generate(&mut rand::thread_rng())?, + webrtc::tokio::Certificate::generate(&mut rand::rng())?, )) })? .with_behaviour(behaviour_constructor)? diff --git a/libp2p/Cargo.toml b/libp2p/Cargo.toml index 09acbf86688..f9c50d089c3 100644 --- a/libp2p/Cargo.toml +++ b/libp2p/Cargo.toml @@ -85,7 +85,7 @@ tcp = ["dep:libp2p-tcp"] tls = ["dep:libp2p-tls"] tokio = [ "libp2p-swarm/tokio", "libp2p-mdns?/tokio", "libp2p-tcp?/tokio", "libp2p-dns?/tokio", "libp2p-quic?/tokio", "libp2p-upnp?/tokio"] uds = ["dep:libp2p-uds"] -wasm-bindgen = [ "futures-timer/wasm-bindgen", "getrandom/js", "libp2p-swarm/wasm-bindgen", "libp2p-gossipsub?/wasm-bindgen"] +wasm-bindgen = [ "futures-timer/wasm-bindgen", "libp2p-swarm/wasm-bindgen", "libp2p-gossipsub?/wasm-bindgen"] webrtc-websys = ['dep:libp2p-webrtc-websys'] websocket-websys = ["dep:libp2p-websocket-websys"] websocket = ["dep:libp2p-websocket"] diff --git a/misc/connection-limits/Cargo.toml b/misc/connection-limits/Cargo.toml index 56f3ab091d2..cf687574150 100644 --- a/misc/connection-limits/Cargo.toml +++ b/misc/connection-limits/Cargo.toml @@ -21,7 +21,7 @@ libp2p-ping = { workspace = true } libp2p-swarm-derive = { path = "../../swarm-derive" } libp2p-swarm-test = { path = "../../swarm-test" } quickcheck = { workspace = true } -rand = "0.8.5" +rand = "0.9" [lints] workspace = true diff --git a/misc/connection-limits/src/lib.rs b/misc/connection-limits/src/lib.rs index bd95dd6760c..47f18292dc3 100644 --- a/misc/connection-limits/src/lib.rs +++ b/misc/connection-limits/src/lib.rs @@ -416,7 +416,7 @@ mod tests { fn fill_outgoing() -> (Swarm, Multiaddr, u32) { use rand::Rng; - let outgoing_limit = rand::thread_rng().gen_range(1..10); + let outgoing_limit = rand::rng().gen_range(1..10); let mut network = Swarm::new_ephemeral(|_| { Behaviour::new( diff --git a/misc/webrtc-utils/Cargo.toml b/misc/webrtc-utils/Cargo.toml index 8c6eaedd1e3..edae86fe7c6 100644 --- a/misc/webrtc-utils/Cargo.toml +++ b/misc/webrtc-utils/Cargo.toml @@ -20,7 +20,7 @@ libp2p-identity = { workspace = true } libp2p-noise = { workspace = true } quick-protobuf = "0.8" quick-protobuf-codec = { workspace = true } -rand = "0.8" +rand = "0.9" serde = { version = "1.0", features = ["derive"] } sha2 = "0.10.8" tinytemplate = "1.2" diff --git a/misc/webrtc-utils/src/sdp.rs b/misc/webrtc-utils/src/sdp.rs index 96a07f5db95..aa741f0481c 100644 --- a/misc/webrtc-utils/src/sdp.rs +++ b/misc/webrtc-utils/src/sdp.rs @@ -20,7 +20,7 @@ // DEALINGS IN THE SOFTWARE. use std::net::{IpAddr, SocketAddr}; -use rand::{distributions::Alphanumeric, thread_rng, Rng}; +use rand::{distributions::Alphanumeric, rng, Rng}; use serde::Serialize; use tinytemplate::TinyTemplate; @@ -149,7 +149,7 @@ pub fn render_description( pub fn random_ufrag() -> String { format!( "libp2p+webrtc+v1/{}", - thread_rng() + rng() .sample_iter(&Alphanumeric) .take(64) .map(char::from) diff --git a/muxers/mplex/Cargo.toml b/muxers/mplex/Cargo.toml index ddfea1edc44..5bb15f34fc4 100644 --- a/muxers/mplex/Cargo.toml +++ b/muxers/mplex/Cargo.toml @@ -18,7 +18,7 @@ libp2p-core = { workspace = true } libp2p-identity = { workspace = true } nohash-hasher = "0.2" parking_lot = "0.12" -rand = "0.8" +rand = "0.9" smallvec = "1.13.2" tracing = { workspace = true } unsigned-varint = { workspace = true, features = ["asynchronous_codec"] } diff --git a/protocols/autonat/Cargo.toml b/protocols/autonat/Cargo.toml index 61a15eae3bc..faacbdd509a 100644 --- a/protocols/autonat/Cargo.toml +++ b/protocols/autonat/Cargo.toml @@ -30,8 +30,8 @@ libp2p-swarm = { workspace = true } quick-protobuf = "0.8" tracing = { workspace = true } quick-protobuf-codec = { workspace = true } -rand = "0.8" -rand_core = { version = "0.6", optional = true } +rand = "0.9" +rand_core = { version = "0.9", optional = true } thiserror = { workspace = true, optional = true } [dev-dependencies] diff --git a/protocols/autonat/src/v1/behaviour/as_client.rs b/protocols/autonat/src/v1/behaviour/as_client.rs index ca8daf6e1ac..7d21d01f75b 100644 --- a/protocols/autonat/src/v1/behaviour/as_client.rs +++ b/protocols/autonat/src/v1/behaviour/as_client.rs @@ -30,7 +30,7 @@ use libp2p_core::Multiaddr; use libp2p_identity::PeerId; use libp2p_request_response::{self as request_response, OutboundFailure, OutboundRequestId}; use libp2p_swarm::{ConnectionId, ListenAddresses, ToSwarm}; -use rand::{seq::SliceRandom, thread_rng}; +use rand::{seq::SliceRandom, rng}; use web_time::Instant; use super::{ @@ -265,7 +265,7 @@ impl AsClient<'_> { servers.retain(|s| !self.throttled_servers.iter().any(|(id, _)| s == &id)); - servers.choose(&mut thread_rng()).map(|&&p| p) + servers.choose(&mut rng()).map(|&&p| p) } // Send a dial-request to a randomly selected server. diff --git a/protocols/floodsub/Cargo.toml b/protocols/floodsub/Cargo.toml index c9a14fa8cbc..54b2f0ed616 100644 --- a/protocols/floodsub/Cargo.toml +++ b/protocols/floodsub/Cargo.toml @@ -21,7 +21,7 @@ libp2p-swarm = { workspace = true } libp2p-identity = { workspace = true } quick-protobuf = "0.8" quick-protobuf-codec = { workspace = true } -rand = "0.8" +rand = "0.9" smallvec = "1.13.2" thiserror = { workspace = true } tracing = { workspace = true } diff --git a/protocols/gossipsub/Cargo.toml b/protocols/gossipsub/Cargo.toml index 99213860a27..0a83f59d719 100644 --- a/protocols/gossipsub/Cargo.toml +++ b/protocols/gossipsub/Cargo.toml @@ -11,7 +11,7 @@ keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] [features] -wasm-bindgen = ["getrandom/js", "futures-timer/wasm-bindgen"] +wasm-bindgen = ["futures-timer/wasm-bindgen"] [dependencies] async-channel = "2.3.1" @@ -32,7 +32,7 @@ libp2p-identity = { workspace = true, features = ["rand"] } libp2p-swarm = { workspace = true } quick-protobuf = "0.8" quick-protobuf-codec = { workspace = true } -rand = "0.8" +rand = "0.9" regex = "1.10.5" serde = { version = "1", optional = true, features = ["derive"] } sha2 = "0.10.8" diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index 0e9e44b2ef5..5e9e32f3732 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -45,7 +45,7 @@ use libp2p_swarm::{ }; use prometheus_client::registry::Registry; use quick_protobuf::{MessageWrite, Writer}; -use rand::{seq::SliceRandom, thread_rng}; +use rand::{seq::SliceRandom, rng}; use web_time::{Instant, SystemTime}; use crate::{ @@ -1291,7 +1291,7 @@ where // Ask in random order let mut iwant_ids_vec: Vec<_> = iwant_ids.into_iter().collect(); - let mut rng = thread_rng(); + let mut rng = rng(); iwant_ids_vec.partial_shuffle(&mut rng, iask); iwant_ids_vec.truncate(iask); @@ -1632,7 +1632,7 @@ where px.retain(|p| p.peer_id.is_some()); if px.len() > n { // only use at most prune_peers many random peers - let mut rng = thread_rng(); + let mut rng = rng(); px.partial_shuffle(&mut rng, n); px = px.into_iter().take(n).collect(); } @@ -2177,7 +2177,7 @@ where let excess_peer_no = peers.len() - self.config.mesh_n(); // shuffle the peers and then sort by score ascending beginning with the worst - let mut rng = thread_rng(); + let mut rng = rng(); let mut shuffled = peers.iter().copied().collect::>(); shuffled.shuffle(&mut rng); shuffled.sort_by(|p1, p2| { @@ -2467,7 +2467,7 @@ where /// Emits gossip - Send IHAVE messages to a random set of gossip peers. This is applied to mesh /// and fanout peers fn emit_gossip(&mut self) { - let mut rng = thread_rng(); + let mut rng = rng(); let mut messages = Vec::new(); for (topic_hash, peers) in self.mesh.iter().chain(self.fanout.iter()) { let mut message_ids = self.mcache.get_gossip_message_ids(topic_hash); @@ -3491,7 +3491,7 @@ fn get_random_peers_dynamic( } // we have more peers than needed, shuffle them and return n of them - let mut rng = thread_rng(); + let mut rng = rng(); gossip_peers.partial_shuffle(&mut rng, n); tracing::debug!("RANDOM PEERS: Got {:?} peers", n); diff --git a/protocols/gossipsub/src/behaviour/tests.rs b/protocols/gossipsub/src/behaviour/tests.rs index ff69c243453..b2b0d23add0 100644 --- a/protocols/gossipsub/src/behaviour/tests.rs +++ b/protocols/gossipsub/src/behaviour/tests.rs @@ -3349,7 +3349,7 @@ fn test_scoring_p1() { } fn random_message(seq: &mut u64, topics: &[TopicHash]) -> RawMessage { - let mut rng = rand::thread_rng(); + let mut rng = rand::rng(); *seq += 1; RawMessage { source: Some(PeerId::random()), diff --git a/protocols/gossipsub/src/rpc_proto.rs b/protocols/gossipsub/src/rpc_proto.rs index 2f6832a01a1..d64730e0462 100644 --- a/protocols/gossipsub/src/rpc_proto.rs +++ b/protocols/gossipsub/src/rpc_proto.rs @@ -39,27 +39,27 @@ mod test { let new_message1 = super::proto::Message { from: Some(PeerId::random().to_bytes()), - data: Some(rand::thread_rng().gen::<[u8; 32]>().to_vec()), - seqno: Some(rand::thread_rng().gen::<[u8; 8]>().to_vec()), + data: Some(rand::rng().gen::<[u8; 32]>().to_vec()), + seqno: Some(rand::rng().gen::<[u8; 8]>().to_vec()), topic: topic1.clone().into_string(), - signature: Some(rand::thread_rng().gen::<[u8; 32]>().to_vec()), - key: Some(rand::thread_rng().gen::<[u8; 32]>().to_vec()), + signature: Some(rand::rng().gen::<[u8; 32]>().to_vec()), + key: Some(rand::rng().gen::<[u8; 32]>().to_vec()), }; let old_message1 = compat::pb::Message { from: Some(PeerId::random().to_bytes()), - data: Some(rand::thread_rng().gen::<[u8; 32]>().to_vec()), - seqno: Some(rand::thread_rng().gen::<[u8; 8]>().to_vec()), + data: Some(rand::rng().gen::<[u8; 32]>().to_vec()), + seqno: Some(rand::rng().gen::<[u8; 8]>().to_vec()), topic_ids: vec![topic1.clone().into_string()], - signature: Some(rand::thread_rng().gen::<[u8; 32]>().to_vec()), - key: Some(rand::thread_rng().gen::<[u8; 32]>().to_vec()), + signature: Some(rand::rng().gen::<[u8; 32]>().to_vec()), + key: Some(rand::rng().gen::<[u8; 32]>().to_vec()), }; let old_message2 = compat::pb::Message { from: Some(PeerId::random().to_bytes()), - data: Some(rand::thread_rng().gen::<[u8; 32]>().to_vec()), - seqno: Some(rand::thread_rng().gen::<[u8; 8]>().to_vec()), + data: Some(rand::rng().gen::<[u8; 32]>().to_vec()), + seqno: Some(rand::rng().gen::<[u8; 8]>().to_vec()), topic_ids: vec![topic1.clone().into_string(), topic2.clone().into_string()], - signature: Some(rand::thread_rng().gen::<[u8; 32]>().to_vec()), - key: Some(rand::thread_rng().gen::<[u8; 32]>().to_vec()), + signature: Some(rand::rng().gen::<[u8; 32]>().to_vec()), + key: Some(rand::rng().gen::<[u8; 32]>().to_vec()), }; let mut new_message1b = Vec::with_capacity(new_message1.get_size()); diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index 0d235511242..213806425f5 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -22,7 +22,7 @@ futures-bounded = { workspace = true } quick-protobuf = "0.8" quick-protobuf-codec = { workspace = true } libp2p-identity = { workspace = true, features = ["rand"] } -rand = "0.8" +rand = "0.9" sha2 = "0.10.8" smallvec = "1.13.2" uint = "0.10" diff --git a/protocols/kad/src/behaviour/test.rs b/protocols/kad/src/behaviour/test.rs index 467865dd225..418ece5fd9b 100644 --- a/protocols/kad/src/behaviour/test.rs +++ b/protocols/kad/src/behaviour/test.rs @@ -33,7 +33,7 @@ use libp2p_noise as noise; use libp2p_swarm::{self as swarm, Swarm, SwarmEvent}; use libp2p_yamux as yamux; use quickcheck::*; -use rand::{random, rngs::StdRng, thread_rng, Rng, SeedableRng}; +use rand::{random, rngs::StdRng, rng, Rng, SeedableRng}; use super::*; use crate::{ @@ -137,7 +137,7 @@ fn build_fully_connected_nodes_with_config( } fn random_multihash() -> Multihash<64> { - Multihash::wrap(SHA_256_MH, &thread_rng().gen::<[u8; 32]>()).unwrap() + Multihash::wrap(SHA_256_MH, &rng().gen::<[u8; 32]>()).unwrap() } #[derive(Clone, Debug)] @@ -315,7 +315,7 @@ fn query_iter() { })) } - let mut rng = thread_rng(); + let mut rng = rng(); for _ in 0..10 { run(&mut rng) } @@ -1176,7 +1176,7 @@ fn disjoint_query_does_not_finish_before_all_paths_did() { let mut bob = build_node(); let key = Key::from( - Multihash::<64>::wrap(SHA_256_MH, &thread_rng().gen::<[u8; 32]>()) + Multihash::<64>::wrap(SHA_256_MH, &rng().gen::<[u8; 32]>()) .expect("32 array to fit into 64 byte multihash"), ); let record_bob = Record::new(key.clone(), b"bob".to_vec()); diff --git a/protocols/kad/src/jobs.rs b/protocols/kad/src/jobs.rs index 56b3e080d96..d3c50564eb4 100644 --- a/protocols/kad/src/jobs.rs +++ b/protocols/kad/src/jobs.rs @@ -345,7 +345,7 @@ mod tests { use crate::record::store::MemoryStore; fn rand_put_record_job() -> PutRecordJob { - let mut rng = rand::thread_rng(); + let mut rng = rand::rng(); let id = PeerId::random(); let replicate_interval = Duration::from_secs(rng.gen_range(1..60)); let publish_interval = Some(replicate_interval * rng.gen_range(1..10)); @@ -354,7 +354,7 @@ mod tests { } fn rand_add_provider_job() -> AddProviderJob { - let mut rng = rand::thread_rng(); + let mut rng = rand::rng(); let interval = Duration::from_secs(rng.gen_range(1..60)); AddProviderJob::new(interval) } diff --git a/protocols/kad/src/kbucket.rs b/protocols/kad/src/kbucket.rs index f32c34e9bb7..dada6e73538 100644 --- a/protocols/kad/src/kbucket.rs +++ b/protocols/kad/src/kbucket.rs @@ -615,7 +615,7 @@ mod tests { let num = g.gen_range(0..usize::min(bucket_size, num_total) + 1); num_total -= num; for _ in 0..num { - let distance = ix.rand_distance(&mut rand::thread_rng()); + let distance = ix.rand_distance(&mut rand::rng()); let key = local_key.for_distance(distance); let node = Node { key, value: () }; let status = NodeStatus::arbitrary(g); @@ -684,7 +684,7 @@ mod tests { #[test] fn rand_distance() { fn prop(ix: u8) -> bool { - let d = BucketIndex(ix as usize).rand_distance(&mut rand::thread_rng()); + let d = BucketIndex(ix as usize).rand_distance(&mut rand::rng()); let n = d.0; let b = U256::from(2); let e = U256::from(ix); diff --git a/protocols/kad/src/record/store/memory.rs b/protocols/kad/src/record/store/memory.rs index 28f6a55044f..29daf2e666b 100644 --- a/protocols/kad/src/record/store/memory.rs +++ b/protocols/kad/src/record/store/memory.rs @@ -218,7 +218,7 @@ mod tests { use crate::SHA_256_MH; fn random_multihash() -> Multihash<64> { - Multihash::wrap(SHA_256_MH, &rand::thread_rng().gen::<[u8; 32]>()).unwrap() + Multihash::wrap(SHA_256_MH, &rand::rng().gen::<[u8; 32]>()).unwrap() } #[test] fn put_get_remove_record() { diff --git a/protocols/mdns/Cargo.toml b/protocols/mdns/Cargo.toml index dbf66abe61c..93b7b91a86f 100644 --- a/protocols/mdns/Cargo.toml +++ b/protocols/mdns/Cargo.toml @@ -18,7 +18,7 @@ if-watch = { workspace = true } libp2p-core = { workspace = true } libp2p-swarm = { workspace = true } libp2p-identity = { workspace = true } -rand = "0.8.3" +rand = "0.9" smallvec = "1.13.2" socket2 = { version = "0.5.7", features = ["all"] } tokio = { workspace = true, default-features = false, features = ["net", "time"], optional = true} diff --git a/protocols/mdns/src/behaviour/iface.rs b/protocols/mdns/src/behaviour/iface.rs index 873bb8a307b..9f704c7bdd3 100644 --- a/protocols/mdns/src/behaviour/iface.rs +++ b/protocols/mdns/src/behaviour/iface.rs @@ -162,7 +162,7 @@ where // randomize timer to prevent all converging and firing at the same time. let query_interval = { use rand::Rng; - let mut rng = rand::thread_rng(); + let mut rng = rand::rng(); let jitter = rng.gen_range(0..100); config.query_interval + Duration::from_millis(jitter) }; diff --git a/protocols/mdns/src/behaviour/iface/dns.rs b/protocols/mdns/src/behaviour/iface/dns.rs index 35cba44f4af..633dffa7ce5 100644 --- a/protocols/mdns/src/behaviour/iface/dns.rs +++ b/protocols/mdns/src/behaviour/iface/dns.rs @@ -24,7 +24,7 @@ use std::{borrow::Cow, cmp, error, fmt, str, time::Duration}; use libp2p_core::Multiaddr; use libp2p_identity::PeerId; -use rand::{distributions::Alphanumeric, thread_rng, Rng}; +use rand::{distributions::Alphanumeric, rng, Rng}; use crate::{META_QUERY_SERVICE, SERVICE_NAME}; @@ -267,7 +267,7 @@ fn append_u16(out: &mut Vec, value: u16) { /// Generates and returns a random alphanumeric string of `length` size. fn random_string(length: usize) -> String { - thread_rng() + rng() .sample_iter(&Alphanumeric) .take(length) .map(char::from) @@ -278,7 +278,7 @@ fn random_string(length: usize) -> String { fn generate_peer_name() -> Vec { // Use a variable-length random string for mDNS peer name. // See https://github.com/libp2p/rust-libp2p/pull/2311/ - let peer_name = random_string(32 + thread_rng().gen_range(0..32)); + let peer_name = random_string(32 + rng().gen_range(0..32)); // allocate with a little extra padding for QNAME encoding let mut peer_name_bytes = Vec::with_capacity(peer_name.len() + 32); @@ -429,7 +429,7 @@ mod tests { #[test] fn test_random_string() { - let varsize = thread_rng().gen_range(0..32); + let varsize = rng().gen_range(0..32); let size = 32 + varsize; let name = random_string(size); assert_eq!(name.len(), size); diff --git a/protocols/ping/Cargo.toml b/protocols/ping/Cargo.toml index 223a8eee602..db952067a26 100644 --- a/protocols/ping/Cargo.toml +++ b/protocols/ping/Cargo.toml @@ -17,7 +17,7 @@ web-time = { workspace = true } libp2p-core = { workspace = true } libp2p-swarm = { workspace = true } libp2p-identity = { workspace = true } -rand = "0.8" +rand = "0.9" tracing = { workspace = true } [dev-dependencies] diff --git a/protocols/ping/src/protocol.rs b/protocols/ping/src/protocol.rs index 5e84f55e090..9050afd5823 100644 --- a/protocols/ping/src/protocol.rs +++ b/protocols/ping/src/protocol.rs @@ -52,7 +52,7 @@ pub(crate) async fn send_ping(mut stream: S) -> io::Result<(S, Duration)> where S: AsyncRead + AsyncWrite + Unpin, { - let payload: [u8; PING_SIZE] = thread_rng().sample(distributions::Standard); + let payload: [u8; PING_SIZE] = rng().sample(distributions::Standard); stream.write_all(&payload).await?; stream.flush().await?; let started = Instant::now(); @@ -93,7 +93,7 @@ mod tests { #[tokio::test] async fn ping_pong() { - let mem_addr = multiaddr![Memory(thread_rng().gen::())]; + let mem_addr = multiaddr![Memory(rng().gen::())]; let mut transport = MemoryTransport::new().boxed(); transport.listen_on(ListenerId::next(), mem_addr).unwrap(); diff --git a/protocols/relay/Cargo.toml b/protocols/relay/Cargo.toml index ca5c57bce5a..9eedf01a148 100644 --- a/protocols/relay/Cargo.toml +++ b/protocols/relay/Cargo.toml @@ -23,7 +23,7 @@ libp2p-swarm = { workspace = true } libp2p-identity = { workspace = true } quick-protobuf = "0.8" quick-protobuf-codec = { workspace = true } -rand = "0.8.4" +rand = "0.9" static_assertions = "1" thiserror = { workspace = true } tracing = { workspace = true } diff --git a/protocols/rendezvous/Cargo.toml b/protocols/rendezvous/Cargo.toml index 3b79a292b62..3ad12cf0862 100644 --- a/protocols/rendezvous/Cargo.toml +++ b/protocols/rendezvous/Cargo.toml @@ -23,14 +23,14 @@ libp2p-identity = { workspace = true } libp2p-request-response = { workspace = true } quick-protobuf = "0.8" quick-protobuf-codec = { workspace = true } -rand = "0.8" +rand = "0.9" thiserror = { workspace = true } tracing = { workspace = true } [dev-dependencies] libp2p-swarm = { workspace = true, features = ["macros", "tokio"] } libp2p-swarm-test = { path = "../../swarm-test" } -rand = "0.8" +rand = "0.9" tokio = { workspace = true, features = [ "rt-multi-thread", "time", "macros", "sync", "process", "fs", "net" ] } tracing-subscriber = { workspace = true, features = ["env-filter"] } diff --git a/protocols/rendezvous/src/codec.rs b/protocols/rendezvous/src/codec.rs index 60f9f14f332..ccc177739c8 100644 --- a/protocols/rendezvous/src/codec.rs +++ b/protocols/rendezvous/src/codec.rs @@ -116,7 +116,7 @@ impl Cookie { /// namespace. pub fn for_namespace(namespace: Namespace) -> Self { Self { - id: rand::thread_rng().next_u64(), + id: rand::rng().next_u64(), namespace: Some(namespace), } } diff --git a/protocols/request-response/Cargo.toml b/protocols/request-response/Cargo.toml index 913a56bb8e4..bb94e57e2c1 100644 --- a/protocols/request-response/Cargo.toml +++ b/protocols/request-response/Cargo.toml @@ -17,7 +17,7 @@ futures = { workspace = true } libp2p-core = { workspace = true } libp2p-swarm = { workspace = true } libp2p-identity = { workspace = true } -rand = "0.8" +rand = "0.9" serde = { version = "1.0", optional = true} serde_json = { version = "1.0.117", optional = true } smallvec = "1.13.2" @@ -31,7 +31,7 @@ cbor = ["dep:serde", "dep:cbor4ii", "libp2p-swarm/macros"] [dev-dependencies] anyhow = "1.0.86" async-std = { version = "1.6.2", features = ["attributes"] } -rand = "0.8" +rand = "0.9" libp2p-swarm-test = { path = "../../swarm-test" } futures_ringbuf = "0.4.0" serde = { version = "1.0", features = ["derive"] } diff --git a/protocols/request-response/tests/ping.rs b/protocols/request-response/tests/ping.rs index 94adedac2d7..c93d1f5eca8 100644 --- a/protocols/request-response/tests/ping.rs +++ b/protocols/request-response/tests/ping.rs @@ -137,7 +137,7 @@ async fn ping_protocol() { } }; - let num_pings: u8 = rand::thread_rng().gen_range(1..100); + let num_pings: u8 = rand::rng().gen_range(1..100); let peer2 = async { let mut count = 0; diff --git a/protocols/stream/Cargo.toml b/protocols/stream/Cargo.toml index d4114a590b0..16d496c0411 100644 --- a/protocols/stream/Cargo.toml +++ b/protocols/stream/Cargo.toml @@ -15,7 +15,7 @@ libp2p-core = { workspace = true } libp2p-identity = { workspace = true, features = ["peerid"] } libp2p-swarm = { workspace = true } tracing = { workspace = true } -rand = "0.8" +rand = "0.9" [dev-dependencies] libp2p-swarm-test = { workspace = true } diff --git a/protocols/stream/src/shared.rs b/protocols/stream/src/shared.rs index 62d7b3cfe68..bf16312db9e 100644 --- a/protocols/stream/src/shared.rs +++ b/protocols/stream/src/shared.rs @@ -124,7 +124,7 @@ impl Shared { .connections .iter() .filter_map(|(c, p)| (p == &peer).then_some(c)) - .choose(&mut rand::thread_rng()) + .choose(&mut rand::rng()) .and_then(|c| self.senders.get(c)); match maybe_sender { diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index 43e714eb159..7a2f343cef1 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -15,14 +15,14 @@ either = "1.11.0" fnv = "1.0" futures = { workspace = true } futures-timer = "3.0.3" -getrandom = { workspace = true, features = ["js"], optional = true } # Explicit dependency to be used in `wasm-bindgen` feature +getrandom = { workspace = true, features = [], optional = true } # Explicit dependency to be used in `wasm-bindgen` feature web-time = { workspace = true } libp2p-core = { workspace = true } libp2p-identity = { workspace = true } libp2p-swarm-derive = { workspace = true, optional = true } lru = "0.12.3" multistream-select = { workspace = true } -rand = "0.8" +rand = "0.9" smallvec = "1.13.2" tracing = { workspace = true } wasm-bindgen-futures = { version = "0.4.42", optional = true } diff --git a/swarm/src/behaviour/external_addresses.rs b/swarm/src/behaviour/external_addresses.rs index 6aac4d18e85..c093dbb4f96 100644 --- a/swarm/src/behaviour/external_addresses.rs +++ b/swarm/src/behaviour/external_addresses.rs @@ -136,7 +136,7 @@ mod tests { while addresses.as_slice().len() < MAX_LOCAL_EXTERNAL_ADDRS { let random_address = - Multiaddr::empty().with(Protocol::Memory(rand::thread_rng().gen_range(0..1000))); + Multiaddr::empty().with(Protocol::Memory(rand::rng().gen_range(0..1000))); addresses.on_swarm_event(&FromSwarm::ExternalAddrConfirmed(ExternalAddrConfirmed { addr: &random_address, })); diff --git a/swarm/src/handler/multi.rs b/swarm/src/handler/multi.rs index 73af1b1109e..e2fee53409a 100644 --- a/swarm/src/handler/multi.rs +++ b/swarm/src/handler/multi.rs @@ -255,7 +255,7 @@ where // Not always polling handlers in the same order // should give anyone the chance to make progress. - let pos = rand::thread_rng().gen_range(0..self.handlers.len()); + let pos = rand::rng().gen_range(0..self.handlers.len()); for (k, h) in self.handlers.iter_mut().skip(pos) { if let Poll::Ready(e) = h.poll(cx) { diff --git a/transports/noise/Cargo.toml b/transports/noise/Cargo.toml index a3fa86ca220..26480e9921d 100644 --- a/transports/noise/Cargo.toml +++ b/transports/noise/Cargo.toml @@ -17,7 +17,7 @@ libp2p-identity = { workspace = true, features = ["ed25519"] } multiaddr = { workspace = true } multihash = { workspace = true } quick-protobuf = "0.8" -rand = "0.8.3" +rand = "0.9" static_assertions = "1" thiserror = { workspace = true } tracing = { workspace = true } diff --git a/transports/noise/src/protocol.rs b/transports/noise/src/protocol.rs index 2b72a1f23ca..c07bdd96450 100644 --- a/transports/noise/src/protocol.rs +++ b/transports/noise/src/protocol.rs @@ -116,7 +116,7 @@ impl Keypair { /// Create a new X25519 keypair. pub(crate) fn new() -> Keypair { let mut sk_bytes = [0u8; 32]; - rand::thread_rng().fill(&mut sk_bytes); + rand::rng().fill(&mut sk_bytes); let sk = SecretKey(sk_bytes); // Copy sk_bytes.zeroize(); Self::from(sk) diff --git a/transports/pnet/Cargo.toml b/transports/pnet/Cargo.toml index 3c2e706501f..8bbabf047b3 100644 --- a/transports/pnet/Cargo.toml +++ b/transports/pnet/Cargo.toml @@ -15,7 +15,7 @@ futures = { workspace = true } salsa20 = "0.10" sha3 = "0.10" tracing = { workspace = true } -rand = "0.8" +rand = "0.9" pin-project = "1.1.5" [dev-dependencies] diff --git a/transports/pnet/src/lib.rs b/transports/pnet/src/lib.rs index b27f9777c47..792fd3f7834 100644 --- a/transports/pnet/src/lib.rs +++ b/transports/pnet/src/lib.rs @@ -212,7 +212,7 @@ impl PnetConfig { tracing::trace!("exchanging nonces"); let mut local_nonce = [0u8; NONCE_SIZE]; let mut remote_nonce = [0u8; NONCE_SIZE]; - rand::thread_rng().fill_bytes(&mut local_nonce); + rand::rng().fill_bytes(&mut local_nonce); socket .write_all(&local_nonce) .await diff --git a/transports/quic/Cargo.toml b/transports/quic/Cargo.toml index 3e2f685f923..85211530b97 100644 --- a/transports/quic/Cargo.toml +++ b/transports/quic/Cargo.toml @@ -17,7 +17,7 @@ libp2p-core = { workspace = true } libp2p-tls = { workspace = true } libp2p-identity = { workspace = true } quinn = { version = "0.11.6", default-features = false, features = ["rustls", "futures-io"] } -rand = "0.8.5" +rand = "0.9" rustls = { version = "0.23.9", default-features = false } thiserror = { workspace = true } tokio = { workspace = true, default-features = false, features = ["net", "rt", "time"], optional = true } diff --git a/transports/quic/src/hole_punching.rs b/transports/quic/src/hole_punching.rs index 6f1961081d2..a8ae8a0c790 100644 --- a/transports/quic/src/hole_punching.rs +++ b/transports/quic/src/hole_punching.rs @@ -30,7 +30,7 @@ async fn punch_holes( remote_addr: SocketAddr, ) -> Result { loop { - let contents: Vec = rand::thread_rng() + let contents: Vec = rand::rng() .sample_iter(distributions::Standard) .take(64) .collect(); @@ -39,7 +39,7 @@ async fn punch_holes( P::send_to(&socket, &contents, remote_addr).await?; - let sleep_duration = Duration::from_millis(rand::thread_rng().gen_range(10..=200)); + let sleep_duration = Duration::from_millis(rand::rng().gen_range(10..=200)); P::sleep(sleep_duration).await; } } diff --git a/transports/quic/tests/smoke.rs b/transports/quic/tests/smoke.rs index ed2ff981634..efbc510f339 100644 --- a/transports/quic/tests/smoke.rs +++ b/transports/quic/tests/smoke.rs @@ -737,7 +737,7 @@ async fn open_outbound_streams( } let mut data = vec![0; BUFFER_SIZE]; - rand::thread_rng().fill_bytes(&mut data); + rand::rng().fill_bytes(&mut data); let mut received = Vec::new(); diff --git a/transports/webrtc-websys/Cargo.toml b/transports/webrtc-websys/Cargo.toml index e5596da90e4..9146dd855b9 100644 --- a/transports/webrtc-websys/Cargo.toml +++ b/transports/webrtc-websys/Cargo.toml @@ -14,7 +14,7 @@ publish = true [dependencies] bytes = "1" futures = { workspace = true } -getrandom = { workspace = true, features = ["js"] } +getrandom = { workspace = true, features = [] } hex = "0.4.3" js-sys = { version = "0.3" } libp2p-core = { workspace = true } diff --git a/transports/webrtc/Cargo.toml b/transports/webrtc/Cargo.toml index a465bc3ff02..1baae7dfcb2 100644 --- a/transports/webrtc/Cargo.toml +++ b/transports/webrtc/Cargo.toml @@ -21,7 +21,7 @@ libp2p-noise = { workspace = true } libp2p-identity = { workspace = true } libp2p-webrtc-utils = { workspace = true } multihash = { workspace = true } -rand = "0.8" +rand = "0.9" rcgen = "0.11" stun = "0.7" thiserror = { workspace = true } diff --git a/transports/webrtc/src/tokio/certificate.rs b/transports/webrtc/src/tokio/certificate.rs index 7ff35d46bdd..0c8466e67f9 100644 --- a/transports/webrtc/src/tokio/certificate.rs +++ b/transports/webrtc/src/tokio/certificate.rs @@ -38,7 +38,7 @@ impl Certificate { R: CryptoRng + Rng, { let mut params = rcgen::CertificateParams::new(vec![ - rand::distributions::Alphanumeric.sample_string(&mut rand::thread_rng(), 16) + rand::distributions::Alphanumeric.sample_string(&mut rand::rng(), 16) ]); params.alg = &rcgen::PKCS_ECDSA_P256_SHA256; Ok(Self { @@ -100,13 +100,13 @@ enum Kind { #[cfg(all(test, feature = "pem"))] mod test { - use rand::thread_rng; + use rand::rng; use super::*; #[test] fn test_certificate_serialize_pem_and_from_pem() { - let cert = Certificate::generate(&mut thread_rng()).unwrap(); + let cert = Certificate::generate(&mut rng()).unwrap(); let pem = cert.serialize_pem(); let loaded_cert = Certificate::from_pem(&pem).unwrap(); diff --git a/transports/webrtc/src/tokio/transport.rs b/transports/webrtc/src/tokio/transport.rs index 29fad180d93..5389fcad2fb 100644 --- a/transports/webrtc/src/tokio/transport.rs +++ b/transports/webrtc/src/tokio/transport.rs @@ -60,10 +60,10 @@ impl Transport { /// ``` /// use libp2p_identity as identity; /// use libp2p_webrtc::tokio::{Certificate, Transport}; - /// use rand::thread_rng; + /// use rand::rng; /// /// let id_keys = identity::Keypair::generate_ed25519(); - /// let transport = Transport::new(id_keys, Certificate::generate(&mut thread_rng()).unwrap()); + /// let transport = Transport::new(id_keys, Certificate::generate(&mut rng()).unwrap()); /// ``` pub fn new(id_keys: identity::Keypair, certificate: Certificate) -> Self { Self { @@ -429,7 +429,7 @@ mod tests { use futures::future::poll_fn; use libp2p_core::Transport as _; - use rand::thread_rng; + use rand::rng; use super::*; @@ -493,7 +493,7 @@ mod tests { async fn close_listener() { let id_keys = identity::Keypair::generate_ed25519(); let mut transport = - Transport::new(id_keys, Certificate::generate(&mut thread_rng()).unwrap()); + Transport::new(id_keys, Certificate::generate(&mut rng()).unwrap()); assert!(poll_fn(|cx| Pin::new(&mut transport).as_mut().poll(cx)) .now_or_never() diff --git a/transports/webrtc/tests/smoke.rs b/transports/webrtc/tests/smoke.rs index 5f67c09d962..bb716aacbb8 100644 --- a/transports/webrtc/tests/smoke.rs +++ b/transports/webrtc/tests/smoke.rs @@ -41,7 +41,7 @@ use libp2p_core::{ }; use libp2p_identity::PeerId; use libp2p_webrtc as webrtc; -use rand::{thread_rng, RngCore}; +use rand::{rng, RngCore}; use tracing_subscriber::EnvFilter; #[tokio::test] @@ -86,7 +86,7 @@ fn create_transport() -> (PeerId, Boxed<(PeerId, StreamMuxerBox)>) { let transport = webrtc::tokio::Transport::new( keypair, - webrtc::tokio::Certificate::generate(&mut thread_rng()).unwrap(), + webrtc::tokio::Certificate::generate(&mut rng()).unwrap(), ) .map(|(p, c), _| (p, StreamMuxerBox::new(c))) .boxed(); @@ -245,7 +245,7 @@ async fn open_outbound_streams( } let mut data = vec![0; BUFFER_SIZE]; - rand::thread_rng().fill_bytes(&mut data); + rand::rng().fill_bytes(&mut data); let mut received = Vec::new(); diff --git a/wasm-tests/webtransport-tests/Cargo.toml b/wasm-tests/webtransport-tests/Cargo.toml index cd103b46d05..2fe7d559e10 100644 --- a/wasm-tests/webtransport-tests/Cargo.toml +++ b/wasm-tests/webtransport-tests/Cargo.toml @@ -10,7 +10,7 @@ release = false [dependencies] futures = { workspace = true } -getrandom = { workspace = true, features = ["js"] } +getrandom = { workspace = true, features = [] } libp2p-core = { workspace = true } libp2p-identity = { workspace = true, features = ["rand"] } libp2p-noise = { workspace = true } From 7d1469c808e9160c56603381dee40c0fde4a7803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?19=E5=B9=B4=E6=A2=A6=E9=86=92?= <3949379+getong@users.noreply.github.com> Date: Fri, 14 Mar 2025 00:02:41 +0800 Subject: [PATCH 2/3] update code --- misc/connection-limits/src/lib.rs | 2 +- protocols/autonat/src/v2/protocol.rs | 2 +- protocols/gossipsub/src/behaviour/tests.rs | 4 ++-- protocols/gossipsub/src/rpc_proto.rs | 24 +++++++++++----------- protocols/kad/src/behaviour/test.rs | 14 ++++++------- protocols/kad/src/jobs.rs | 8 ++++---- protocols/kad/src/kbucket.rs | 2 +- protocols/kad/src/query/peers/closest.rs | 2 +- protocols/kad/src/record/store/memory.rs | 2 +- protocols/mdns/src/behaviour/iface.rs | 2 +- protocols/mdns/src/behaviour/iface/dns.rs | 4 ++-- protocols/ping/src/protocol.rs | 2 +- protocols/request-response/tests/ping.rs | 2 +- swarm/src/behaviour/external_addresses.rs | 2 +- swarm/src/handler/multi.rs | 4 ++-- transports/quic/src/hole_punching.rs | 2 +- 16 files changed, 39 insertions(+), 39 deletions(-) diff --git a/misc/connection-limits/src/lib.rs b/misc/connection-limits/src/lib.rs index 47f18292dc3..3157f4fc2c4 100644 --- a/misc/connection-limits/src/lib.rs +++ b/misc/connection-limits/src/lib.rs @@ -416,7 +416,7 @@ mod tests { fn fill_outgoing() -> (Swarm, Multiaddr, u32) { use rand::Rng; - let outgoing_limit = rand::rng().gen_range(1..10); + let outgoing_limit = rand::rng().random_range(1..10); let mut network = Swarm::new_ephemeral(|_| { Behaviour::new( diff --git a/protocols/autonat/src/v2/protocol.rs b/protocols/autonat/src/v2/protocol.rs index 70f9f8c37af..ed0c78b1cbd 100644 --- a/protocols/autonat/src/v2/protocol.rs +++ b/protocols/autonat/src/v2/protocol.rs @@ -238,7 +238,7 @@ impl From for proto::Message { impl DialDataRequest { pub(crate) fn from_rng(addr_idx: usize, mut rng: R) -> Self { - let num_bytes = rng.gen_range(DATA_LEN_LOWER_BOUND..=DATA_LEN_UPPER_BOUND); + let num_bytes = rng.random_range(DATA_LEN_LOWER_BOUND..=DATA_LEN_UPPER_BOUND); Self { addr_idx, num_bytes, diff --git a/protocols/gossipsub/src/behaviour/tests.rs b/protocols/gossipsub/src/behaviour/tests.rs index b2b0d23add0..347f99356be 100644 --- a/protocols/gossipsub/src/behaviour/tests.rs +++ b/protocols/gossipsub/src/behaviour/tests.rs @@ -3353,9 +3353,9 @@ fn random_message(seq: &mut u64, topics: &[TopicHash]) -> RawMessage { *seq += 1; RawMessage { source: Some(PeerId::random()), - data: (0..rng.gen_range(10..30)).map(|_| rng.gen()).collect(), + data: (0..rng.random_range(10..30)).map(|_| rng.gen()).collect(), sequence_number: Some(*seq), - topic: topics[rng.gen_range(0..topics.len())].clone(), + topic: topics[rng.random_range(0..topics.len())].clone(), signature: None, key: None, validated: true, diff --git a/protocols/gossipsub/src/rpc_proto.rs b/protocols/gossipsub/src/rpc_proto.rs index d64730e0462..dcba2e58869 100644 --- a/protocols/gossipsub/src/rpc_proto.rs +++ b/protocols/gossipsub/src/rpc_proto.rs @@ -39,27 +39,27 @@ mod test { let new_message1 = super::proto::Message { from: Some(PeerId::random().to_bytes()), - data: Some(rand::rng().gen::<[u8; 32]>().to_vec()), - seqno: Some(rand::rng().gen::<[u8; 8]>().to_vec()), + data: Some(rand::rng().random::<[u8; 32]>().to_vec()), + seqno: Some(rand::rng().random::<[u8; 8]>().to_vec()), topic: topic1.clone().into_string(), - signature: Some(rand::rng().gen::<[u8; 32]>().to_vec()), - key: Some(rand::rng().gen::<[u8; 32]>().to_vec()), + signature: Some(rand::rng().random::<[u8; 32]>().to_vec()), + key: Some(rand::rng().random::<[u8; 32]>().to_vec()), }; let old_message1 = compat::pb::Message { from: Some(PeerId::random().to_bytes()), - data: Some(rand::rng().gen::<[u8; 32]>().to_vec()), - seqno: Some(rand::rng().gen::<[u8; 8]>().to_vec()), + data: Some(rand::rng().random::<[u8; 32]>().to_vec()), + seqno: Some(rand::rng().random::<[u8; 8]>().to_vec()), topic_ids: vec![topic1.clone().into_string()], - signature: Some(rand::rng().gen::<[u8; 32]>().to_vec()), - key: Some(rand::rng().gen::<[u8; 32]>().to_vec()), + signature: Some(rand::rng().random::<[u8; 32]>().to_vec()), + key: Some(rand::rng().random::<[u8; 32]>().to_vec()), }; let old_message2 = compat::pb::Message { from: Some(PeerId::random().to_bytes()), - data: Some(rand::rng().gen::<[u8; 32]>().to_vec()), - seqno: Some(rand::rng().gen::<[u8; 8]>().to_vec()), + data: Some(rand::rng().random::<[u8; 32]>().to_vec()), + seqno: Some(rand::rng().random::<[u8; 8]>().to_vec()), topic_ids: vec![topic1.clone().into_string(), topic2.clone().into_string()], - signature: Some(rand::rng().gen::<[u8; 32]>().to_vec()), - key: Some(rand::rng().gen::<[u8; 32]>().to_vec()), + signature: Some(rand::rng().random::<[u8; 32]>().to_vec()), + key: Some(rand::rng().random::<[u8; 32]>().to_vec()), }; let mut new_message1b = Vec::with_capacity(new_message1.get_size()); diff --git a/protocols/kad/src/behaviour/test.rs b/protocols/kad/src/behaviour/test.rs index 418ece5fd9b..a7e11278254 100644 --- a/protocols/kad/src/behaviour/test.rs +++ b/protocols/kad/src/behaviour/test.rs @@ -137,7 +137,7 @@ fn build_fully_connected_nodes_with_config( } fn random_multihash() -> Multihash<64> { - Multihash::wrap(SHA_256_MH, &rng().gen::<[u8; 32]>()).unwrap() + Multihash::wrap(SHA_256_MH, &rng().random::<[u8; 32]>()).unwrap() } #[derive(Clone, Debug)] @@ -155,14 +155,14 @@ fn bootstrap() { fn prop(seed: Seed) { let mut rng = StdRng::from_seed(seed.0); - let num_total = rng.gen_range(2..20); + let num_total = rng.random_range(2..20); // When looking for the closest node to a key, Kademlia considers // K_VALUE nodes to query at initialization. If `num_group` is larger // than K_VALUE the remaining locally known nodes will not be // considered. Given that no other node is aware of them, they would be // lost entirely. To prevent the above restrict `num_group` to be equal // or smaller than K_VALUE. - let num_group = rng.gen_range(1..(num_total % K_VALUE.get()) + 2); + let num_group = rng.random_range(1..(num_total % K_VALUE.get()) + 2); let mut cfg = Config::new(PROTOCOL_NAME); // Disabling periodic bootstrap and automatic bootstrap to prevent the bootstrap from @@ -246,7 +246,7 @@ fn query_iter() { } fn run(rng: &mut impl Rng) { - let num_total = rng.gen_range(2..20); + let num_total = rng.random_range(2..20); let mut config = Config::new(PROTOCOL_NAME); // Disabling periodic bootstrap and automatic bootstrap to prevent the bootstrap from // triggering automatically. @@ -558,7 +558,7 @@ fn put_record() { fn prop(records: Vec, seed: Seed, filter_records: bool, drop_records: bool) { let mut rng = StdRng::from_seed(seed.0); let replication_factor = - NonZeroUsize::new(rng.gen_range(1..(K_VALUE.get() / 2) + 1)).unwrap(); + NonZeroUsize::new(rng.random_range(1..(K_VALUE.get() / 2) + 1)).unwrap(); // At least 4 nodes, 1 under test + 3 bootnodes. let num_total = usize::max(4, replication_factor.get() * 2); @@ -931,7 +931,7 @@ fn add_provider() { fn prop(keys: Vec, seed: Seed) { let mut rng = StdRng::from_seed(seed.0); let replication_factor = - NonZeroUsize::new(rng.gen_range(1..(K_VALUE.get() / 2) + 1)).unwrap(); + NonZeroUsize::new(rng.random_range(1..(K_VALUE.get() / 2) + 1)).unwrap(); // At least 4 nodes, 1 under test + 3 bootnodes. let num_total = usize::max(4, replication_factor.get() * 2); @@ -1176,7 +1176,7 @@ fn disjoint_query_does_not_finish_before_all_paths_did() { let mut bob = build_node(); let key = Key::from( - Multihash::<64>::wrap(SHA_256_MH, &rng().gen::<[u8; 32]>()) + Multihash::<64>::wrap(SHA_256_MH, &rng().random::<[u8; 32]>()) .expect("32 array to fit into 64 byte multihash"), ); let record_bob = Record::new(key.clone(), b"bob".to_vec()); diff --git a/protocols/kad/src/jobs.rs b/protocols/kad/src/jobs.rs index d3c50564eb4..8b19ba1867b 100644 --- a/protocols/kad/src/jobs.rs +++ b/protocols/kad/src/jobs.rs @@ -347,15 +347,15 @@ mod tests { fn rand_put_record_job() -> PutRecordJob { let mut rng = rand::rng(); let id = PeerId::random(); - let replicate_interval = Duration::from_secs(rng.gen_range(1..60)); - let publish_interval = Some(replicate_interval * rng.gen_range(1..10)); - let record_ttl = Some(Duration::from_secs(rng.gen_range(1..600))); + let replicate_interval = Duration::from_secs(rng.random_range(1..60)); + let publish_interval = Some(replicate_interval * rng.random_range(1..10)); + let record_ttl = Some(Duration::from_secs(rng.random_range(1..600))); PutRecordJob::new(id, replicate_interval, publish_interval, record_ttl) } fn rand_add_provider_job() -> AddProviderJob { let mut rng = rand::rng(); - let interval = Duration::from_secs(rng.gen_range(1..60)); + let interval = Duration::from_secs(rng.random_range(1..60)); AddProviderJob::new(interval) } diff --git a/protocols/kad/src/kbucket.rs b/protocols/kad/src/kbucket.rs index dada6e73538..584f287b82e 100644 --- a/protocols/kad/src/kbucket.rs +++ b/protocols/kad/src/kbucket.rs @@ -175,7 +175,7 @@ impl BucketIndex { let rem = (self.0 % 8) as u32; let lower = usize::pow(2, rem); let upper = usize::pow(2, rem + 1); - bytes[31 - quot] = rng.gen_range(lower..upper) as u8; + bytes[31 - quot] = rng.random_range(lower..upper) as u8; Distance(U256::from_big_endian(bytes.as_slice())) } } diff --git a/protocols/kad/src/query/peers/closest.rs b/protocols/kad/src/query/peers/closest.rs index 2d1f91f050c..2b8a122713a 100644 --- a/protocols/kad/src/query/peers/closest.rs +++ b/protocols/kad/src/query/peers/closest.rs @@ -646,7 +646,7 @@ mod tests { // peers or an error, thus finishing the "in-flight requests". for (i, k) in expected.iter().enumerate() { if rng.gen_bool(0.75) { - let num_closer = rng.gen_range(0..iter.config.num_results.get() + 1); + let num_closer = rng.random_range(0..iter.config.num_results.get() + 1); let closer_peers = random_peers(num_closer, &mut rng); remaining.extend(closer_peers.iter().cloned().map(Key::from)); iter.on_success(k.preimage(), closer_peers); diff --git a/protocols/kad/src/record/store/memory.rs b/protocols/kad/src/record/store/memory.rs index 29daf2e666b..9c6f8c78255 100644 --- a/protocols/kad/src/record/store/memory.rs +++ b/protocols/kad/src/record/store/memory.rs @@ -218,7 +218,7 @@ mod tests { use crate::SHA_256_MH; fn random_multihash() -> Multihash<64> { - Multihash::wrap(SHA_256_MH, &rand::rng().gen::<[u8; 32]>()).unwrap() + Multihash::wrap(SHA_256_MH, &rand::rng().random::<[u8; 32]>()).unwrap() } #[test] fn put_get_remove_record() { diff --git a/protocols/mdns/src/behaviour/iface.rs b/protocols/mdns/src/behaviour/iface.rs index 9f704c7bdd3..afcd9d1fe6f 100644 --- a/protocols/mdns/src/behaviour/iface.rs +++ b/protocols/mdns/src/behaviour/iface.rs @@ -163,7 +163,7 @@ where let query_interval = { use rand::Rng; let mut rng = rand::rng(); - let jitter = rng.gen_range(0..100); + let jitter = rng.random_range(0..100); config.query_interval + Duration::from_millis(jitter) }; let multicast_addr = match addr { diff --git a/protocols/mdns/src/behaviour/iface/dns.rs b/protocols/mdns/src/behaviour/iface/dns.rs index 633dffa7ce5..593f2321611 100644 --- a/protocols/mdns/src/behaviour/iface/dns.rs +++ b/protocols/mdns/src/behaviour/iface/dns.rs @@ -278,7 +278,7 @@ fn random_string(length: usize) -> String { fn generate_peer_name() -> Vec { // Use a variable-length random string for mDNS peer name. // See https://github.com/libp2p/rust-libp2p/pull/2311/ - let peer_name = random_string(32 + rng().gen_range(0..32)); + let peer_name = random_string(32 + rng().random_range(0..32)); // allocate with a little extra padding for QNAME encoding let mut peer_name_bytes = Vec::with_capacity(peer_name.len() + 32); @@ -429,7 +429,7 @@ mod tests { #[test] fn test_random_string() { - let varsize = rng().gen_range(0..32); + let varsize = rng().random_range(0..32); let size = 32 + varsize; let name = random_string(size); assert_eq!(name.len(), size); diff --git a/protocols/ping/src/protocol.rs b/protocols/ping/src/protocol.rs index 9050afd5823..e5b34019549 100644 --- a/protocols/ping/src/protocol.rs +++ b/protocols/ping/src/protocol.rs @@ -93,7 +93,7 @@ mod tests { #[tokio::test] async fn ping_pong() { - let mem_addr = multiaddr![Memory(rng().gen::())]; + let mem_addr = multiaddr![Memory(rng().random::())]; let mut transport = MemoryTransport::new().boxed(); transport.listen_on(ListenerId::next(), mem_addr).unwrap(); diff --git a/protocols/request-response/tests/ping.rs b/protocols/request-response/tests/ping.rs index c93d1f5eca8..333c02427f7 100644 --- a/protocols/request-response/tests/ping.rs +++ b/protocols/request-response/tests/ping.rs @@ -137,7 +137,7 @@ async fn ping_protocol() { } }; - let num_pings: u8 = rand::rng().gen_range(1..100); + let num_pings: u8 = rand::rng().random_range(1..100); let peer2 = async { let mut count = 0; diff --git a/swarm/src/behaviour/external_addresses.rs b/swarm/src/behaviour/external_addresses.rs index c093dbb4f96..b83c086b9cf 100644 --- a/swarm/src/behaviour/external_addresses.rs +++ b/swarm/src/behaviour/external_addresses.rs @@ -136,7 +136,7 @@ mod tests { while addresses.as_slice().len() < MAX_LOCAL_EXTERNAL_ADDRS { let random_address = - Multiaddr::empty().with(Protocol::Memory(rand::rng().gen_range(0..1000))); + Multiaddr::empty().with(Protocol::Memory(rand::rng().random_range(0..1000))); addresses.on_swarm_event(&FromSwarm::ExternalAddrConfirmed(ExternalAddrConfirmed { addr: &random_address, })); diff --git a/swarm/src/handler/multi.rs b/swarm/src/handler/multi.rs index e2fee53409a..1068f71dc47 100644 --- a/swarm/src/handler/multi.rs +++ b/swarm/src/handler/multi.rs @@ -247,7 +247,7 @@ where ) -> Poll< ConnectionHandlerEvent, > { - // Calling `gen_range(0, 0)` (see below) would panic, so we have return early to avoid + // Calling `random_range(0, 0)` (see below) would panic, so we have return early to avoid // that situation. if self.handlers.is_empty() { return Poll::Pending; @@ -255,7 +255,7 @@ where // Not always polling handlers in the same order // should give anyone the chance to make progress. - let pos = rand::rng().gen_range(0..self.handlers.len()); + let pos = rand::rng().random_range(0..self.handlers.len()); for (k, h) in self.handlers.iter_mut().skip(pos) { if let Poll::Ready(e) = h.poll(cx) { diff --git a/transports/quic/src/hole_punching.rs b/transports/quic/src/hole_punching.rs index a8ae8a0c790..f9f7ebae100 100644 --- a/transports/quic/src/hole_punching.rs +++ b/transports/quic/src/hole_punching.rs @@ -39,7 +39,7 @@ async fn punch_holes( P::send_to(&socket, &contents, remote_addr).await?; - let sleep_duration = Duration::from_millis(rand::rng().gen_range(10..=200)); + let sleep_duration = Duration::from_millis(rand::rng().random_range(10..=200)); P::sleep(sleep_duration).await; } } From 606b66ad67751923eb703ee2efe930618e8448a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?19=E5=B9=B4=E6=A2=A6=E9=86=92?= <3949379+getong@users.noreply.github.com> Date: Fri, 14 Mar 2025 00:10:53 +0800 Subject: [PATCH 3/3] update loc file --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1f981a33fdd..47a2e30d88e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -651,9 +651,9 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "base64ct" -version = "1.7.1" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb97d56060ee67d285efb8001fec9d2a4c710c32efd2e14b5cbb5ba71930fc2d" +checksum = "8faa168b8c4ffca39c2699e772943af41ec2b75fb1683dda07b28a6d285c53dc" [[package]] name = "bimap"