diff --git a/Cargo.toml b/Cargo.toml index a8b8fb70..5f853e60 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -86,7 +86,6 @@ futures = "0.3.1" futures-timer = "3.0.2" # Explicit dependency to be used in `wasm-bindgen` feature getrandom = "0.2.3" # Explicit dependency to be used in `wasm-bindgen` feature instant = "0.1.11" # Explicit dependency to be used in `wasm-bindgen` feature -lazy_static = "1.2" libp2p-autonat = { version = "0.9.0", path = "protocols/autonat", optional = true } libp2p-core = { version = "0.38.0", path = "core" } diff --git a/core/Cargo.toml b/core/Cargo.toml index f90e721c..3e39ee79 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -19,7 +19,6 @@ fnv = "1.0" futures = { version = "0.3.1", features = ["executor", "thread-pool"] } futures-timer = "3" instant = "0.1.11" -lazy_static = "1.2" libsecp256k1 = { version = "0.7.0", optional = true } log = "0.4" multiaddr = { version = "0.16.0" } @@ -29,6 +28,7 @@ p256 = { version = "0.11.1", default-features = false, features = ["ecdsa"], opt parking_lot = "0.12.0" pin-project = "1.0.0" prost = "0.11" +once_cell = "1.16.0" rand = "0.8" rw-stream-sink = { version = "0.3.0", path = "../misc/rw-stream-sink" } sha2 = "0.10.0" diff --git a/core/src/transport/memory.rs b/core/src/transport/memory.rs index 8121bfc8..c08fe945 100644 --- a/core/src/transport/memory.rs +++ b/core/src/transport/memory.rs @@ -27,8 +27,8 @@ use futures::{ task::Context, task::Poll, }; -use lazy_static::lazy_static; use multiaddr::{Multiaddr, Protocol}; +use once_cell::sync::Lazy; use parking_lot::Mutex; use rw_stream_sink::RwStreamSink; use std::{ @@ -38,9 +38,7 @@ use std::{ pin::Pin, }; -lazy_static! { - static ref HUB: Hub = Hub(Mutex::new(FnvHashMap::default())); -} +static HUB: Lazy = Lazy::new(|| Hub(Mutex::new(FnvHashMap::default()))); struct Hub(Mutex>); diff --git a/transports/noise/Cargo.toml b/transports/noise/Cargo.toml index 33800c1e..274e7830 100644 --- a/transports/noise/Cargo.toml +++ b/transports/noise/Cargo.toml @@ -12,9 +12,9 @@ repository = "https://github.com/libp2p/rust-libp2p" bytes = "1" curve25519-dalek = "3.0.0" futures = "0.3.1" -lazy_static = "1.2" libp2p-core = { version = "0.38.0", path = "../../core" } log = "0.4" +once_cell = "1.16.0" prost = "0.11" rand = "0.8.3" sha2 = "0.10.0" diff --git a/transports/noise/src/protocol.rs b/transports/noise/src/protocol.rs index 9b57f05d..5a4ea04f 100644 --- a/transports/noise/src/protocol.rs +++ b/transports/noise/src/protocol.rs @@ -309,6 +309,7 @@ impl snow::types::Random for Rng {} mod tests { use super::*; use crate::X25519; + use once_cell::sync::Lazy; #[test] fn handshake_hashes_disagree_if_prologue_differs() { @@ -337,7 +338,5 @@ mod tests { } // Hack to work around borrow-checker. - lazy_static::lazy_static! { - static ref TEST_KEY: Keypair = Keypair::::new(); - } + static TEST_KEY: Lazy> = Lazy::new(Keypair::::new); } diff --git a/transports/noise/src/protocol/x25519.rs b/transports/noise/src/protocol/x25519.rs index 482f2024..a1d542ae 100644 --- a/transports/noise/src/protocol/x25519.rs +++ b/transports/noise/src/protocol/x25519.rs @@ -25,9 +25,9 @@ use crate::{NoiseConfig, NoiseError, Protocol, ProtocolParams}; use curve25519_dalek::edwards::CompressedEdwardsY; -use lazy_static::lazy_static; use libp2p_core::UpgradeInfo; use libp2p_core::{identity, identity::ed25519}; +use once_cell::sync::Lazy; use rand::Rng; use sha2::{Digest, Sha512}; use x25519_dalek::{x25519, X25519_BASEPOINT_BYTES}; @@ -35,20 +35,24 @@ use zeroize::Zeroize; use super::*; -lazy_static! { - static ref PARAMS_IK: ProtocolParams = "Noise_IK_25519_ChaChaPoly_SHA256" +static PARAMS_IK: Lazy = Lazy::new(|| { + "Noise_IK_25519_ChaChaPoly_SHA256" .parse() .map(ProtocolParams) - .expect("Invalid protocol name"); - static ref PARAMS_IX: ProtocolParams = "Noise_IX_25519_ChaChaPoly_SHA256" + .expect("Invalid protocol name") +}); +static PARAMS_IX: Lazy = Lazy::new(|| { + "Noise_IX_25519_ChaChaPoly_SHA256" .parse() .map(ProtocolParams) - .expect("Invalid protocol name"); - static ref PARAMS_XX: ProtocolParams = "Noise_XX_25519_ChaChaPoly_SHA256" + .expect("Invalid protocol name") +}); +static PARAMS_XX: Lazy = Lazy::new(|| { + "Noise_XX_25519_ChaChaPoly_SHA256" .parse() .map(ProtocolParams) - .expect("Invalid protocol name"); -} + .expect("Invalid protocol name") +}); /// A X25519 key. #[derive(Clone)]