From 0fdb20ef5c050241aa71b92d7d047449e5357a30 Mon Sep 17 00:00:00 2001 From: Oliver Wangler Date: Fri, 27 Aug 2021 13:03:26 +0200 Subject: [PATCH 01/16] remove wasm-timer depency (pending gossipsub) --- Cargo.toml | 9 +++++-- core/Cargo.toml | 2 +- core/src/lib.rs | 1 + protocols/gossipsub/Cargo.toml | 23 +++++++++-------- protocols/gossipsub/src/backoff.rs | 3 +-- protocols/gossipsub/src/gossip_promises.rs | 3 +-- protocols/gossipsub/src/handler.rs | 6 +++-- protocols/identify/Cargo.toml | 2 +- protocols/identify/src/handler.rs | 5 ++-- protocols/kad/Cargo.toml | 6 ++--- protocols/kad/src/behaviour.rs | 3 +-- protocols/kad/src/handler.rs | 3 +-- protocols/kad/src/jobs.rs | 14 +++++------ protocols/kad/src/protocol.rs | 3 +-- protocols/kad/src/query.rs | 3 +-- protocols/kad/src/query/peers/closest.rs | 3 +-- .../kad/src/query/peers/closest/disjoint.rs | 3 +-- protocols/kad/src/record.rs | 3 +-- protocols/ping/Cargo.toml | 2 +- protocols/ping/src/handler.rs | 9 ++----- protocols/ping/src/protocol.rs | 3 +-- protocols/relay/Cargo.toml | 1 - protocols/relay/src/handler.rs | 3 +-- protocols/request-response/Cargo.toml | 1 - protocols/request-response/src/handler.rs | 6 +++-- swarm/Cargo.toml | 2 +- swarm/src/protocols_handler.rs | 3 +-- swarm/src/protocols_handler/node_handler.rs | 25 +++++++++---------- swarm/src/protocols_handler/one_shot.rs | 3 +-- 29 files changed, 71 insertions(+), 82 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 05b5ccc8860..7d68acd4619 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,7 +53,7 @@ rendezvous = ["libp2p-rendezvous"] tcp-async-io = ["libp2p-tcp", "libp2p-tcp/async-io"] tcp-tokio = ["libp2p-tcp", "libp2p-tcp/tokio"] uds = ["libp2p-uds"] -wasm-bindgen = ["parking_lot/wasm-bindgen"] +wasm-bindgen = ["futures-timer/wasm-bindgen", "instant/wasm-bindgen", "parking_lot/wasm-bindgen", "getrandom/js"] wasm-ext = ["libp2p-wasm-ext"] wasm-ext-websocket = ["wasm-ext", "libp2p-wasm-ext/websocket"] websocket = ["libp2p-websocket"] @@ -67,6 +67,9 @@ all-features = true atomic = "0.5.0" bytes = "1" futures = "0.3.1" +futures-timer = "3.0.2" +getrandom = "0.2.3" +instant = "0.1.10" lazy_static = "1.2" libp2p-core = { version = "0.30.0", path = "core", default-features = false } libp2p-floodsub = { version = "0.31.0", path = "protocols/floodsub", optional = true } @@ -91,7 +94,6 @@ multiaddr = { version = "0.13.0" } parking_lot = "0.11.0" pin-project = "1.0.0" smallvec = "1.6.1" -wasm-timer = "0.2.4" [target.'cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))'.dependencies] libp2p-deflate = { version = "0.30.0", path = "transports/deflate", optional = true } @@ -141,3 +143,6 @@ members = [ [[example]] name = "chat-tokio" required-features = ["tcp-tokio", "mdns"] + +[patch.crates-io] +instant = { git = "https://github.com/wngr/instant" } diff --git a/core/Cargo.toml b/core/Cargo.toml index e2ca3996738..de26cdac265 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -17,6 +17,7 @@ either = "1.5" fnv = "1.0" futures = { version = "0.3.1", features = ["executor", "thread-pool"] } futures-timer = "3" +instant = "0.1.10" lazy_static = "1.2" libsecp256k1 = { version = "0.6.0", optional = true } log = "0.4" @@ -47,7 +48,6 @@ libp2p-noise = { path = "../transports/noise" } libp2p-tcp = { path = "../transports/tcp" } multihash = { version = "0.14", default-features = false, features = ["arb"] } quickcheck = "0.9.0" -wasm-timer = "0.2" [build-dependencies] prost-build = "0.8" diff --git a/core/src/lib.rs b/core/src/lib.rs index 1a7d841e342..3fe7f74bc9d 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -66,6 +66,7 @@ pub mod upgrade; pub use connection::{Connected, ConnectedPoint, Endpoint}; pub use identity::PublicKey; +pub use instant::{Duration, Instant}; pub use multiaddr::Multiaddr; pub use multihash; pub use muxing::StreamMuxer; diff --git a/protocols/gossipsub/Cargo.toml b/protocols/gossipsub/Cargo.toml index 115051a5ef4..06daf39fdb4 100644 --- a/protocols/gossipsub/Cargo.toml +++ b/protocols/gossipsub/Cargo.toml @@ -10,23 +10,24 @@ keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] [dependencies] -libp2p-swarm = { version = "0.31.0", path = "../../swarm" } -libp2p-core = { version = "0.30.0", path = "../../core", default-features = false } -bytes = "1.0" +asynchronous-codec = "0.6" +base64 = "0.13.0" byteorder = "1.3.4" +bytes = "1.0" fnv = "1.0.7" futures = "0.3.5" -rand = "0.7.3" -asynchronous-codec = "0.6" -wasm-timer = "0.2.4" -unsigned-varint = { version = "0.7.0", features = ["asynchronous_codec"] } +futures-timer = "3.0.2" +hex_fmt = "0.3.0" +libp2p-core = { version = "0.30.0", path = "../../core", default-features = false } +libp2p-swarm = { version = "0.31.0", path = "../../swarm" } log = "0.4.11" -sha2 = "0.9.1" -base64 = "0.13.0" -smallvec = "1.6.1" prost = "0.8" -hex_fmt = "0.3.0" +rand = "0.7.3" regex = "1.4.0" +sha2 = "0.9.1" +smallvec = "1.6.1" +unsigned-varint = { version = "0.7.0", features = ["asynchronous_codec"] } +wasm-timer = "0.2.4" [dev-dependencies] async-std = "1.6.3" diff --git a/protocols/gossipsub/src/backoff.rs b/protocols/gossipsub/src/backoff.rs index c10814d289e..9921ab6d3ab 100644 --- a/protocols/gossipsub/src/backoff.rs +++ b/protocols/gossipsub/src/backoff.rs @@ -20,13 +20,12 @@ //! Data structure for efficiently storing known back-off's when pruning peers. use crate::topic::TopicHash; -use libp2p_core::PeerId; +use libp2p_core::{Instant, PeerId}; use std::collections::{ hash_map::{Entry, HashMap}, HashSet, }; use std::time::Duration; -use wasm_timer::Instant; #[derive(Copy, Clone)] struct HeartbeatIndex(usize); diff --git a/protocols/gossipsub/src/gossip_promises.rs b/protocols/gossipsub/src/gossip_promises.rs index 49b1dde6d66..f0796b7ffba 100644 --- a/protocols/gossipsub/src/gossip_promises.rs +++ b/protocols/gossipsub/src/gossip_promises.rs @@ -21,12 +21,11 @@ use crate::error::ValidationError; use crate::peer_score::RejectReason; use crate::MessageId; -use libp2p_core::PeerId; +use libp2p_core::{Instant, PeerId}; use log::debug; use rand::seq::SliceRandom; use rand::thread_rng; use std::collections::HashMap; -use wasm_timer::Instant; /// Tracks recently sent `IWANT` messages and checks if peers respond to them /// for each `IWANT` message we track one random requested message id. diff --git a/protocols/gossipsub/src/handler.rs b/protocols/gossipsub/src/handler.rs index 4f0810d2934..2090d8b0be3 100644 --- a/protocols/gossipsub/src/handler.rs +++ b/protocols/gossipsub/src/handler.rs @@ -25,7 +25,10 @@ use crate::types::{GossipsubRpc, PeerKind, RawGossipsubMessage}; use asynchronous_codec::Framed; use futures::prelude::*; use futures::StreamExt; -use libp2p_core::upgrade::{InboundUpgrade, NegotiationError, OutboundUpgrade, UpgradeError}; +use libp2p_core::{ + upgrade::{InboundUpgrade, NegotiationError, OutboundUpgrade, UpgradeError}, + Instant, +}; use libp2p_swarm::protocols_handler::{ KeepAlive, ProtocolsHandler, ProtocolsHandlerEvent, ProtocolsHandlerUpgrErr, SubstreamProtocol, }; @@ -39,7 +42,6 @@ use std::{ task::{Context, Poll}, time::Duration, }; -use wasm_timer::Instant; /// The initial time (in seconds) we set the keep alive for protocol negotiations to occur. const INITIAL_KEEP_ALIVE: u64 = 30; diff --git a/protocols/identify/Cargo.toml b/protocols/identify/Cargo.toml index 6f6c37d12e2..d75a0d4bef0 100644 --- a/protocols/identify/Cargo.toml +++ b/protocols/identify/Cargo.toml @@ -11,12 +11,12 @@ categories = ["network-programming", "asynchronous"] [dependencies] futures = "0.3.1" +futures-timer = "3.0.2" libp2p-core = { version = "0.30.0", path = "../../core", default-features = false } libp2p-swarm = { version = "0.31.0", path = "../../swarm" } log = "0.4.1" prost = "0.8" smallvec = "1.6.1" -wasm-timer = "0.2" [dev-dependencies] async-std = "1.6.2" diff --git a/protocols/identify/src/handler.rs b/protocols/identify/src/handler.rs index f0d05f79dc9..4ceb8d25e3d 100644 --- a/protocols/identify/src/handler.rs +++ b/protocols/identify/src/handler.rs @@ -22,6 +22,7 @@ use crate::protocol::{ IdentifyInfo, IdentifyProtocol, IdentifyPushProtocol, InboundPush, OutboundPush, ReplySubstream, }; use futures::prelude::*; +use futures_timer::Delay; use libp2p_core::either::{EitherError, EitherOutput}; use libp2p_core::upgrade::{ EitherUpgrade, InboundUpgrade, OutboundUpgrade, SelectUpgrade, UpgradeError, @@ -32,7 +33,6 @@ use libp2p_swarm::{ }; use smallvec::SmallVec; use std::{io, pin::Pin, task::Context, task::Poll, time::Duration}; -use wasm_timer::Delay; /// Protocol handler for sending and receiving identification requests. /// @@ -189,14 +189,13 @@ impl ProtocolsHandler for IdentifyHandler { // Poll the future that fires when we need to identify the node again. match Future::poll(Pin::new(&mut self.next_id), cx) { Poll::Pending => Poll::Pending, - Poll::Ready(Ok(())) => { + Poll::Ready(()) => { self.next_id.reset(self.interval); let ev = ProtocolsHandlerEvent::OutboundSubstreamRequest { protocol: SubstreamProtocol::new(EitherUpgrade::A(IdentifyProtocol), ()), }; Poll::Ready(ev) } - Poll::Ready(Err(err)) => Poll::Ready(ProtocolsHandlerEvent::Close(err)), } } } diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index 20fe6fe2c75..264a14a5e08 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -11,19 +11,19 @@ categories = ["network-programming", "asynchronous"] [dependencies] arrayvec = "0.5.1" +asynchronous-codec = "0.6" bytes = "1" either = "1.5" fnv = "1.0" -asynchronous-codec = "0.6" futures = "0.3.1" -log = "0.4" +futures-timer = "3.0.2" libp2p-core = { version = "0.30.0", path = "../../core", default-features = false } libp2p-swarm = { version = "0.31.0", path = "../../swarm" } +log = "0.4" prost = "0.8" rand = "0.7.2" sha2 = "0.9.1" smallvec = "1.6.1" -wasm-timer = "0.2" uint = "0.9" unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] } void = "1.0" diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs index 74b5616ff91..726cc3fff6f 100644 --- a/protocols/kad/src/behaviour.rs +++ b/protocols/kad/src/behaviour.rs @@ -40,7 +40,7 @@ use crate::K_VALUE; use fnv::{FnvHashMap, FnvHashSet}; use libp2p_core::{ connection::{ConnectionId, ListenerId}, - ConnectedPoint, Multiaddr, PeerId, + ConnectedPoint, Instant, Multiaddr, PeerId, }; use libp2p_swarm::{ DialError, DialPeerCondition, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler, @@ -54,7 +54,6 @@ use std::num::NonZeroUsize; use std::task::{Context, Poll}; use std::vec; use std::{borrow::Cow, error, time::Duration}; -use wasm_timer::Instant; pub use crate::query::QueryStats; diff --git a/protocols/kad/src/handler.rs b/protocols/kad/src/handler.rs index b92c89bfee5..98f33d8cf1b 100644 --- a/protocols/kad/src/handler.rs +++ b/protocols/kad/src/handler.rs @@ -27,7 +27,7 @@ use futures::prelude::*; use libp2p_core::{ either::EitherOutput, upgrade::{self, InboundUpgrade, OutboundUpgrade}, - ConnectedPoint, PeerId, + ConnectedPoint, Instant, PeerId, }; use libp2p_swarm::{ IntoProtocolsHandler, KeepAlive, NegotiatedSubstream, ProtocolsHandler, ProtocolsHandlerEvent, @@ -37,7 +37,6 @@ use log::trace; use std::{ error, fmt, io, marker::PhantomData, pin::Pin, task::Context, task::Poll, time::Duration, }; -use wasm_timer::Instant; /// A prototype from which [`KademliaHandler`]s can be constructed. pub struct KademliaHandlerProto { diff --git a/protocols/kad/src/jobs.rs b/protocols/kad/src/jobs.rs index 402a797a52d..a788f24f6be 100644 --- a/protocols/kad/src/jobs.rs +++ b/protocols/kad/src/jobs.rs @@ -63,13 +63,13 @@ use crate::record::{self, store::RecordStore, ProviderRecord, Record}; use futures::prelude::*; -use libp2p_core::PeerId; +use futures_timer::Delay; +use libp2p_core::{Instant, PeerId}; use std::collections::HashSet; use std::pin::Pin; use std::task::{Context, Poll}; use std::time::Duration; use std::vec; -use wasm_timer::{Delay, Instant}; /// The maximum number of queries towards which background jobs /// are allowed to start new queries on an invocation of @@ -101,7 +101,7 @@ impl PeriodicJob { if let PeriodicJobState::Waiting(delay, deadline) = &mut self.state { let new_deadline = Instant::now() - Duration::from_secs(1); *deadline = new_deadline; - delay.reset_at(new_deadline); + delay.reset(Duration::from_secs(1)); } } @@ -148,7 +148,7 @@ impl PutRecordJob { ) -> Self { let now = Instant::now(); let deadline = now + replicate_interval; - let delay = Delay::new_at(deadline); + let delay = Delay::new(replicate_interval); let next_publish = publish_interval.map(|i| now + i); Self { local_id, @@ -236,7 +236,7 @@ impl PutRecordJob { // Wait for the next run. let deadline = now + self.inner.interval; - let delay = Delay::new_at(deadline); + let delay = Delay::new(self.inner.interval); self.inner.state = PeriodicJobState::Waiting(delay, deadline); assert!(!self.inner.is_ready(cx, now)); } @@ -262,7 +262,7 @@ impl AddProviderJob { interval, state: { let deadline = now + interval; - PeriodicJobState::Waiting(Delay::new_at(deadline), deadline) + PeriodicJobState::Waiting(Delay::new(interval), deadline) }, }, } @@ -314,7 +314,7 @@ impl AddProviderJob { } let deadline = now + self.inner.interval; - let delay = Delay::new_at(deadline); + let delay = Delay::new(self.inner.interval); self.inner.state = PeriodicJobState::Waiting(delay, deadline); assert!(!self.inner.is_ready(cx, now)); } diff --git a/protocols/kad/src/protocol.rs b/protocols/kad/src/protocol.rs index 0f883649b05..ad2869b4aaa 100644 --- a/protocols/kad/src/protocol.rs +++ b/protocols/kad/src/protocol.rs @@ -33,12 +33,11 @@ use bytes::BytesMut; use codec::UviBytes; use futures::prelude::*; use libp2p_core::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; -use libp2p_core::{Multiaddr, PeerId}; +use libp2p_core::{Instant, Multiaddr, PeerId}; use prost::Message; use std::{borrow::Cow, convert::TryFrom, time::Duration}; use std::{io, iter}; use unsigned_varint::codec; -use wasm_timer::Instant; /// The protocol name used for negotiating with multistream-select. pub const DEFAULT_PROTO_NAME: &[u8] = b"/ipfs/kad/1.0.0"; diff --git a/protocols/kad/src/query.rs b/protocols/kad/src/query.rs index 6fcf90df79f..5c60fb82eb0 100644 --- a/protocols/kad/src/query.rs +++ b/protocols/kad/src/query.rs @@ -30,9 +30,8 @@ use crate::kbucket::{Key, KeyBytes}; use crate::{ALPHA_VALUE, K_VALUE}; use either::Either; use fnv::FnvHashMap; -use libp2p_core::PeerId; +use libp2p_core::{Instant, PeerId}; use std::{num::NonZeroUsize, time::Duration}; -use wasm_timer::Instant; /// A `QueryPool` provides an aggregate state machine for driving `Query`s to completion. /// diff --git a/protocols/kad/src/query/peers/closest.rs b/protocols/kad/src/query/peers/closest.rs index 684c109b934..3300cab2947 100644 --- a/protocols/kad/src/query/peers/closest.rs +++ b/protocols/kad/src/query/peers/closest.rs @@ -22,10 +22,9 @@ use super::*; use crate::kbucket::{Distance, Key, KeyBytes}; use crate::{ALPHA_VALUE, K_VALUE}; -use libp2p_core::PeerId; +use libp2p_core::{Instant, PeerId}; use std::collections::btree_map::{BTreeMap, Entry}; use std::{iter::FromIterator, num::NonZeroUsize, time::Duration}; -use wasm_timer::Instant; pub mod disjoint; diff --git a/protocols/kad/src/query/peers/closest/disjoint.rs b/protocols/kad/src/query/peers/closest/disjoint.rs index 01506ff6f7b..9d60c627521 100644 --- a/protocols/kad/src/query/peers/closest/disjoint.rs +++ b/protocols/kad/src/query/peers/closest/disjoint.rs @@ -20,13 +20,12 @@ use super::*; use crate::kbucket::{Key, KeyBytes}; -use libp2p_core::PeerId; +use libp2p_core::{Instant, PeerId}; use std::{ collections::HashMap, iter::{Cycle, Map, Peekable}, ops::{Index, IndexMut, Range}, }; -use wasm_timer::Instant; /// Wraps around a set of [`ClosestPeersIter`], enforcing a disjoint discovery /// path per configured parallelism according to the S/Kademlia paper. diff --git a/protocols/kad/src/record.rs b/protocols/kad/src/record.rs index 8f1c585d1b8..64733f9ae9e 100644 --- a/protocols/kad/src/record.rs +++ b/protocols/kad/src/record.rs @@ -23,10 +23,9 @@ pub mod store; use bytes::Bytes; -use libp2p_core::{multihash::Multihash, Multiaddr, PeerId}; +use libp2p_core::{multihash::Multihash, Instant, Multiaddr, PeerId}; use std::borrow::Borrow; use std::hash::{Hash, Hasher}; -use wasm_timer::Instant; /// The (opaque) key of a record. #[derive(Clone, Debug, PartialEq, Eq, Hash)] diff --git a/protocols/ping/Cargo.toml b/protocols/ping/Cargo.toml index 24924c48217..ee1c6500aff 100644 --- a/protocols/ping/Cargo.toml +++ b/protocols/ping/Cargo.toml @@ -11,12 +11,12 @@ categories = ["network-programming", "asynchronous"] [dependencies] futures = "0.3.1" +futures-timer = "3.0.2" libp2p-core = { version = "0.30.0", path = "../../core", default-features = false } libp2p-swarm = { version = "0.31.0", path = "../../swarm" } log = "0.4.1" rand = "0.7.2" void = "1.0" -wasm-timer = "0.2" [dev-dependencies] async-std = "1.6.2" diff --git a/protocols/ping/src/handler.rs b/protocols/ping/src/handler.rs index 435a5048485..d10538562de 100644 --- a/protocols/ping/src/handler.rs +++ b/protocols/ping/src/handler.rs @@ -21,6 +21,7 @@ use crate::protocol; use futures::future::BoxFuture; use futures::prelude::*; +use futures_timer::Delay; use libp2p_core::{upgrade::NegotiationError, UpgradeError}; use libp2p_swarm::{ KeepAlive, NegotiatedSubstream, ProtocolsHandler, ProtocolsHandlerEvent, @@ -35,7 +36,6 @@ use std::{ time::Duration, }; use void::Void; -use wasm_timer::Delay; /// The configuration for outbound pings. #[derive(Clone, Debug)] @@ -349,15 +349,10 @@ impl ProtocolsHandler for Handler { self.outbound = Some(PingState::Idle(stream)); break; } - Poll::Ready(Ok(())) => { + Poll::Ready(()) => { self.timer.reset(self.config.timeout); self.outbound = Some(PingState::Ping(protocol::send_ping(stream).boxed())); } - Poll::Ready(Err(e)) => { - return Poll::Ready(ProtocolsHandlerEvent::Close(Failure::Other { - error: Box::new(e), - })) - } }, Some(PingState::OpenStream) => { self.outbound = Some(PingState::OpenStream); diff --git a/protocols/ping/src/protocol.rs b/protocols/ping/src/protocol.rs index a3138568777..5560c1943b2 100644 --- a/protocols/ping/src/protocol.rs +++ b/protocols/ping/src/protocol.rs @@ -19,12 +19,11 @@ // DEALINGS IN THE SOFTWARE. use futures::prelude::*; -use libp2p_core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; +use libp2p_core::{InboundUpgrade, Instant, OutboundUpgrade, UpgradeInfo}; use libp2p_swarm::NegotiatedSubstream; use rand::{distributions, prelude::*}; use std::{io, iter, time::Duration}; use void::Void; -use wasm_timer::Instant; /// The `Ping` protocol upgrade. /// diff --git a/protocols/relay/Cargo.toml b/protocols/relay/Cargo.toml index aedfe262f0b..a17c23ddcda 100644 --- a/protocols/relay/Cargo.toml +++ b/protocols/relay/Cargo.toml @@ -23,7 +23,6 @@ rand = "0.7" smallvec = "1.6.1" unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] } void = "1" -wasm-timer = "0.2" [build-dependencies] prost-build = "0.8" diff --git a/protocols/relay/src/handler.rs b/protocols/relay/src/handler.rs index 79aba915c2f..57b51b68476 100644 --- a/protocols/relay/src/handler.rs +++ b/protocols/relay/src/handler.rs @@ -27,7 +27,7 @@ use futures::prelude::*; use futures::stream::FuturesUnordered; use libp2p_core::connection::ConnectionId; use libp2p_core::either::{EitherError, EitherOutput}; -use libp2p_core::{upgrade, ConnectedPoint, Multiaddr, PeerId}; +use libp2p_core::{upgrade, ConnectedPoint, Instant, Multiaddr, PeerId}; use libp2p_swarm::{ IntoProtocolsHandler, KeepAlive, NegotiatedSubstream, ProtocolsHandler, ProtocolsHandlerEvent, ProtocolsHandlerUpgrErr, SubstreamProtocol, @@ -36,7 +36,6 @@ use log::warn; use std::fmt; use std::task::{Context, Poll}; use std::time::Duration; -use wasm_timer::Instant; pub struct RelayHandlerConfig { pub connection_idle_timeout: Duration, diff --git a/protocols/request-response/Cargo.toml b/protocols/request-response/Cargo.toml index 6f71ec9f408..c10a54b7ef1 100644 --- a/protocols/request-response/Cargo.toml +++ b/protocols/request-response/Cargo.toml @@ -21,7 +21,6 @@ minicbor = { version = "0.11", features = ["std", "derive"] } rand = "0.7" smallvec = "1.6.1" unsigned-varint = { version = "0.7", features = ["std", "futures"] } -wasm-timer = "0.2" [dev-dependencies] async-std = "1.6.2" diff --git a/protocols/request-response/src/handler.rs b/protocols/request-response/src/handler.rs index ee2550df183..a482ec5c285 100644 --- a/protocols/request-response/src/handler.rs +++ b/protocols/request-response/src/handler.rs @@ -26,7 +26,10 @@ use crate::{RequestId, EMPTY_QUEUE_SHRINK_THRESHOLD}; pub use protocol::{ProtocolSupport, RequestProtocol, ResponseProtocol}; use futures::{channel::oneshot, future::BoxFuture, prelude::*, stream::FuturesUnordered}; -use libp2p_core::upgrade::{NegotiationError, UpgradeError}; +use libp2p_core::{ + upgrade::{NegotiationError, UpgradeError}, + Instant, +}; use libp2p_swarm::{ protocols_handler::{ KeepAlive, ProtocolsHandler, ProtocolsHandlerEvent, ProtocolsHandlerUpgrErr, @@ -44,7 +47,6 @@ use std::{ task::{Context, Poll}, time::Duration, }; -use wasm_timer::Instant; /// A connection handler of a `RequestResponse` protocol. #[doc(hidden)] diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index b8e5d77a242..05c4e61f022 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -12,11 +12,11 @@ categories = ["network-programming", "asynchronous"] [dependencies] either = "1.6.0" futures = "0.3.1" +futures-timer = "3.0.2" libp2p-core = { version = "0.30.0", path = "../core", default-features = false } log = "0.4" rand = "0.7" smallvec = "1.6.1" -wasm-timer = "0.2" void = "1" [dev-dependencies] diff --git a/swarm/src/protocols_handler.rs b/swarm/src/protocols_handler.rs index 2000dbc3fb0..861d507cbd1 100644 --- a/swarm/src/protocols_handler.rs +++ b/swarm/src/protocols_handler.rs @@ -48,9 +48,8 @@ mod select; pub use crate::upgrade::{InboundUpgradeSend, OutboundUpgradeSend, SendWrapper, UpgradeInfoSend}; -use libp2p_core::{upgrade::UpgradeError, ConnectedPoint, Multiaddr, PeerId}; +use libp2p_core::{upgrade::UpgradeError, ConnectedPoint, Instant, Multiaddr, PeerId}; use std::{cmp::Ordering, error, fmt, task::Context, task::Poll, time::Duration}; -use wasm_timer::Instant; pub use dummy::DummyProtocolsHandler; pub use map_in::MapInEvent; diff --git a/swarm/src/protocols_handler/node_handler.rs b/swarm/src/protocols_handler/node_handler.rs index 8254968c6e8..19962b53227 100644 --- a/swarm/src/protocols_handler/node_handler.rs +++ b/swarm/src/protocols_handler/node_handler.rs @@ -26,6 +26,7 @@ use crate::upgrade::SendWrapper; use futures::prelude::*; use futures::stream::FuturesUnordered; +use futures_timer::Delay; use libp2p_core::{ connection::{ ConnectionHandler, ConnectionHandlerEvent, IntoConnectionHandler, Substream, @@ -33,10 +34,9 @@ use libp2p_core::{ }, muxing::StreamMuxerBox, upgrade::{self, InboundUpgradeApply, OutboundUpgradeApply, UpgradeError}, - Connected, Multiaddr, + Connected, Instant, Multiaddr, }; use std::{error, fmt, pin::Pin, task::Context, task::Poll, time::Duration}; -use wasm_timer::{Delay, Instant}; /// Prototype for a `NodeHandlerWrapper`. pub struct NodeHandlerWrapperBuilder { @@ -159,7 +159,7 @@ where fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll { match self.timeout.poll_unpin(cx) { - Poll::Ready(Ok(_)) => { + Poll::Ready(()) => { return Poll::Ready(( self.user_data .take() @@ -167,14 +167,7 @@ where Err(ProtocolsHandlerUpgrErr::Timeout), )) } - Poll::Ready(Err(_)) => { - return Poll::Ready(( - self.user_data - .take() - .expect("Future not to be polled again once ready."), - Err(ProtocolsHandlerUpgrErr::Timer), - )) - } + Poll::Pending => {} } @@ -362,10 +355,16 @@ where (Shutdown::Later(timer, deadline), KeepAlive::Until(t)) => { if *deadline != t { *deadline = t; - timer.reset_at(t) + if let Some(dur) = deadline.checked_duration_since(Instant::now()) { + timer.reset(dur) + } + } + } + (_, KeepAlive::Until(t)) => { + if let Some(dur) = t.checked_duration_since(Instant::now()) { + self.shutdown = Shutdown::Later(Delay::new(dur), t) } } - (_, KeepAlive::Until(t)) => self.shutdown = Shutdown::Later(Delay::new_at(t), t), (_, KeepAlive::No) => self.shutdown = Shutdown::Asap, (_, KeepAlive::Yes) => self.shutdown = Shutdown::None, }; diff --git a/swarm/src/protocols_handler/one_shot.rs b/swarm/src/protocols_handler/one_shot.rs index 01a2951efc5..bef097bf672 100644 --- a/swarm/src/protocols_handler/one_shot.rs +++ b/swarm/src/protocols_handler/one_shot.rs @@ -22,10 +22,9 @@ use crate::protocols_handler::{ KeepAlive, ProtocolsHandler, ProtocolsHandlerEvent, ProtocolsHandlerUpgrErr, SubstreamProtocol, }; use crate::upgrade::{InboundUpgradeSend, OutboundUpgradeSend}; - +use libp2p_core::Instant; use smallvec::SmallVec; use std::{error, fmt::Debug, task::Context, task::Poll, time::Duration}; -use wasm_timer::Instant; /// A `ProtocolsHandler` that opens a new substream for each request. // TODO: Debug From 92b6bfcc393c14f896cf1e1cc0f56657699b49f6 Mon Sep 17 00:00:00 2001 From: Oliver Wangler Date: Fri, 27 Aug 2021 20:50:23 +0200 Subject: [PATCH 02/16] make ws transport work with SharedArrayBuffer --- transports/wasm-ext/src/websockets.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/transports/wasm-ext/src/websockets.js b/transports/wasm-ext/src/websockets.js index 290af968e70..3e7de1f76cb 100644 --- a/transports/wasm-ext/src/websockets.js +++ b/transports/wasm-ext/src/websockets.js @@ -80,7 +80,18 @@ const dial = (addr) => { read: (function*() { while(ws.readyState == 1) { yield reader.next(); } })(), write: (data) => { if (ws.readyState == 1) { - ws.send(data); + // The passed in `data` is an `ArrayBufferView` [0]. If the + // underlying typed array is a `SharedArrayBuffer` (when + // using WASM threads, so multiple web workers sharing + // memory) the WebSocket's `send` method errors [1][2][3]. + // This limitation will probably be lifted in the future, + // but for now we have to make a copy here .. + // + // [0]: https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView + // [1]: https://chromium.googlesource.com/chromium/src/+/1438f63f369fed3766fa5031e7a252c986c69be6%5E%21/ + // [2]: https://bugreports.qt.io/browse/QTBUG-78078 + // [3]: https://chromium.googlesource.com/chromium/src/+/HEAD/third_party/blink/renderer/bindings/IDLExtendedAttributes.md#AllowShared_p + ws.send(data.slice(0)); return promise_when_send_finished(ws); } else { return Promise.reject("WebSocket is closed"); From 85970e73b0dbf5a4a99e95d7fd09b8227f948ab9 Mon Sep 17 00:00:00 2001 From: wngr Date: Wed, 22 Sep 2021 16:25:16 +0200 Subject: [PATCH 03/16] add rand --- Cargo.toml | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7d68acd4619..099f8d9cac4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,7 +53,7 @@ rendezvous = ["libp2p-rendezvous"] tcp-async-io = ["libp2p-tcp", "libp2p-tcp/async-io"] tcp-tokio = ["libp2p-tcp", "libp2p-tcp/tokio"] uds = ["libp2p-uds"] -wasm-bindgen = ["futures-timer/wasm-bindgen", "instant/wasm-bindgen", "parking_lot/wasm-bindgen", "getrandom/js"] +wasm-bindgen = ["futures-timer/wasm-bindgen", "instant/wasm-bindgen", "parking_lot/wasm-bindgen", "getrandom/js", "rand/wasm-bindgen" ] wasm-ext = ["libp2p-wasm-ext"] wasm-ext-websocket = ["wasm-ext", "libp2p-wasm-ext/websocket"] websocket = ["libp2p-websocket"] @@ -65,12 +65,12 @@ all-features = true [dependencies] atomic = "0.5.0" -bytes = "1" -futures = "0.3.1" +bytes = "1.1.0" +futures = "0.3.17" futures-timer = "3.0.2" getrandom = "0.2.3" instant = "0.1.10" -lazy_static = "1.2" +lazy_static = "1.4.0" libp2p-core = { version = "0.30.0", path = "core", default-features = false } libp2p-floodsub = { version = "0.31.0", path = "protocols/floodsub", optional = true } libp2p-gossipsub = { version = "0.33.0", path = "./protocols/gossipsub", optional = true } @@ -90,9 +90,10 @@ libp2p-swarm-derive = { version = "0.25.0", path = "swarm-derive" } libp2p-uds = { version = "0.30.0", path = "transports/uds", optional = true } libp2p-wasm-ext = { version = "0.30.0", path = "transports/wasm-ext", default-features = false, optional = true } libp2p-yamux = { version = "0.34.0", path = "muxers/yamux", optional = true } -multiaddr = { version = "0.13.0" } -parking_lot = "0.11.0" -pin-project = "1.0.0" +multiaddr = "0.13.0" +parking_lot = "0.11.2" +pin-project = "1.0.8" +rand = "0.7.3" smallvec = "1.6.1" [target.'cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))'.dependencies] @@ -103,11 +104,11 @@ libp2p-tcp = { version = "0.30.0", path = "transports/tcp", default-features = f libp2p-websocket = { version = "0.31.0", path = "transports/websocket", optional = true } [dev-dependencies] -async-std = { version = "1.6.2", features = ["attributes"] } -async-trait = "0.1" +async-std = { version = "1.10.0", features = ["attributes"] } +async-trait = "0.1.51" env_logger = "0.9.0" -structopt = "0.3.21" -tokio = { version = "1.0.1", features = ["io-util", "io-std", "macros", "rt", "rt-multi-thread"] } +structopt = "0.3.23" +tokio = { version = "1.12.0", features = ["io-util", "io-std", "macros", "rt", "rt-multi-thread"] } [workspace] resolver = "2" From a3b54977269d648dbde7e9b32ba3fdf2c6b93850 Mon Sep 17 00:00:00 2001 From: wngr Date: Wed, 22 Sep 2021 21:17:09 +0200 Subject: [PATCH 04/16] remove wasm-timer from rendezvous --- Cargo.toml | 3 ++- protocols/rendezvous/Cargo.toml | 14 +++++++------- protocols/rendezvous/src/client.rs | 4 ++-- protocols/rendezvous/src/server.rs | 10 ++-------- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 099f8d9cac4..76b60513567 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -146,4 +146,5 @@ name = "chat-tokio" required-features = ["tcp-tokio", "mdns"] [patch.crates-io] -instant = { git = "https://github.com/wngr/instant" } +# wait for a new release, see https://github.com/sebcrozet/instant/pull/36 +instant = { git = "https://github.com/sebcrozet/instant" } diff --git a/protocols/rendezvous/Cargo.toml b/protocols/rendezvous/Cargo.toml index aa2cb8d9c6e..9bc798392da 100644 --- a/protocols/rendezvous/Cargo.toml +++ b/protocols/rendezvous/Cargo.toml @@ -11,18 +11,18 @@ categories = ["network-programming", "asynchronous"] [dependencies] asynchronous-codec = "0.6" +bimap = "0.6.1" +futures = { version = "0.3", default-features = false, features = ["std"] } +futures-timer = "3.0.2" libp2p-core = { version = "0.30.0", path = "../../core", default-features = false } libp2p-swarm = { version = "0.31.0", path = "../../swarm" } -prost = "0.8" -void = "1" log = "0.4" -futures = { version = "0.3", default-features = false, features = ["std"] } +prost = "0.8" +rand = "0.8" +sha2 = "0.9" thiserror = "1" unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] } -bimap = "0.6.1" -sha2 = "0.9" -rand = "0.8" -wasm-timer = "0.2" +void = "1" [dev-dependencies] libp2p = { path = "../.." } diff --git a/protocols/rendezvous/src/client.rs b/protocols/rendezvous/src/client.rs index 73eb90edb38..05dba57b185 100644 --- a/protocols/rendezvous/src/client.rs +++ b/protocols/rendezvous/src/client.rs @@ -310,8 +310,8 @@ fn handle_outbound_event( expiring_registrations.extend(registrations.iter().cloned().map(|registration| { async move { // if the timer errors we consider it expired - let _ = - wasm_timer::Delay::new(Duration::from_secs(registration.ttl as u64)).await; + let _ = futures_timer::Delay::new(Duration::from_secs(registration.ttl as u64)) + .await; (registration.record.peer_id(), registration.namespace) } diff --git a/protocols/rendezvous/src/server.rs b/protocols/rendezvous/src/server.rs index 93682dda422..33a9af4f0fd 100644 --- a/protocols/rendezvous/src/server.rs +++ b/protocols/rendezvous/src/server.rs @@ -381,14 +381,8 @@ impl Registrations { self.registrations .insert(registration_id, registration.clone()); - let next_expiry = wasm_timer::Delay::new(Duration::from_secs(ttl as u64)) - .map(move |result| { - if result.is_err() { - log::warn!("Timer for registration {} has unexpectedly errored, treating it as expired", registration_id.0); - } - - registration_id - }) + let next_expiry = futures_timer::Delay::new(Duration::from_secs(ttl as u64)) + .map(move |_| registration_id) .boxed(); self.next_expiry.push(next_expiry); From e57de9b5e904f71e556b18613953cf4fd73818d9 Mon Sep 17 00:00:00 2001 From: wngr Date: Thu, 23 Sep 2021 10:22:21 +0200 Subject: [PATCH 05/16] use upstream instant --- Cargo.toml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 76b60513567..74e16a339e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -69,7 +69,7 @@ bytes = "1.1.0" futures = "0.3.17" futures-timer = "3.0.2" getrandom = "0.2.3" -instant = "0.1.10" +instant = "0.1.11" lazy_static = "1.4.0" libp2p-core = { version = "0.30.0", path = "core", default-features = false } libp2p-floodsub = { version = "0.31.0", path = "protocols/floodsub", optional = true } @@ -144,7 +144,3 @@ members = [ [[example]] name = "chat-tokio" required-features = ["tcp-tokio", "mdns"] - -[patch.crates-io] -# wait for a new release, see https://github.com/sebcrozet/instant/pull/36 -instant = { git = "https://github.com/sebcrozet/instant" } From c8e2b0e2cbec63bf45666294ec30a09c3c60da70 Mon Sep 17 00:00:00 2001 From: wngr Date: Mon, 27 Sep 2021 14:39:01 +0200 Subject: [PATCH 06/16] protocols/gossipsup: get rid of `wasm-timer` --- protocols/gossipsub/Cargo.toml | 2 +- protocols/gossipsub/src/behaviour.rs | 9 +- protocols/gossipsub/src/interval.rs | 210 +++++++++++++++++++++++++++ protocols/gossipsub/src/lib.rs | 1 + 4 files changed, 216 insertions(+), 6 deletions(-) create mode 100644 protocols/gossipsub/src/interval.rs diff --git a/protocols/gossipsub/Cargo.toml b/protocols/gossipsub/Cargo.toml index 06daf39fdb4..db420037ce4 100644 --- a/protocols/gossipsub/Cargo.toml +++ b/protocols/gossipsub/Cargo.toml @@ -21,13 +21,13 @@ hex_fmt = "0.3.0" libp2p-core = { version = "0.30.0", path = "../../core", default-features = false } libp2p-swarm = { version = "0.31.0", path = "../../swarm" } log = "0.4.11" +pin-project = "1.0.8" prost = "0.8" rand = "0.7.3" regex = "1.4.0" sha2 = "0.9.1" smallvec = "1.6.1" unsigned-varint = { version = "0.7.0", features = ["asynchronous_codec"] } -wasm-timer = "0.2.4" [dev-dependencies] async-std = "1.6.3" diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index 65c551a2f3c..a52d8699c6b 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -34,18 +34,16 @@ use futures::StreamExt; use log::{debug, error, trace, warn}; use prost::Message; use rand::{seq::SliceRandom, thread_rng}; -use wasm_timer::{Instant, Interval}; use libp2p_core::{ connection::ConnectionId, identity::Keypair, multiaddr::Protocol::Ip4, - multiaddr::Protocol::Ip6, ConnectedPoint, Multiaddr, PeerId, + multiaddr::Protocol::Ip6, ConnectedPoint, Instant, Multiaddr, PeerId, }; use libp2p_swarm::{ DialPeerCondition, IntoProtocolsHandler, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler, PollParameters, }; -use crate::backoff::BackoffStorage; use crate::config::{GossipsubConfig, ValidationMode}; use crate::error::{PublishError, SubscriptionError, ValidationError}; use crate::gossip_promises::GossipPromises; @@ -62,6 +60,7 @@ use crate::types::{ GossipsubSubscriptionAction, MessageAcceptance, MessageId, PeerInfo, RawGossipsubMessage, }; use crate::types::{GossipsubRpc, PeerConnections, PeerKind}; +use crate::{backoff::BackoffStorage, interval::Interval}; use crate::{rpc_proto, TopicScoreParams}; use std::{cmp::Ordering::Equal, fmt::Debug}; @@ -406,8 +405,8 @@ where config.backoff_slack(), ), mcache: MessageCache::new(config.history_gossip(), config.history_length()), - heartbeat: Interval::new_at( - Instant::now() + config.heartbeat_initial_delay(), + heartbeat: Interval::new_initial( + config.heartbeat_initial_delay(), config.heartbeat_interval(), ), heartbeat_ticks: 0, diff --git a/protocols/gossipsub/src/interval.rs b/protocols/gossipsub/src/interval.rs new file mode 100644 index 00000000000..3fd515ad4d2 --- /dev/null +++ b/protocols/gossipsub/src/interval.rs @@ -0,0 +1,210 @@ +// Copyright 2021 Oliver Wangler +// Copyright 2019 Pierre Krieger +// Copyright (c) 2019 Tokio Contributors +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of +// this software and associated documentation files (the "Software"), to deal in +// the Software without restriction, including without limitation the rights to +// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +// the Software, and to permit persons to whom the Software is furnished to do so, +// subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +// OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +// Initial version copied from +// https://github.com/tomaka/wasm-timer/blob/8964804eff980dd3eb115b711c57e481ba541708/src/timer/interval.rs +// and adapted. +use std::{ + pin::Pin, + task::{Context, Poll}, + time::Duration, +}; + +use futures::prelude::*; +use futures_timer::Delay; +use libp2p_core::Instant; +use pin_project::pin_project; + +/// A stream representing notifications at fixed interval +/// +/// Intervals are created through the `Interval::new` or +/// `Interval::new_intial` methods indicating when a first notification +/// should be triggered and when it will be repeated. +/// +/// Note that intervals are not intended for high resolution timers, but rather +/// they will likely fire some granularity after the exact instant that they're +/// otherwise indicated to fire at. +#[pin_project] +#[derive(Debug)] +pub struct Interval { + #[pin] + delay: Delay, + interval: Duration, + fires_at: Instant, +} + +impl Interval { + /// Creates a new interval which will fire at `dur` time into the future, + /// and will repeat every `dur` interval after + /// + /// The returned object will be bound to the default timer for this thread. + /// The default timer will be spun up in a helper thread on first use. + pub fn new(dur: Duration) -> Interval { + Interval::new_initial(dur, dur) + } + + /// Creates a new interval which will fire the first time after the specified `initial_delay`, + /// and then will repeat every `dur` interval after. + /// + /// The returned object will be bound to the default timer for this thread. + /// The default timer will be spun up in a helper thread on first use. + pub fn new_initial(initial_delay: Duration, dur: Duration) -> Interval { + let fires_at = Instant::now() + initial_delay; + Interval { + delay: Delay::new(initial_delay), + interval: dur, + fires_at, + } + } +} + +impl Stream for Interval { + type Item = (); + + fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { + if self.as_mut().project().delay.poll(cx).is_pending() { + return Poll::Pending; + } + let next = next_interval(self.fires_at, Instant::now(), self.interval); + self.delay.reset(next); + self.fires_at += next; + Poll::Ready(Some(())) + } +} + +/// Converts Duration object to raw nanoseconds if possible +/// +/// This is useful to divide intervals. +/// +/// While technically for large duration it's impossible to represent any +/// duration as nanoseconds, the largest duration we can represent is about +/// 427_000 years. Large enough for any interval we would use or calculate in +/// tokio. +fn duration_to_nanos(dur: Duration) -> Option { + dur.as_secs() + .checked_mul(1_000_000_000) + .and_then(|v| v.checked_add(dur.subsec_nanos() as u64)) +} + +fn next_interval(prev: Instant, now: Instant, interval: Duration) -> Duration { + let new = prev + interval; + if new > now { + interval + } else { + let spent_ns = + duration_to_nanos(now.duration_since(prev)).expect("interval should be expired"); + let interval_ns = + duration_to_nanos(interval).expect("interval is less that 427 thousand years"); + let mult = spent_ns / interval_ns + 1; + assert!( + mult < (1 << 32), + "can't skip more than 4 billion intervals of {:?} \ + (trying to skip {})", + interval, + mult + ); + interval * mult as u32 + } +} + +#[cfg(test)] +mod test { + use super::next_interval; + use std::time::{Duration, Instant}; + + struct Timeline(Instant); + + impl Timeline { + fn new() -> Timeline { + Timeline(Instant::now()) + } + fn at(&self, millis: u64) -> Instant { + self.0 + Duration::from_millis(millis) + } + fn at_ns(&self, sec: u64, nanos: u32) -> Instant { + self.0 + Duration::new(sec, nanos) + } + } + + fn dur(millis: u64) -> Duration { + Duration::from_millis(millis) + } + + // The math around Instant/Duration isn't 100% precise due to rounding + // errors + fn almost_eq(a: Instant, b: Instant) -> bool { + let diff = match a.cmp(&b) { + std::cmp::Ordering::Less => b - a, + std::cmp::Ordering::Equal => return true, + std::cmp::Ordering::Greater => a - b, + }; + + diff < Duration::from_millis(1) + } + + #[test] + fn norm_next() { + let tm = Timeline::new(); + assert!(almost_eq( + tm.at(1) + next_interval(tm.at(1), tm.at(2), dur(10)), + tm.at(11) + )); + assert!(almost_eq( + tm.at(7777) + next_interval(tm.at(7777), tm.at(7788), dur(100)), + tm.at(7877) + )); + assert!(almost_eq( + tm.at(1) + next_interval(tm.at(1), tm.at(1000), dur(2100)), + tm.at(2101) + )); + } + + #[test] + fn fast_forward() { + let tm = Timeline::new(); + + assert!(almost_eq( + tm.at(1) + next_interval(tm.at(1), tm.at(1000), dur(10)), + tm.at(1001) + )); + assert!(almost_eq( + tm.at(7777) + next_interval(tm.at(7777), tm.at(8888), dur(100)), + tm.at(8977) + )); + assert!(almost_eq( + tm.at(1) + next_interval(tm.at(1), tm.at(10000), dur(2100)), + tm.at(10501) + )); + } + + /// TODO: this test actually should be successful, but since we can't + /// multiply Duration on anything larger than u32 easily we decided + /// to allow it to fail for now + #[test] + #[should_panic(expected = "can't skip more than 4 billion intervals")] + fn large_skip() { + let tm = Timeline::new(); + assert_eq!( + tm.0 + next_interval(tm.at_ns(0, 1), tm.at_ns(25, 0), Duration::new(0, 2)), + tm.at_ns(25, 1) + ); + } +} diff --git a/protocols/gossipsub/src/lib.rs b/protocols/gossipsub/src/lib.rs index ddba0f69a1e..5a426d51df8 100644 --- a/protocols/gossipsub/src/lib.rs +++ b/protocols/gossipsub/src/lib.rs @@ -130,6 +130,7 @@ mod behaviour; mod config; mod gossip_promises; mod handler; +mod interval; mod mcache; mod peer_score; pub mod subscription_filter; From c82735f94a7e3d16253463193acbb99efca8b031 Mon Sep 17 00:00:00 2001 From: wngr Date: Mon, 27 Sep 2021 14:45:22 +0200 Subject: [PATCH 07/16] ci: add wasm32-unknown-unknown build --- .github/workflows/ci.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d4148477108..b1656697226 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,6 +60,13 @@ jobs: target: wasm32-wasi override: true + - name: Install Rust wasm32-unknown-unknown + uses: actions-rs/toolchain@v1.0.7 + with: + toolchain: stable + target: wasm32-unknown-unknown + override: true + - name: Install a recent version of clang run: | apt-get update @@ -80,6 +87,11 @@ jobs: # TODO: ideally we would build `--workspace`, but not all crates compile for WASM run: cargo build --target=wasm32-wasi + - name: Build on wasm32-wasi + # TODO: also run `cargo test` + # TODO: ideally we would build `--workspace`, but not all crates compile for WASM + run: cargo build --target=wasm32-unknown-unknown --features wasm-bindgen + check-rustdoc-links: name: Check rustdoc intra-doc links runs-on: ubuntu-latest From 9a3494e065c25f1bd0a8e9eaf234aa0f0a3e3b89 Mon Sep 17 00:00:00 2001 From: wngr Date: Thu, 30 Sep 2021 22:26:31 +0200 Subject: [PATCH 08/16] protocols/rendezvous: replace usage of std::time::instant with libp2p_core::Instant --- protocols/rendezvous/src/substream_handler.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/protocols/rendezvous/src/substream_handler.rs b/protocols/rendezvous/src/substream_handler.rs index efd7956b13c..e301736d4a1 100644 --- a/protocols/rendezvous/src/substream_handler.rs +++ b/protocols/rendezvous/src/substream_handler.rs @@ -27,7 +27,7 @@ use futures::future::{self, BoxFuture, Fuse, FusedFuture}; use futures::FutureExt; -use libp2p_core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; +use libp2p_core::{InboundUpgrade, Instant, OutboundUpgrade, UpgradeInfo}; use libp2p_swarm::protocols_handler::{InboundUpgradeSend, OutboundUpgradeSend}; use libp2p_swarm::{ KeepAlive, NegotiatedSubstream, ProtocolsHandler, ProtocolsHandlerEvent, @@ -38,7 +38,7 @@ use std::fmt; use std::future::Future; use std::hash::Hash; use std::task::{Context, Poll}; -use std::time::{Duration, Instant}; +use std::time::Duration; use void::Void; /// Handles a substream throughout its lifetime. From 0aab228a63d764ca08c5685ae2afc3cd223b6db0 Mon Sep 17 00:00:00 2001 From: wngr Date: Fri, 1 Oct 2021 11:19:17 +0200 Subject: [PATCH 09/16] protocols/gossipsub: replace leftovers --- protocols/gossipsub/src/peer_score.rs | 4 ++-- protocols/gossipsub/src/time_cache.rs | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/protocols/gossipsub/src/peer_score.rs b/protocols/gossipsub/src/peer_score.rs index 9e78ff69d4b..b9e1d1742c8 100644 --- a/protocols/gossipsub/src/peer_score.rs +++ b/protocols/gossipsub/src/peer_score.rs @@ -23,11 +23,11 @@ use crate::time_cache::TimeCache; use crate::{MessageId, TopicHash}; -use libp2p_core::PeerId; +use libp2p_core::{Instant, PeerId}; use log::{debug, trace, warn}; use std::collections::{hash_map, HashMap, HashSet}; use std::net::IpAddr; -use std::time::{Duration, Instant}; +use std::time::Duration; mod params; use crate::error::ValidationError; diff --git a/protocols/gossipsub/src/time_cache.rs b/protocols/gossipsub/src/time_cache.rs index 90300e77ea3..b718d19ac56 100644 --- a/protocols/gossipsub/src/time_cache.rs +++ b/protocols/gossipsub/src/time_cache.rs @@ -21,12 +21,13 @@ //! This implements a time-based LRU cache for checking gossipsub message duplicates. use fnv::FnvHashMap; +use libp2p_core::Instant; use std::collections::hash_map::{ self, Entry::{Occupied, Vacant}, }; use std::collections::VecDeque; -use std::time::{Duration, Instant}; +use std::time::Duration; struct ExpiringElement { /// The element that expires From eeb366ac6ca65d0ee639e27878dc1887428b6e31 Mon Sep 17 00:00:00 2001 From: wngr Date: Sun, 10 Oct 2021 20:54:37 +0200 Subject: [PATCH 10/16] PR comments - first round --- .github/workflows/ci.yml | 14 +++++--------- Cargo.toml | 4 ++++ transports/wasm-ext/src/websockets.js | 22 +++++++++++----------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 231085f4c02..70821f2ad52 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,6 +39,7 @@ jobs: matrix: toolchain: [ wasm32-unknown-emscripten, + wasm32-unknown-unknown, wasm32-wasi ] container: @@ -61,13 +62,6 @@ jobs: target: ${{ matrix.toolchain }} override: true - - name: Install Rust wasm32-unknown-unknown - uses: actions-rs/toolchain@v1.0.7 - with: - toolchain: stable - target: wasm32-unknown-unknown - override: true - - name: Install a recent version of clang run: | apt-get update @@ -81,14 +75,16 @@ jobs: key: ${{ matrix.toolchain }} - name: Build on ${{ matrix.toolchain }} + if: matrix.toolchain != wasm32-unknown-unknown # TODO: also run `cargo test` # TODO: ideally we would build `--workspace`, but not all crates compile for WASM run: cargo build --target=${{ matrix.toolchain }} - - name: Build on wasm32-wasi + - name: Build on ${{ matrix.toolchain }} + if: matrix.toolchain == wasm32-unknown-unknown # TODO: also run `cargo test` # TODO: ideally we would build `--workspace`, but not all crates compile for WASM - run: cargo build --target=wasm32-unknown-unknown --features wasm-bindgen + run: cargo build --target=${{ matrix.toolchain }} --features wasm-bindgen check-rustdoc-links: name: Check rustdoc intra-doc links diff --git a/Cargo.toml b/Cargo.toml index 74e16a339e3..30dd8bf4644 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,8 +67,11 @@ all-features = true atomic = "0.5.0" bytes = "1.1.0" futures = "0.3.17" +# Explicit dependency to be used in `wasm-bindgen` feature 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" lazy_static = "1.4.0" libp2p-core = { version = "0.30.0", path = "core", default-features = false } @@ -91,6 +94,7 @@ libp2p-uds = { version = "0.30.0", path = "transports/uds", optional = true } libp2p-wasm-ext = { version = "0.30.0", path = "transports/wasm-ext", default-features = false, optional = true } libp2p-yamux = { version = "0.34.0", path = "muxers/yamux", optional = true } multiaddr = "0.13.0" +# Explicit dependency to be used in `wasm-bindgen` feature parking_lot = "0.11.2" pin-project = "1.0.8" rand = "0.7.3" diff --git a/transports/wasm-ext/src/websockets.js b/transports/wasm-ext/src/websockets.js index 3e7de1f76cb..1ef2faf6ded 100644 --- a/transports/wasm-ext/src/websockets.js +++ b/transports/wasm-ext/src/websockets.js @@ -80,17 +80,17 @@ const dial = (addr) => { read: (function*() { while(ws.readyState == 1) { yield reader.next(); } })(), write: (data) => { if (ws.readyState == 1) { - // The passed in `data` is an `ArrayBufferView` [0]. If the - // underlying typed array is a `SharedArrayBuffer` (when - // using WASM threads, so multiple web workers sharing - // memory) the WebSocket's `send` method errors [1][2][3]. - // This limitation will probably be lifted in the future, - // but for now we have to make a copy here .. - // - // [0]: https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView - // [1]: https://chromium.googlesource.com/chromium/src/+/1438f63f369fed3766fa5031e7a252c986c69be6%5E%21/ - // [2]: https://bugreports.qt.io/browse/QTBUG-78078 - // [3]: https://chromium.googlesource.com/chromium/src/+/HEAD/third_party/blink/renderer/bindings/IDLExtendedAttributes.md#AllowShared_p + // The passed in `data` is an `ArrayBufferView` [0]. If the + // underlying typed array is a `SharedArrayBuffer` (when + // using WASM threads, so multiple web workers sharing + // memory) the WebSocket's `send` method errors [1][2][3]. + // This limitation will probably be lifted in the future, + // but for now we have to make a copy here .. + // + // [0]: https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView + // [1]: https://chromium.googlesource.com/chromium/src/+/1438f63f369fed3766fa5031e7a252c986c69be6%5E%21/ + // [2]: https://bugreports.qt.io/browse/QTBUG-78078 + // [3]: https://chromium.googlesource.com/chromium/src/+/HEAD/third_party/blink/renderer/bindings/IDLExtendedAttributes.md#AllowShared_p ws.send(data.slice(0)); return promise_when_send_finished(ws); } else { From 4e87d01df32da00adb917d5ac4cd1f5a21c7b75a Mon Sep 17 00:00:00 2001 From: wngr Date: Sun, 10 Oct 2021 20:57:12 +0200 Subject: [PATCH 11/16] fix ci --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 70821f2ad52..9f94998a42b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -75,13 +75,13 @@ jobs: key: ${{ matrix.toolchain }} - name: Build on ${{ matrix.toolchain }} - if: matrix.toolchain != wasm32-unknown-unknown + if: matrix.toolchain != 'wasm32-unknown-unknown' # TODO: also run `cargo test` # TODO: ideally we would build `--workspace`, but not all crates compile for WASM run: cargo build --target=${{ matrix.toolchain }} - name: Build on ${{ matrix.toolchain }} - if: matrix.toolchain == wasm32-unknown-unknown + if: matrix.toolchain == 'wasm32-unknown-unknown' # TODO: also run `cargo test` # TODO: ideally we would build `--workspace`, but not all crates compile for WASM run: cargo build --target=${{ matrix.toolchain }} --features wasm-bindgen From bbd2329e1068727fbc52b27bf034ae3dc15ac0c3 Mon Sep 17 00:00:00 2001 From: wngr Date: Sat, 16 Oct 2021 19:53:38 +0200 Subject: [PATCH 12/16] dont re-export Instant in core --- core/Cargo.toml | 1 - core/src/lib.rs | 1 - protocols/gossipsub/Cargo.toml | 1 + protocols/gossipsub/src/backoff.rs | 3 ++- protocols/gossipsub/src/behaviour.rs | 3 ++- protocols/gossipsub/src/gossip_promises.rs | 3 ++- protocols/gossipsub/src/handler.rs | 6 ++---- protocols/gossipsub/src/interval.rs | 2 +- protocols/gossipsub/src/peer_score.rs | 3 ++- protocols/gossipsub/src/time_cache.rs | 2 +- protocols/kad/Cargo.toml | 1 + protocols/kad/src/behaviour.rs | 3 ++- protocols/kad/src/handler.rs | 3 ++- protocols/kad/src/jobs.rs | 3 ++- protocols/kad/src/protocol.rs | 3 ++- protocols/kad/src/query.rs | 3 ++- protocols/kad/src/query/peers/closest.rs | 3 ++- protocols/kad/src/query/peers/closest/disjoint.rs | 3 ++- protocols/kad/src/record.rs | 3 ++- protocols/ping/Cargo.toml | 1 + protocols/ping/src/protocol.rs | 3 ++- protocols/relay/Cargo.toml | 1 + protocols/relay/src/handler.rs | 3 ++- protocols/rendezvous/Cargo.toml | 1 + protocols/rendezvous/src/substream_handler.rs | 3 ++- protocols/request-response/Cargo.toml | 1 + protocols/request-response/src/handler.rs | 6 ++---- swarm/Cargo.toml | 1 + swarm/src/protocols_handler.rs | 3 ++- swarm/src/protocols_handler/node_handler.rs | 3 ++- swarm/src/protocols_handler/one_shot.rs | 2 +- 31 files changed, 48 insertions(+), 30 deletions(-) diff --git a/core/Cargo.toml b/core/Cargo.toml index 66f3a6bf7bf..8e4d4e25f9f 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -17,7 +17,6 @@ either = "1.5" fnv = "1.0" futures = { version = "0.3.1", features = ["executor", "thread-pool"] } futures-timer = "3" -instant = "0.1.10" lazy_static = "1.2" libsecp256k1 = { version = "0.6.0", optional = true } log = "0.4" diff --git a/core/src/lib.rs b/core/src/lib.rs index 3fe7f74bc9d..1a7d841e342 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -66,7 +66,6 @@ pub mod upgrade; pub use connection::{Connected, ConnectedPoint, Endpoint}; pub use identity::PublicKey; -pub use instant::{Duration, Instant}; pub use multiaddr::Multiaddr; pub use multihash; pub use muxing::StreamMuxer; diff --git a/protocols/gossipsub/Cargo.toml b/protocols/gossipsub/Cargo.toml index 25c2374fd3e..7d5ee7b648a 100644 --- a/protocols/gossipsub/Cargo.toml +++ b/protocols/gossipsub/Cargo.toml @@ -28,6 +28,7 @@ hex_fmt = "0.3.0" regex = "1.4.0" futures-timer = "3.0.2" pin-project = "1.0.8" +instant = "0.1.11" [dev-dependencies] async-std = "1.6.3" diff --git a/protocols/gossipsub/src/backoff.rs b/protocols/gossipsub/src/backoff.rs index 9921ab6d3ab..2fe0eb7fd56 100644 --- a/protocols/gossipsub/src/backoff.rs +++ b/protocols/gossipsub/src/backoff.rs @@ -20,7 +20,8 @@ //! Data structure for efficiently storing known back-off's when pruning peers. use crate::topic::TopicHash; -use libp2p_core::{Instant, PeerId}; +use instant::Instant; +use libp2p_core::PeerId; use std::collections::{ hash_map::{Entry, HashMap}, HashSet, diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index 178a9c0ced6..d9682791f20 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -35,9 +35,10 @@ use log::{debug, error, trace, warn}; use prost::Message; use rand::{seq::SliceRandom, thread_rng}; +use instant::Instant; use libp2p_core::{ connection::ConnectionId, identity::Keypair, multiaddr::Protocol::Ip4, - multiaddr::Protocol::Ip6, ConnectedPoint, Instant, Multiaddr, PeerId, + multiaddr::Protocol::Ip6, ConnectedPoint, Multiaddr, PeerId, }; use libp2p_swarm::{ DialPeerCondition, IntoProtocolsHandler, NetworkBehaviour, NetworkBehaviourAction, diff --git a/protocols/gossipsub/src/gossip_promises.rs b/protocols/gossipsub/src/gossip_promises.rs index f0796b7ffba..2904b152ee7 100644 --- a/protocols/gossipsub/src/gossip_promises.rs +++ b/protocols/gossipsub/src/gossip_promises.rs @@ -21,7 +21,8 @@ use crate::error::ValidationError; use crate::peer_score::RejectReason; use crate::MessageId; -use libp2p_core::{Instant, PeerId}; +use instant::Instant; +use libp2p_core::PeerId; use log::debug; use rand::seq::SliceRandom; use rand::thread_rng; diff --git a/protocols/gossipsub/src/handler.rs b/protocols/gossipsub/src/handler.rs index 2090d8b0be3..592c5b409c4 100644 --- a/protocols/gossipsub/src/handler.rs +++ b/protocols/gossipsub/src/handler.rs @@ -25,10 +25,8 @@ use crate::types::{GossipsubRpc, PeerKind, RawGossipsubMessage}; use asynchronous_codec::Framed; use futures::prelude::*; use futures::StreamExt; -use libp2p_core::{ - upgrade::{InboundUpgrade, NegotiationError, OutboundUpgrade, UpgradeError}, - Instant, -}; +use instant::Instant; +use libp2p_core::upgrade::{InboundUpgrade, NegotiationError, OutboundUpgrade, UpgradeError}; use libp2p_swarm::protocols_handler::{ KeepAlive, ProtocolsHandler, ProtocolsHandlerEvent, ProtocolsHandlerUpgrErr, SubstreamProtocol, }; diff --git a/protocols/gossipsub/src/interval.rs b/protocols/gossipsub/src/interval.rs index 3fd515ad4d2..385d3e17a40 100644 --- a/protocols/gossipsub/src/interval.rs +++ b/protocols/gossipsub/src/interval.rs @@ -30,7 +30,7 @@ use std::{ use futures::prelude::*; use futures_timer::Delay; -use libp2p_core::Instant; +use instant::Instant; use pin_project::pin_project; /// A stream representing notifications at fixed interval diff --git a/protocols/gossipsub/src/peer_score.rs b/protocols/gossipsub/src/peer_score.rs index b9e1d1742c8..09ba48baf62 100644 --- a/protocols/gossipsub/src/peer_score.rs +++ b/protocols/gossipsub/src/peer_score.rs @@ -23,7 +23,8 @@ use crate::time_cache::TimeCache; use crate::{MessageId, TopicHash}; -use libp2p_core::{Instant, PeerId}; +use instant::Instant; +use libp2p_core::PeerId; use log::{debug, trace, warn}; use std::collections::{hash_map, HashMap, HashSet}; use std::net::IpAddr; diff --git a/protocols/gossipsub/src/time_cache.rs b/protocols/gossipsub/src/time_cache.rs index b718d19ac56..768f2fc7cc3 100644 --- a/protocols/gossipsub/src/time_cache.rs +++ b/protocols/gossipsub/src/time_cache.rs @@ -21,7 +21,7 @@ //! This implements a time-based LRU cache for checking gossipsub message duplicates. use fnv::FnvHashMap; -use libp2p_core::Instant; +use instant::Instant; use std::collections::hash_map::{ self, Entry::{Occupied, Vacant}, diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index 75fd497f80d..41a21216511 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -27,6 +27,7 @@ uint = "0.9" unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] } void = "1.0" futures-timer = "3.0.2" +instant = "0.1.11" [dev-dependencies] env_logger = "0.9.0" diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs index b96fc9dda1e..480fdf3f10a 100644 --- a/protocols/kad/src/behaviour.rs +++ b/protocols/kad/src/behaviour.rs @@ -38,9 +38,10 @@ use crate::record::{ }; use crate::K_VALUE; use fnv::{FnvHashMap, FnvHashSet}; +use instant::Instant; use libp2p_core::{ connection::{ConnectionId, ListenerId}, - ConnectedPoint, Instant, Multiaddr, PeerId, + ConnectedPoint, Multiaddr, PeerId, }; use libp2p_swarm::{ DialError, DialPeerCondition, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler, diff --git a/protocols/kad/src/handler.rs b/protocols/kad/src/handler.rs index 98f33d8cf1b..2b3e92ff0ee 100644 --- a/protocols/kad/src/handler.rs +++ b/protocols/kad/src/handler.rs @@ -24,10 +24,11 @@ use crate::protocol::{ }; use crate::record::{self, Record}; use futures::prelude::*; +use instant::Instant; use libp2p_core::{ either::EitherOutput, upgrade::{self, InboundUpgrade, OutboundUpgrade}, - ConnectedPoint, Instant, PeerId, + ConnectedPoint, PeerId, }; use libp2p_swarm::{ IntoProtocolsHandler, KeepAlive, NegotiatedSubstream, ProtocolsHandler, ProtocolsHandlerEvent, diff --git a/protocols/kad/src/jobs.rs b/protocols/kad/src/jobs.rs index a788f24f6be..7ce201a4150 100644 --- a/protocols/kad/src/jobs.rs +++ b/protocols/kad/src/jobs.rs @@ -64,7 +64,8 @@ use crate::record::{self, store::RecordStore, ProviderRecord, Record}; use futures::prelude::*; use futures_timer::Delay; -use libp2p_core::{Instant, PeerId}; +use instant::Instant; +use libp2p_core::PeerId; use std::collections::HashSet; use std::pin::Pin; use std::task::{Context, Poll}; diff --git a/protocols/kad/src/protocol.rs b/protocols/kad/src/protocol.rs index ad2869b4aaa..1058acb00e9 100644 --- a/protocols/kad/src/protocol.rs +++ b/protocols/kad/src/protocol.rs @@ -32,8 +32,9 @@ use asynchronous_codec::Framed; use bytes::BytesMut; use codec::UviBytes; use futures::prelude::*; +use instant::Instant; use libp2p_core::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; -use libp2p_core::{Instant, Multiaddr, PeerId}; +use libp2p_core::{Multiaddr, PeerId}; use prost::Message; use std::{borrow::Cow, convert::TryFrom, time::Duration}; use std::{io, iter}; diff --git a/protocols/kad/src/query.rs b/protocols/kad/src/query.rs index 5c60fb82eb0..708c758464f 100644 --- a/protocols/kad/src/query.rs +++ b/protocols/kad/src/query.rs @@ -30,7 +30,8 @@ use crate::kbucket::{Key, KeyBytes}; use crate::{ALPHA_VALUE, K_VALUE}; use either::Either; use fnv::FnvHashMap; -use libp2p_core::{Instant, PeerId}; +use instant::Instant; +use libp2p_core::PeerId; use std::{num::NonZeroUsize, time::Duration}; /// A `QueryPool` provides an aggregate state machine for driving `Query`s to completion. diff --git a/protocols/kad/src/query/peers/closest.rs b/protocols/kad/src/query/peers/closest.rs index 3300cab2947..2b3cb124274 100644 --- a/protocols/kad/src/query/peers/closest.rs +++ b/protocols/kad/src/query/peers/closest.rs @@ -22,7 +22,8 @@ use super::*; use crate::kbucket::{Distance, Key, KeyBytes}; use crate::{ALPHA_VALUE, K_VALUE}; -use libp2p_core::{Instant, PeerId}; +use instant::Instant; +use libp2p_core::PeerId; use std::collections::btree_map::{BTreeMap, Entry}; use std::{iter::FromIterator, num::NonZeroUsize, time::Duration}; diff --git a/protocols/kad/src/query/peers/closest/disjoint.rs b/protocols/kad/src/query/peers/closest/disjoint.rs index 9d60c627521..af91b8c1f0b 100644 --- a/protocols/kad/src/query/peers/closest/disjoint.rs +++ b/protocols/kad/src/query/peers/closest/disjoint.rs @@ -20,7 +20,8 @@ use super::*; use crate::kbucket::{Key, KeyBytes}; -use libp2p_core::{Instant, PeerId}; +use instant::Instant; +use libp2p_core::PeerId; use std::{ collections::HashMap, iter::{Cycle, Map, Peekable}, diff --git a/protocols/kad/src/record.rs b/protocols/kad/src/record.rs index 64733f9ae9e..e8e05670c79 100644 --- a/protocols/kad/src/record.rs +++ b/protocols/kad/src/record.rs @@ -23,7 +23,8 @@ pub mod store; use bytes::Bytes; -use libp2p_core::{multihash::Multihash, Instant, Multiaddr, PeerId}; +use instant::Instant; +use libp2p_core::{multihash::Multihash, Multiaddr, PeerId}; use std::borrow::Borrow; use std::hash::{Hash, Hasher}; diff --git a/protocols/ping/Cargo.toml b/protocols/ping/Cargo.toml index 4d50af59060..ded0e12e0b0 100644 --- a/protocols/ping/Cargo.toml +++ b/protocols/ping/Cargo.toml @@ -12,6 +12,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] futures = "0.3.1" futures-timer = "3.0.2" +instant = "0.1.11" libp2p-core = { version = "0.30.0-rc.1", path = "../../core", default-features = false } libp2p-swarm = { version = "0.31.0-rc.1", path = "../../swarm" } log = "0.4.1" diff --git a/protocols/ping/src/protocol.rs b/protocols/ping/src/protocol.rs index 5560c1943b2..703a9275d87 100644 --- a/protocols/ping/src/protocol.rs +++ b/protocols/ping/src/protocol.rs @@ -19,7 +19,8 @@ // DEALINGS IN THE SOFTWARE. use futures::prelude::*; -use libp2p_core::{InboundUpgrade, Instant, OutboundUpgrade, UpgradeInfo}; +use instant::Instant; +use libp2p_core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; use libp2p_swarm::NegotiatedSubstream; use rand::{distributions, prelude::*}; use std::{io, iter, time::Duration}; diff --git a/protocols/relay/Cargo.toml b/protocols/relay/Cargo.toml index a2aae09044f..95518a54045 100644 --- a/protocols/relay/Cargo.toml +++ b/protocols/relay/Cargo.toml @@ -14,6 +14,7 @@ asynchronous-codec = "0.6" bytes = "1" futures = "0.3.1" futures-timer = "3" +instant = "0.1.11" libp2p-core = { version = "0.30.0-rc.1", path = "../../core", default-features = false } libp2p-swarm = { version = "0.31.0-rc.1", path = "../../swarm" } log = "0.4" diff --git a/protocols/relay/src/handler.rs b/protocols/relay/src/handler.rs index 57b51b68476..792ffd50534 100644 --- a/protocols/relay/src/handler.rs +++ b/protocols/relay/src/handler.rs @@ -25,9 +25,10 @@ use futures::channel::oneshot::{self, Canceled}; use futures::future::BoxFuture; use futures::prelude::*; use futures::stream::FuturesUnordered; +use instant::Instant; use libp2p_core::connection::ConnectionId; use libp2p_core::either::{EitherError, EitherOutput}; -use libp2p_core::{upgrade, ConnectedPoint, Instant, Multiaddr, PeerId}; +use libp2p_core::{upgrade, ConnectedPoint, Multiaddr, PeerId}; use libp2p_swarm::{ IntoProtocolsHandler, KeepAlive, NegotiatedSubstream, ProtocolsHandler, ProtocolsHandlerEvent, ProtocolsHandlerUpgrErr, SubstreamProtocol, diff --git a/protocols/rendezvous/Cargo.toml b/protocols/rendezvous/Cargo.toml index 2e930ac0bf0..8804a4487af 100644 --- a/protocols/rendezvous/Cargo.toml +++ b/protocols/rendezvous/Cargo.toml @@ -23,6 +23,7 @@ bimap = "0.6.1" sha2 = "0.9" rand = "0.8" futures-timer = "3.0.2" +instant = "0.1.11" [dev-dependencies] async-trait = "0.1" diff --git a/protocols/rendezvous/src/substream_handler.rs b/protocols/rendezvous/src/substream_handler.rs index e301736d4a1..55b2a3638c9 100644 --- a/protocols/rendezvous/src/substream_handler.rs +++ b/protocols/rendezvous/src/substream_handler.rs @@ -27,7 +27,8 @@ use futures::future::{self, BoxFuture, Fuse, FusedFuture}; use futures::FutureExt; -use libp2p_core::{InboundUpgrade, Instant, OutboundUpgrade, UpgradeInfo}; +use instant::Instant; +use libp2p_core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; use libp2p_swarm::protocols_handler::{InboundUpgradeSend, OutboundUpgradeSend}; use libp2p_swarm::{ KeepAlive, NegotiatedSubstream, ProtocolsHandler, ProtocolsHandlerEvent, diff --git a/protocols/request-response/Cargo.toml b/protocols/request-response/Cargo.toml index 2493cc2de8a..703ad01355e 100644 --- a/protocols/request-response/Cargo.toml +++ b/protocols/request-response/Cargo.toml @@ -13,6 +13,7 @@ categories = ["network-programming", "asynchronous"] async-trait = "0.1" bytes = "1" futures = "0.3.1" +instant = "0.1.11" libp2p-core = { version = "0.30.0-rc.1", path = "../../core", default-features = false } libp2p-swarm = { version = "0.31.0-rc.1", path = "../../swarm" } log = "0.4.11" diff --git a/protocols/request-response/src/handler.rs b/protocols/request-response/src/handler.rs index a482ec5c285..e0b482ccd3e 100644 --- a/protocols/request-response/src/handler.rs +++ b/protocols/request-response/src/handler.rs @@ -26,10 +26,8 @@ use crate::{RequestId, EMPTY_QUEUE_SHRINK_THRESHOLD}; pub use protocol::{ProtocolSupport, RequestProtocol, ResponseProtocol}; use futures::{channel::oneshot, future::BoxFuture, prelude::*, stream::FuturesUnordered}; -use libp2p_core::{ - upgrade::{NegotiationError, UpgradeError}, - Instant, -}; +use instant::Instant; +use libp2p_core::upgrade::{NegotiationError, UpgradeError}; use libp2p_swarm::{ protocols_handler::{ KeepAlive, ProtocolsHandler, ProtocolsHandlerEvent, ProtocolsHandlerUpgrErr, diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index 298de4df897..94b91c090ee 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -18,6 +18,7 @@ rand = "0.7" smallvec = "1.6.1" void = "1" futures-timer = "3.0.2" +instant = "0.1.11" [dev-dependencies] libp2p = { path = "../", default-features = false, features = ["yamux", "plaintext"] } diff --git a/swarm/src/protocols_handler.rs b/swarm/src/protocols_handler.rs index 861d507cbd1..3cdb1bb0095 100644 --- a/swarm/src/protocols_handler.rs +++ b/swarm/src/protocols_handler.rs @@ -48,7 +48,8 @@ mod select; pub use crate::upgrade::{InboundUpgradeSend, OutboundUpgradeSend, SendWrapper, UpgradeInfoSend}; -use libp2p_core::{upgrade::UpgradeError, ConnectedPoint, Instant, Multiaddr, PeerId}; +use instant::Instant; +use libp2p_core::{upgrade::UpgradeError, ConnectedPoint, Multiaddr, PeerId}; use std::{cmp::Ordering, error, fmt, task::Context, task::Poll, time::Duration}; pub use dummy::DummyProtocolsHandler; diff --git a/swarm/src/protocols_handler/node_handler.rs b/swarm/src/protocols_handler/node_handler.rs index 19962b53227..fa339fd9416 100644 --- a/swarm/src/protocols_handler/node_handler.rs +++ b/swarm/src/protocols_handler/node_handler.rs @@ -27,6 +27,7 @@ use crate::upgrade::SendWrapper; use futures::prelude::*; use futures::stream::FuturesUnordered; use futures_timer::Delay; +use instant::Instant; use libp2p_core::{ connection::{ ConnectionHandler, ConnectionHandlerEvent, IntoConnectionHandler, Substream, @@ -34,7 +35,7 @@ use libp2p_core::{ }, muxing::StreamMuxerBox, upgrade::{self, InboundUpgradeApply, OutboundUpgradeApply, UpgradeError}, - Connected, Instant, Multiaddr, + Connected, Multiaddr, }; use std::{error, fmt, pin::Pin, task::Context, task::Poll, time::Duration}; diff --git a/swarm/src/protocols_handler/one_shot.rs b/swarm/src/protocols_handler/one_shot.rs index bef097bf672..0851ff82e43 100644 --- a/swarm/src/protocols_handler/one_shot.rs +++ b/swarm/src/protocols_handler/one_shot.rs @@ -22,7 +22,7 @@ use crate::protocols_handler::{ KeepAlive, ProtocolsHandler, ProtocolsHandlerEvent, ProtocolsHandlerUpgrErr, SubstreamProtocol, }; use crate::upgrade::{InboundUpgradeSend, OutboundUpgradeSend}; -use libp2p_core::Instant; +use instant::Instant; use smallvec::SmallVec; use std::{error, fmt::Debug, task::Context, task::Poll, time::Duration}; From 76bdd421a2fdf0089f54bec3a3465d77f5fd8b88 Mon Sep 17 00:00:00 2001 From: wngr Date: Sat, 16 Oct 2021 20:00:28 +0200 Subject: [PATCH 13/16] replace SystemTime --- Cargo.toml | 3 +++ core/Cargo.toml | 1 + core/src/peer_record.rs | 2 +- protocols/rendezvous/src/server.rs | 2 +- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b0b7efe47ad..75eb295b67c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -149,3 +149,6 @@ members = [ [[example]] name = "chat-tokio" required-features = ["tcp-tokio", "mdns"] + +[patch.crates-io] +instant = { git = "https://github.com/wngr/instant", branch = "systemtime" } diff --git a/core/Cargo.toml b/core/Cargo.toml index 8e4d4e25f9f..e6f0bd08c24 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -17,6 +17,7 @@ either = "1.5" 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.6.0", optional = true } log = "0.4" diff --git a/core/src/peer_record.rs b/core/src/peer_record.rs index 6b7759213c9..18b62d2335d 100644 --- a/core/src/peer_record.rs +++ b/core/src/peer_record.rs @@ -2,9 +2,9 @@ use crate::identity::error::SigningError; use crate::identity::Keypair; use crate::signed_envelope::SignedEnvelope; use crate::{peer_record_proto, signed_envelope, Multiaddr, PeerId}; +use instant::SystemTime; use std::convert::TryInto; use std::fmt; -use std::time::SystemTime; const PAYLOAD_TYPE: &str = "/libp2p/routing-state-record"; const DOMAIN_SEP: &str = "libp2p-routing-state"; diff --git a/protocols/rendezvous/src/server.rs b/protocols/rendezvous/src/server.rs index 33a9af4f0fd..ecfd8ce50c5 100644 --- a/protocols/rendezvous/src/server.rs +++ b/protocols/rendezvous/src/server.rs @@ -490,8 +490,8 @@ pub struct CookieNamespaceMismatch; #[cfg(test)] mod tests { + use instant::SystemTime; use std::option::Option::None; - use std::time::SystemTime; use libp2p_core::{identity, PeerRecord}; From bfc7d7f779feb159f90a38a83e8bc0963377a945 Mon Sep 17 00:00:00 2001 From: wngr Date: Mon, 18 Oct 2021 13:48:20 +0200 Subject: [PATCH 14/16] new instant release --- Cargo.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 75eb295b67c..b0b7efe47ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -149,6 +149,3 @@ members = [ [[example]] name = "chat-tokio" required-features = ["tcp-tokio", "mdns"] - -[patch.crates-io] -instant = { git = "https://github.com/wngr/instant", branch = "systemtime" } From d792ce2d05effb0db75376311ed747df250fbc2a Mon Sep 17 00:00:00 2001 From: wngr Date: Tue, 19 Oct 2021 21:04:30 +0200 Subject: [PATCH 15/16] pr comments --- .github/workflows/ci.yml | 13 ++++--------- Cargo.toml | 15 +++++---------- protocols/gossipsub/src/interval.rs | 5 ++--- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 84c2ca886d2..ae2e4c79564 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,9 +39,11 @@ jobs: matrix: toolchain: [ wasm32-unknown-emscripten, - wasm32-unknown-unknown, wasm32-wasi ] + include: + - toolchain: wasm32-unknown-unknown + args: "--features wasm-bindgen" container: image: rust env: @@ -75,16 +77,9 @@ jobs: key: ${{ matrix.toolchain }} - name: Build on ${{ matrix.toolchain }} - if: matrix.toolchain != 'wasm32-unknown-unknown' # TODO: also run `cargo test` # TODO: ideally we would build `--workspace`, but not all crates compile for WASM - run: cargo build --target=${{ matrix.toolchain }} - - - name: Build on ${{ matrix.toolchain }} - if: matrix.toolchain == 'wasm32-unknown-unknown' - # TODO: also run `cargo test` - # TODO: ideally we would build `--workspace`, but not all crates compile for WASM - run: cargo build --target=${{ matrix.toolchain }} --features wasm-bindgen + run: cargo build --target=${{ matrix.toolchain }} ${{ matrix.args }} check-rustdoc-links: name: Check rustdoc intra-doc links diff --git a/Cargo.toml b/Cargo.toml index b0b7efe47ad..37ffa96d6a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,12 +67,9 @@ all-features = true atomic = "0.5.0" bytes = "1" futures = "0.3.1" -# Explicit dependency to be used in `wasm-bindgen` feature -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" +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-core = { version = "0.30.0-rc.1", path = "core", default-features = false } libp2p-floodsub = { version = "0.31.0-rc.1", path = "protocols/floodsub", optional = true } @@ -94,11 +91,9 @@ libp2p-uds = { version = "0.30.0-rc.1", path = "transports/uds", optional = true libp2p-wasm-ext = { version = "0.30.0-rc.1", path = "transports/wasm-ext", default-features = false, optional = true } libp2p-yamux = { version = "0.34.0-rc.1", path = "muxers/yamux", optional = true } multiaddr = { version = "0.13.0-rc.1" } -# Explicit dependency to be used in `wasm-bindgen` feature -parking_lot = "0.11.2" +parking_lot = "0.11.2" # Explicit dependency to be used in `wasm-bindgen` feature pin-project = "1.0.0" -# Explicit dependency to be used in `wasm-bindgen` feature -rand = "0.7.3" +rand = "0.7.3" # Explicit dependency to be used in `wasm-bindgen` feature smallvec = "1.6.1" [target.'cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))'.dependencies] diff --git a/protocols/gossipsub/src/interval.rs b/protocols/gossipsub/src/interval.rs index 385d3e17a40..3080f541a55 100644 --- a/protocols/gossipsub/src/interval.rs +++ b/protocols/gossipsub/src/interval.rs @@ -99,9 +99,8 @@ impl Stream for Interval { /// 427_000 years. Large enough for any interval we would use or calculate in /// tokio. fn duration_to_nanos(dur: Duration) -> Option { - dur.as_secs() - .checked_mul(1_000_000_000) - .and_then(|v| v.checked_add(dur.subsec_nanos() as u64)) + let v = dur.as_secs().checked_mul(1_000_000_000)?; + v.checked_add(dur.subsec_nanos() as u64) } fn next_interval(prev: Instant, now: Instant, interval: Duration) -> Duration { From 0ee5dba134ad7677881fa379ea17f953433c7f63 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Sat, 30 Oct 2021 12:17:03 +0200 Subject: [PATCH 16/16] *: Bump versions and add changelog entries --- CHANGELOG.md | 5 +++++ Cargo.toml | 2 +- core/CHANGELOG.md | 6 ++++++ core/Cargo.toml | 4 ++-- protocols/gossipsub/CHANGELOG.md | 6 ++++++ protocols/gossipsub/Cargo.toml | 2 +- protocols/identify/CHANGELOG.md | 6 ++++++ protocols/identify/Cargo.toml | 2 +- protocols/kad/CHANGELOG.md | 6 ++++++ protocols/kad/Cargo.toml | 2 +- protocols/ping/CHANGELOG.md | 6 ++++++ protocols/ping/Cargo.toml | 2 +- protocols/relay/CHANGELOG.md | 6 ++++++ protocols/relay/Cargo.toml | 2 +- protocols/rendezvous/CHANGELOG.md | 6 ++++++ protocols/rendezvous/Cargo.toml | 2 +- protocols/request-response/CHANGELOG.md | 6 ++++++ protocols/request-response/Cargo.toml | 2 +- swarm/CHANGELOG.md | 6 ++++++ swarm/Cargo.toml | 2 +- 20 files changed, 70 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db0ca108d3b..bcc9908265f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,11 @@ # `libp2p` facade crate +## Version 0.41.0 [unreleased] + +- Update individual crates. + - `libp2p-kad` +- Forward `wasm-bindgen` feature to `futures-timer`, `instant`, `parking_lot`, `getrandom/js` and `rand/wasm-bindgen`. ## Version 0.40.0-rc.2 [2021-10-15] diff --git a/Cargo.toml b/Cargo.toml index 37ffa96d6a4..fb48268c39d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p" edition = "2018" description = "Peer-to-peer networking library" -version = "0.40.0-rc.2" +version = "0.41.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index cbe0d188e97..113e1254e23 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -1,3 +1,9 @@ +# 0.30.1 [unreleased] + +- Use `instant` instead of `wasm-timer` (see [PR 2245]). + +[PR 2245]: https://github.com/libp2p/rust-libp2p/pull/2245 + # 0.30.0-rc.1 [2021-10-15] - Add `ConnectionLimit::with_max_established` (see [PR 2137]). diff --git a/core/Cargo.toml b/core/Cargo.toml index e5579f5e35f..8573f45cf7c 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-core" edition = "2018" description = "Core traits and structs of libp2p" -version = "0.30.0-rc.1" +version = "0.30.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -48,7 +48,7 @@ libp2p-noise = { path = "../transports/noise" } libp2p-tcp = { path = "../transports/tcp" } multihash = { version = "0.14", default-features = false, features = ["arb"] } quickcheck = "0.9.0" -rand07 = { package = "rand", version = "0.7" } +rand07 = { package = "rand", version = "0.7" } [build-dependencies] prost-build = "0.9" diff --git a/protocols/gossipsub/CHANGELOG.md b/protocols/gossipsub/CHANGELOG.md index a755c375f01..1178821a15a 100644 --- a/protocols/gossipsub/CHANGELOG.md +++ b/protocols/gossipsub/CHANGELOG.md @@ -1,3 +1,9 @@ +# 0.33.1 [unreleased] + +- Use `instant` and `futures-timer` instead of `wasm-timer` (see [PR 2245]). + +[PR 2245]: https://github.com/libp2p/rust-libp2p/pull/2245 + # 0.33.0-rc.1 [2021-10-15] - Add an event to register peers that do not support the gossipsub protocol diff --git a/protocols/gossipsub/Cargo.toml b/protocols/gossipsub/Cargo.toml index 7d5ee7b648a..db83f9b13b5 100644 --- a/protocols/gossipsub/Cargo.toml +++ b/protocols/gossipsub/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-gossipsub" edition = "2018" description = "Gossipsub protocol for libp2p" -version = "0.33.0-rc.1" +version = "0.33.1" authors = ["Age Manning "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/protocols/identify/CHANGELOG.md b/protocols/identify/CHANGELOG.md index 9611597c067..8305f167bc0 100644 --- a/protocols/identify/CHANGELOG.md +++ b/protocols/identify/CHANGELOG.md @@ -1,3 +1,9 @@ +# 0.31.1 [unreleased] + +- Use `futures-timer` instead of `wasm-timer` (see [PR 2245]). + +[PR 2245]: https://github.com/libp2p/rust-libp2p/pull/2245 + # 0.31.0-rc.1 [2021-10-15] - Make default features of `libp2p-core` optional. diff --git a/protocols/identify/Cargo.toml b/protocols/identify/Cargo.toml index a64e0024bb6..3a6834abcea 100644 --- a/protocols/identify/Cargo.toml +++ b/protocols/identify/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-identify" edition = "2018" description = "Nodes identifcation protocol for libp2p" -version = "0.31.0-rc.1" +version = "0.31.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/protocols/kad/CHANGELOG.md b/protocols/kad/CHANGELOG.md index b4ebf2f68b9..81c5e72094d 100644 --- a/protocols/kad/CHANGELOG.md +++ b/protocols/kad/CHANGELOG.md @@ -1,3 +1,9 @@ +# 0.32.1 [unreleased] + +- Use `instant` and `futures-timer` instead of `wasm-timer` (see [PR 2245]). + +[PR 2245]: https://github.com/libp2p/rust-libp2p/pull/2245 + # 0.32.0-rc.2 [2021-10-15] - Export `KademliaBucketInserts` (see [PR 2294]). diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index 41a21216511..b560906369c 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-kad" edition = "2018" description = "Kademlia protocol for libp2p" -version = "0.32.0-rc.2" +version = "0.32.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/protocols/ping/CHANGELOG.md b/protocols/ping/CHANGELOG.md index 5aa997fc9f2..62b20f14846 100644 --- a/protocols/ping/CHANGELOG.md +++ b/protocols/ping/CHANGELOG.md @@ -1,3 +1,9 @@ +# 0.31.1 [unreleased] + +- Use `instant` and `futures-timer` instead of `wasm-timer` (see [PR 2245]). + +[PR 2245]: https://github.com/libp2p/rust-libp2p/pull/2245 + # 0.31.0-rc.1 [2021-10-15] - Make default features of `libp2p-core` optional. diff --git a/protocols/ping/Cargo.toml b/protocols/ping/Cargo.toml index ded0e12e0b0..fbc84574549 100644 --- a/protocols/ping/Cargo.toml +++ b/protocols/ping/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-ping" edition = "2018" description = "Ping protocol for libp2p" -version = "0.31.0-rc.1" +version = "0.31.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/protocols/relay/CHANGELOG.md b/protocols/relay/CHANGELOG.md index fc50ca28e64..cbd587aceff 100644 --- a/protocols/relay/CHANGELOG.md +++ b/protocols/relay/CHANGELOG.md @@ -1,3 +1,9 @@ +# 0.4.1 [unreleased] + +- Use `instant` instead of `wasm-timer` (see [PR 2245]). + +[PR 2245]: https://github.com/libp2p/rust-libp2p/pull/2245 + # 0.4.0-rc.1 [2021-10-15] - Make default features of `libp2p-core` optional. diff --git a/protocols/relay/Cargo.toml b/protocols/relay/Cargo.toml index 95518a54045..6046741008a 100644 --- a/protocols/relay/Cargo.toml +++ b/protocols/relay/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-relay" edition = "2018" description = "Communications relaying for libp2p" -version = "0.4.0-rc.1" +version = "0.4.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/protocols/rendezvous/CHANGELOG.md b/protocols/rendezvous/CHANGELOG.md index 8e127776e13..6646c66145b 100644 --- a/protocols/rendezvous/CHANGELOG.md +++ b/protocols/rendezvous/CHANGELOG.md @@ -1,3 +1,9 @@ +# 0.1.1 [unreleased] + +- Use `instant` and `futures-timer` instead of `wasm-timer` (see [PR 2245]). + +[PR 2245]: https://github.com/libp2p/rust-libp2p/pull/2245 + # 0.1.0-rc.1 [2021-10-15] - Initial release. diff --git a/protocols/rendezvous/Cargo.toml b/protocols/rendezvous/Cargo.toml index 8804a4487af..c004cf98160 100644 --- a/protocols/rendezvous/Cargo.toml +++ b/protocols/rendezvous/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-rendezvous" edition = "2018" description = "Rendezvous protocol for libp2p" -version = "0.1.0-rc.1" +version = "0.1.1" authors = ["The COMIT guys "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/protocols/request-response/CHANGELOG.md b/protocols/request-response/CHANGELOG.md index a4620fc9a58..8147ec9e91c 100644 --- a/protocols/request-response/CHANGELOG.md +++ b/protocols/request-response/CHANGELOG.md @@ -1,3 +1,9 @@ +# 0.13.1 [unreleased] + +- Use `instant` instead of `wasm-timer` (see [PR 2245]). + +[PR 2245]: https://github.com/libp2p/rust-libp2p/pull/2245 + # 0.13.0-rc.1 [2021-10-15] - Make default features of `libp2p-core` optional. diff --git a/protocols/request-response/Cargo.toml b/protocols/request-response/Cargo.toml index 703ad01355e..bdf5020575d 100644 --- a/protocols/request-response/Cargo.toml +++ b/protocols/request-response/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-request-response" edition = "2018" description = "Generic Request/Response Protocols" -version = "0.13.0-rc.1" +version = "0.13.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index bf67f53d91c..706ad39f92e 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -1,3 +1,9 @@ +# 0.31.1 [unreleased] + +- Use `instant` and `futures-timer` instead of `wasm-timer` (see [PR 2245]). + +[PR 2245]: https://github.com/libp2p/rust-libp2p/pull/2245 + # 0.31.0-rc.1 [2021-10-15] - Make default features of `libp2p-core` optional. diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index 94b91c090ee..baef617e2d1 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-swarm" edition = "2018" description = "The libp2p swarm" -version = "0.31.0-rc.1" +version = "0.31.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p"