diff --git a/Cargo.lock b/Cargo.lock index c9ea14807af..67c1ba524ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3189,7 +3189,6 @@ dependencies = [ "futures", "futures-bounded", "futures-timer", - "instant", "libp2p-core", "libp2p-identity", "libp2p-ping", @@ -3206,6 +3205,7 @@ dependencies = [ "tracing", "tracing-subscriber", "void", + "web-time", ] [[package]] diff --git a/protocols/relay/CHANGELOG.md b/protocols/relay/CHANGELOG.md index b88dd7784f2..83dbf4739ac 100644 --- a/protocols/relay/CHANGELOG.md +++ b/protocols/relay/CHANGELOG.md @@ -2,6 +2,8 @@ - Fix support for unlimited relay connection according to spec. See [PR 5244](https://github.com/libp2p/rust-libp2p/pull/5244). +- use `web_time` `Instant` and `SystemTime` versions for wasm support. + See [PR 5328](https://github.com/libp2p/rust-libp2p/pull/5328). ## 0.17.1 diff --git a/protocols/relay/Cargo.toml b/protocols/relay/Cargo.toml index d4ba1b37d86..35f404d89b4 100644 --- a/protocols/relay/Cargo.toml +++ b/protocols/relay/Cargo.toml @@ -17,7 +17,6 @@ either = "1.11.0" futures = { workspace = true } futures-timer = "3" futures-bounded = { workspace = true } -instant = "0.1.12" libp2p-core = { workspace = true } libp2p-swarm = { workspace = true } libp2p-identity = { workspace = true } @@ -28,6 +27,7 @@ static_assertions = "1" thiserror = "1.0" tracing = { workspace = true } void = "1" +web-time = "1" [dev-dependencies] libp2p-identity = { workspace = true, features = ["rand"] } diff --git a/protocols/relay/src/behaviour.rs b/protocols/relay/src/behaviour.rs index df8443e8359..cf0e76e3662 100644 --- a/protocols/relay/src/behaviour.rs +++ b/protocols/relay/src/behaviour.rs @@ -27,7 +27,6 @@ use crate::multiaddr_ext::MultiaddrExt; use crate::proto; use crate::protocol::{inbound_hop, outbound_stop}; use either::Either; -use instant::Instant; use libp2p_core::multiaddr::Protocol; use libp2p_core::{ConnectedPoint, Endpoint, Multiaddr}; use libp2p_identity::PeerId; @@ -41,6 +40,7 @@ use std::num::NonZeroU32; use std::ops::Add; use std::task::{Context, Poll}; use std::time::Duration; +use web_time::Instant; /// Configuration for the relay [`Behaviour`]. /// diff --git a/protocols/relay/src/behaviour/handler.rs b/protocols/relay/src/behaviour/handler.rs index 958c6a9b906..92557287099 100644 --- a/protocols/relay/src/behaviour/handler.rs +++ b/protocols/relay/src/behaviour/handler.rs @@ -28,7 +28,6 @@ use futures::future::{BoxFuture, FutureExt, TryFutureExt}; use futures::io::AsyncWriteExt; use futures::stream::{FuturesUnordered, StreamExt}; use futures_timer::Delay; -use instant::Instant; use libp2p_core::upgrade::ReadyUpgrade; use libp2p_core::{ConnectedPoint, Multiaddr}; use libp2p_identity::PeerId; @@ -43,6 +42,7 @@ use std::collections::{HashMap, VecDeque}; use std::task::{Context, Poll}; use std::time::Duration; use std::{fmt, io}; +use web_time::Instant; const MAX_CONCURRENT_STREAMS_PER_CONNECTION: usize = 10; const STREAM_TIMEOUT: Duration = Duration::from_secs(60); diff --git a/protocols/relay/src/behaviour/rate_limiter.rs b/protocols/relay/src/behaviour/rate_limiter.rs index 73c164c121c..45b701c1b50 100644 --- a/protocols/relay/src/behaviour/rate_limiter.rs +++ b/protocols/relay/src/behaviour/rate_limiter.rs @@ -18,7 +18,6 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use instant::Instant; use libp2p_core::multiaddr::{Multiaddr, Protocol}; use libp2p_identity::PeerId; use std::collections::{HashMap, VecDeque}; @@ -26,6 +25,7 @@ use std::hash::Hash; use std::net::IpAddr; use std::num::NonZeroU32; use std::time::Duration; +use web_time::Instant; /// Allows rate limiting access to some resource based on the [`PeerId`] and /// [`Multiaddr`] of a remote peer. diff --git a/protocols/relay/src/protocol/inbound_hop.rs b/protocols/relay/src/protocol/inbound_hop.rs index 41fe2675dce..57b5d9ad039 100644 --- a/protocols/relay/src/protocol/inbound_hop.rs +++ b/protocols/relay/src/protocol/inbound_hop.rs @@ -18,7 +18,8 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use std::time::{Duration, SystemTime}; +use std::time::Duration; +use web_time::SystemTime; use asynchronous_codec::{Framed, FramedParts}; use bytes::Bytes; diff --git a/protocols/relay/src/protocol/outbound_hop.rs b/protocols/relay/src/protocol/outbound_hop.rs index 3ae824be167..b349f8848be 100644 --- a/protocols/relay/src/protocol/outbound_hop.rs +++ b/protocols/relay/src/protocol/outbound_hop.rs @@ -19,13 +19,14 @@ // DEALINGS IN THE SOFTWARE. use std::io; -use std::time::{Duration, SystemTime}; +use std::time::Duration; use asynchronous_codec::{Framed, FramedParts}; use bytes::Bytes; use futures::prelude::*; use futures_timer::Delay; use thiserror::Error; +use web_time::SystemTime; use libp2p_core::Multiaddr; use libp2p_identity::PeerId;