diff --git a/Cargo.toml b/Cargo.toml index 3f1efc066bc..c1c756a6f1f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,6 +37,7 @@ smallvec = "0.6" tokio-codec = "0.1" tokio-executor = "0.1" tokio-io = "0.1" +wasm-timer = "0.1" [target.'cfg(not(any(target_os = "emscripten", target_os = "unknown")))'.dependencies] libp2p-dns = { version = "0.7.0", path = "./transports/dns" } @@ -44,9 +45,6 @@ libp2p-mdns = { version = "0.7.0", path = "./misc/mdns" } libp2p-noise = { version = "0.5.0", path = "./protocols/noise" } libp2p-tcp = { version = "0.7.0", path = "./transports/tcp" } -[target.'cfg(any(target_os = "emscripten", target_os = "unknown"))'.dependencies] -stdweb = { version = "0.4", default-features = false } - [dev-dependencies] env_logger = "0.6.0" rand = "0.6" diff --git a/core/Cargo.toml b/core/Cargo.toml index 7647617112c..494a2dd8f8b 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -32,7 +32,7 @@ sha2 = "0.8.0" smallvec = "0.6" tokio-executor = "0.1.4" tokio-io = "0.1" -tokio-timer = "0.2" +wasm-timer = "0.1" unsigned-varint = "0.2" void = "1" zeroize = "0.5" @@ -51,7 +51,7 @@ rand = "0.6" quickcheck = "0.8" tokio = "0.1" tokio-codec = "0.1" -tokio-timer = "0.2" +wasm-timer = "0.1" assert_matches = "1.3" tokio-mock-task = "0.1" diff --git a/core/src/protocols_handler/mod.rs b/core/src/protocols_handler/mod.rs index 6b5bf0309c9..a3137df77c7 100644 --- a/core/src/protocols_handler/mod.rs +++ b/core/src/protocols_handler/mod.rs @@ -44,8 +44,9 @@ use crate::upgrade::{ UpgradeError, }; use futures::prelude::*; -use std::{cmp::Ordering, error, fmt, time::Duration, time::Instant}; +use std::{cmp::Ordering, error, fmt, time::Duration}; use tokio_io::{AsyncRead, AsyncWrite}; +use wasm_timer::Instant; pub use self::dummy::DummyProtocolsHandler; pub use self::map_in::MapInEvent; diff --git a/core/src/protocols_handler/node_handler.rs b/core/src/protocols_handler/node_handler.rs index 5a79ed69f0b..0688e0072c0 100644 --- a/core/src/protocols_handler/node_handler.rs +++ b/core/src/protocols_handler/node_handler.rs @@ -32,7 +32,7 @@ use crate::{ }; use futures::prelude::*; use std::{error, fmt, time::Duration}; -use tokio_timer::{Delay, Timeout}; +use wasm_timer::{Delay, Timeout}; /// Prototype for a `NodeHandlerWrapper`. pub struct NodeHandlerWrapperBuilder { diff --git a/core/src/protocols_handler/one_shot.rs b/core/src/protocols_handler/one_shot.rs index a0424b4d257..ffc3aa7e698 100644 --- a/core/src/protocols_handler/one_shot.rs +++ b/core/src/protocols_handler/one_shot.rs @@ -25,8 +25,9 @@ use crate::protocols_handler::{ use crate::upgrade::{InboundUpgrade, OutboundUpgrade}; use futures::prelude::*; use smallvec::SmallVec; -use std::{error, marker::PhantomData, time::Duration, time::Instant}; +use std::{error, marker::PhantomData, time::Duration}; use tokio_io::{AsyncRead, AsyncWrite}; +use wasm_timer::Instant; /// Implementation of `ProtocolsHandler` that opens a new substream for each individual message. /// diff --git a/core/src/transport/timeout.rs b/core/src/transport/timeout.rs index 987620e5d5f..8a2bde99d5f 100644 --- a/core/src/transport/timeout.rs +++ b/core/src/transport/timeout.rs @@ -28,8 +28,8 @@ use crate::{Multiaddr, Transport, transport::{TransportError, ListenerEvent}}; use futures::{try_ready, Async, Future, Poll, Stream}; use log::debug; use std::{error, fmt, time::Duration}; -use tokio_timer::Timeout; -use tokio_timer::timeout::Error as TimeoutError; +use wasm_timer::Timeout; +use wasm_timer::timeout::Error as TimeoutError; /// A `TransportTimeout` is a `Transport` that wraps another `Transport` and adds /// timeouts to all inbound and outbound connection attempts. diff --git a/core/tests/raw_swarm_simult.rs b/core/tests/raw_swarm_simult.rs index 1b9210daf7e..811c9c2eb6f 100644 --- a/core/tests/raw_swarm_simult.rs +++ b/core/tests/raw_swarm_simult.rs @@ -29,8 +29,8 @@ use libp2p_core::protocols_handler::{ ProtocolsHandlerEvent, ProtocolsHandlerUpgrErr }; -use std::{io, time::Duration, time::Instant}; -use tokio_timer::Delay; +use std::{io, time::Duration}; +use wasm_timer::{Delay, Instant}; // TODO: replace with DummyProtocolsHandler after https://github.com/servo/rust-smallvec/issues/139 ? struct TestHandler(std::marker::PhantomData); diff --git a/misc/mdns/Cargo.toml b/misc/mdns/Cargo.toml index 2f77cc336c4..6c6c6e950d1 100644 --- a/misc/mdns/Cargo.toml +++ b/misc/mdns/Cargo.toml @@ -21,7 +21,7 @@ rand = "0.6" smallvec = "0.6" tokio-io = "0.1" tokio-reactor = "0.1" -tokio-timer = "0.2" +wasm-timer = "0.1" tokio-udp = "0.1" void = "1.0" diff --git a/misc/mdns/src/behaviour.rs b/misc/mdns/src/behaviour.rs index 8bf5dc07836..5aafacc708b 100644 --- a/misc/mdns/src/behaviour.rs +++ b/misc/mdns/src/behaviour.rs @@ -25,9 +25,9 @@ use libp2p_core::protocols_handler::{DummyProtocolsHandler, ProtocolsHandler}; use libp2p_core::swarm::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction, PollParameters}; use libp2p_core::{address_translation, Multiaddr, PeerId, multiaddr::Protocol}; use smallvec::SmallVec; -use std::{cmp, fmt, io, iter, marker::PhantomData, time::Duration, time::Instant}; +use std::{cmp, fmt, io, iter, marker::PhantomData, time::Duration}; use tokio_io::{AsyncRead, AsyncWrite}; -use tokio_timer::Delay; +use wasm_timer::{Delay, Instant}; /// A `NetworkBehaviour` for mDNS. Automatically discovers peers on the local network and adds /// them to the topology. diff --git a/misc/mdns/src/service.rs b/misc/mdns/src/service.rs index 4a6b99d6aa7..1721a656fe6 100644 --- a/misc/mdns/src/service.rs +++ b/misc/mdns/src/service.rs @@ -23,9 +23,9 @@ use dns_parser::{Packet, RData}; use futures::{prelude::*, task}; use libp2p_core::{Multiaddr, PeerId}; use multiaddr::Protocol; -use std::{fmt, io, net::Ipv4Addr, net::SocketAddr, str, time::Duration, time::Instant}; +use std::{fmt, io, net::Ipv4Addr, net::SocketAddr, str, time::Duration}; use tokio_reactor::Handle; -use tokio_timer::Interval; +use wasm_timer::{Instant, Interval}; use tokio_udp::UdpSocket; pub use dns::MdnsResponseError; @@ -169,7 +169,7 @@ impl MdnsService { } } Ok(Async::NotReady) => (), - _ => unreachable!("A tokio_timer::Interval never errors"), // TODO: is that true? + _ => unreachable!("A wasm_timer::Interval never errors"), // TODO: is that true? }; // Flush the send buffer of the main socket. diff --git a/protocols/identify/Cargo.toml b/protocols/identify/Cargo.toml index 92f6d61708b..3432244fc70 100644 --- a/protocols/identify/Cargo.toml +++ b/protocols/identify/Cargo.toml @@ -21,7 +21,7 @@ protobuf = "2.3" smallvec = "0.6" tokio-codec = "0.1" tokio-io = "0.1.0" -tokio-timer = "0.2.6" +wasm-timer = "0.1" unsigned-varint = { version = "0.2.1", features = ["codec"] } void = "1.0" diff --git a/protocols/identify/src/periodic_id_handler.rs b/protocols/identify/src/periodic_id_handler.rs index aaef4c9a8f0..1df09e53008 100644 --- a/protocols/identify/src/periodic_id_handler.rs +++ b/protocols/identify/src/periodic_id_handler.rs @@ -30,9 +30,9 @@ use libp2p_core::{ }, upgrade::{DeniedUpgrade, OutboundUpgrade} }; -use std::{io, marker::PhantomData, time::{Duration, Instant}}; +use std::{io, marker::PhantomData, time::Duration}; use tokio_io::{AsyncRead, AsyncWrite}; -use tokio_timer::{self, Delay}; +use wasm_timer::{Delay, Instant}; use void::{Void, unreachable}; /// Delay between the moment we connect and the first time we identify. @@ -90,7 +90,7 @@ where { type InEvent = Void; type OutEvent = PeriodicIdHandlerEvent; - type Error = tokio_timer::Error; + type Error = wasm_timer::Error; type Substream = TSubstream; type InboundProtocol = DeniedUpgrade; type OutboundProtocol = IdentifyProtocolConfig; diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index be0c496d992..b81d5a745b5 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -27,7 +27,7 @@ rand = "0.6.0" smallvec = "0.6" tokio-codec = "0.1" tokio-io = "0.1" -tokio-timer = "0.2.6" +wasm-timer = "0.1" unsigned-varint = { version = "0.2.1", features = ["codec"] } void = "1.0" diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs index cda99fda822..179412b1953 100644 --- a/protocols/kad/src/behaviour.rs +++ b/protocols/kad/src/behaviour.rs @@ -30,9 +30,9 @@ use libp2p_core::swarm::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourActio use libp2p_core::{protocols_handler::ProtocolsHandler, Multiaddr, PeerId}; use multihash::Multihash; use smallvec::SmallVec; -use std::{error, marker::PhantomData, num::NonZeroUsize, time::Duration, time::Instant}; +use std::{error, marker::PhantomData, num::NonZeroUsize, time::Duration}; use tokio_io::{AsyncRead, AsyncWrite}; -use tokio_timer::Interval; +use wasm_timer::{Instant, Interval}; mod test; diff --git a/protocols/kad/src/handler.rs b/protocols/kad/src/handler.rs index d8ebfbe2dc8..e8568773140 100644 --- a/protocols/kad/src/handler.rs +++ b/protocols/kad/src/handler.rs @@ -32,8 +32,9 @@ use libp2p_core::protocols_handler::{ }; use libp2p_core::{upgrade, either::EitherOutput, InboundUpgrade, OutboundUpgrade, PeerId, upgrade::Negotiated}; use multihash::Multihash; -use std::{error, fmt, io, time::Duration, time::Instant}; +use std::{error, fmt, io, time::Duration}; use tokio_io::{AsyncRead, AsyncWrite}; +use wasm_timer::Instant; /// Protocol handler that handles Kademlia communications with the remote. /// diff --git a/protocols/kad/src/query.rs b/protocols/kad/src/query.rs index ae7a3efb8e2..def306593bf 100644 --- a/protocols/kad/src/query.rs +++ b/protocols/kad/src/query.rs @@ -26,8 +26,8 @@ use crate::kbucket::KBucketsPeerId; use futures::prelude::*; use smallvec::SmallVec; -use std::{cmp::PartialEq, time::Duration, time::Instant}; -use tokio_timer::Delay; +use std::{cmp::PartialEq, time::Duration}; +use wasm_timer::{Delay, Instant}; /// State of a query iterative process. /// diff --git a/protocols/ping/Cargo.toml b/protocols/ping/Cargo.toml index 6288358878e..33b70bd185e 100644 --- a/protocols/ping/Cargo.toml +++ b/protocols/ping/Cargo.toml @@ -20,7 +20,7 @@ parking_lot = "0.7" rand = "0.6" tokio-codec = "0.1" tokio-io = "0.1" -tokio-timer = "0.2.6" +wasm-timer = "0.1" void = "1.0" [dev-dependencies] diff --git a/protocols/ping/src/handler.rs b/protocols/ping/src/handler.rs index 1b816bb6849..8b767e3d475 100644 --- a/protocols/ping/src/handler.rs +++ b/protocols/ping/src/handler.rs @@ -27,10 +27,10 @@ use libp2p_core::protocols_handler::{ ProtocolsHandler, ProtocolsHandlerUpgrErr, }; -use std::{error::Error, io, fmt, num::NonZeroU32, time::{Duration, Instant}}; +use std::{error::Error, io, fmt, num::NonZeroU32, time::Duration}; use std::collections::VecDeque; use tokio_io::{AsyncRead, AsyncWrite}; -use tokio_timer::Delay; +use wasm_timer::{Delay, Instant}; use void::Void; /// The configuration for outbound pings. diff --git a/protocols/ping/src/protocol.rs b/protocols/ping/src/protocol.rs index 4ac0a3f0b53..926aad03e6d 100644 --- a/protocols/ping/src/protocol.rs +++ b/protocols/ping/src/protocol.rs @@ -22,8 +22,9 @@ use futures::{prelude::*, future, try_ready}; use libp2p_core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo, upgrade::Negotiated}; use log::debug; use rand::{distributions, prelude::*}; -use std::{io, iter, time::Duration, time::Instant}; +use std::{io, iter, time::Duration}; use tokio_io::{io as nio, AsyncRead, AsyncWrite}; +use wasm_timer::Instant; /// Represents a prototype for an upgrade to handle the ping protocol. /// diff --git a/src/bandwidth.rs b/src/bandwidth.rs index c6352e9c39e..76b889cfd9b 100644 --- a/src/bandwidth.rs +++ b/src/bandwidth.rs @@ -23,7 +23,8 @@ use futures::{prelude::*, try_ready}; use lazy_static::lazy_static; use parking_lot::Mutex; use smallvec::{smallvec, SmallVec}; -use std::{cmp, io, io::Read, io::Write, sync::Arc, time::Duration, time::Instant}; +use std::{cmp, io, io::Read, io::Write, sync::Arc, time::Duration}; +use wasm_timer::Instant; /// Wraps around a `Transport` and logs the bandwidth that goes through all the opened connections. #[derive(Clone)]