Skip to content

Commit ce4ca3c

Browse files
authored
Switch to wasm-timer (#1071)
1 parent 9a525d5 commit ce4ca3c

20 files changed

+36
-33
lines changed

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,14 @@ smallvec = "0.6"
3737
tokio-codec = "0.1"
3838
tokio-executor = "0.1"
3939
tokio-io = "0.1"
40+
wasm-timer = "0.1"
4041

4142
[target.'cfg(not(any(target_os = "emscripten", target_os = "unknown")))'.dependencies]
4243
libp2p-dns = { version = "0.7.0", path = "./transports/dns" }
4344
libp2p-mdns = { version = "0.7.0", path = "./misc/mdns" }
4445
libp2p-noise = { version = "0.5.0", path = "./protocols/noise" }
4546
libp2p-tcp = { version = "0.7.0", path = "./transports/tcp" }
4647

47-
[target.'cfg(any(target_os = "emscripten", target_os = "unknown"))'.dependencies]
48-
stdweb = { version = "0.4", default-features = false }
49-
5048
[dev-dependencies]
5149
env_logger = "0.6.0"
5250
rand = "0.6"

core/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ sha2 = "0.8.0"
3232
smallvec = "0.6"
3333
tokio-executor = "0.1.4"
3434
tokio-io = "0.1"
35-
tokio-timer = "0.2"
35+
wasm-timer = "0.1"
3636
unsigned-varint = "0.2"
3737
void = "1"
3838
zeroize = "0.5"
@@ -51,7 +51,7 @@ rand = "0.6"
5151
quickcheck = "0.8"
5252
tokio = "0.1"
5353
tokio-codec = "0.1"
54-
tokio-timer = "0.2"
54+
wasm-timer = "0.1"
5555
assert_matches = "1.3"
5656
tokio-mock-task = "0.1"
5757

core/src/protocols_handler/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ use crate::upgrade::{
4444
UpgradeError,
4545
};
4646
use futures::prelude::*;
47-
use std::{cmp::Ordering, error, fmt, time::Duration, time::Instant};
47+
use std::{cmp::Ordering, error, fmt, time::Duration};
4848
use tokio_io::{AsyncRead, AsyncWrite};
49+
use wasm_timer::Instant;
4950

5051
pub use self::dummy::DummyProtocolsHandler;
5152
pub use self::map_in::MapInEvent;

core/src/protocols_handler/node_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::{
3232
};
3333
use futures::prelude::*;
3434
use std::{error, fmt, time::Duration};
35-
use tokio_timer::{Delay, Timeout};
35+
use wasm_timer::{Delay, Timeout};
3636

3737
/// Prototype for a `NodeHandlerWrapper`.
3838
pub struct NodeHandlerWrapperBuilder<TIntoProtoHandler> {

core/src/protocols_handler/one_shot.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ use crate::protocols_handler::{
2525
use crate::upgrade::{InboundUpgrade, OutboundUpgrade};
2626
use futures::prelude::*;
2727
use smallvec::SmallVec;
28-
use std::{error, marker::PhantomData, time::Duration, time::Instant};
28+
use std::{error, marker::PhantomData, time::Duration};
2929
use tokio_io::{AsyncRead, AsyncWrite};
30+
use wasm_timer::Instant;
3031

3132
/// Implementation of `ProtocolsHandler` that opens a new substream for each individual message.
3233
///

core/src/transport/timeout.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ use crate::{Multiaddr, Transport, transport::{TransportError, ListenerEvent}};
2828
use futures::{try_ready, Async, Future, Poll, Stream};
2929
use log::debug;
3030
use std::{error, fmt, time::Duration};
31-
use tokio_timer::Timeout;
32-
use tokio_timer::timeout::Error as TimeoutError;
31+
use wasm_timer::Timeout;
32+
use wasm_timer::timeout::Error as TimeoutError;
3333

3434
/// A `TransportTimeout` is a `Transport` that wraps another `Transport` and adds
3535
/// timeouts to all inbound and outbound connection attempts.

core/tests/raw_swarm_simult.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ use libp2p_core::protocols_handler::{
2929
ProtocolsHandlerEvent,
3030
ProtocolsHandlerUpgrErr
3131
};
32-
use std::{io, time::Duration, time::Instant};
33-
use tokio_timer::Delay;
32+
use std::{io, time::Duration};
33+
use wasm_timer::{Delay, Instant};
3434

3535
// TODO: replace with DummyProtocolsHandler after https://github.com/servo/rust-smallvec/issues/139 ?
3636
struct TestHandler<TSubstream>(std::marker::PhantomData<TSubstream>);

misc/mdns/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ rand = "0.6"
2121
smallvec = "0.6"
2222
tokio-io = "0.1"
2323
tokio-reactor = "0.1"
24-
tokio-timer = "0.2"
24+
wasm-timer = "0.1"
2525
tokio-udp = "0.1"
2626
void = "1.0"
2727

misc/mdns/src/behaviour.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ use libp2p_core::protocols_handler::{DummyProtocolsHandler, ProtocolsHandler};
2525
use libp2p_core::swarm::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction, PollParameters};
2626
use libp2p_core::{address_translation, Multiaddr, PeerId, multiaddr::Protocol};
2727
use smallvec::SmallVec;
28-
use std::{cmp, fmt, io, iter, marker::PhantomData, time::Duration, time::Instant};
28+
use std::{cmp, fmt, io, iter, marker::PhantomData, time::Duration};
2929
use tokio_io::{AsyncRead, AsyncWrite};
30-
use tokio_timer::Delay;
30+
use wasm_timer::{Delay, Instant};
3131

3232
/// A `NetworkBehaviour` for mDNS. Automatically discovers peers on the local network and adds
3333
/// them to the topology.

misc/mdns/src/service.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ use dns_parser::{Packet, RData};
2323
use futures::{prelude::*, task};
2424
use libp2p_core::{Multiaddr, PeerId};
2525
use multiaddr::Protocol;
26-
use std::{fmt, io, net::Ipv4Addr, net::SocketAddr, str, time::Duration, time::Instant};
26+
use std::{fmt, io, net::Ipv4Addr, net::SocketAddr, str, time::Duration};
2727
use tokio_reactor::Handle;
28-
use tokio_timer::Interval;
28+
use wasm_timer::{Instant, Interval};
2929
use tokio_udp::UdpSocket;
3030

3131
pub use dns::MdnsResponseError;
@@ -169,7 +169,7 @@ impl MdnsService {
169169
}
170170
}
171171
Ok(Async::NotReady) => (),
172-
_ => unreachable!("A tokio_timer::Interval never errors"), // TODO: is that true?
172+
_ => unreachable!("A wasm_timer::Interval never errors"), // TODO: is that true?
173173
};
174174

175175
// Flush the send buffer of the main socket.

protocols/identify/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ protobuf = "2.3"
2121
smallvec = "0.6"
2222
tokio-codec = "0.1"
2323
tokio-io = "0.1.0"
24-
tokio-timer = "0.2.6"
24+
wasm-timer = "0.1"
2525
unsigned-varint = { version = "0.2.1", features = ["codec"] }
2626
void = "1.0"
2727

protocols/identify/src/periodic_id_handler.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ use libp2p_core::{
3030
},
3131
upgrade::{DeniedUpgrade, OutboundUpgrade}
3232
};
33-
use std::{io, marker::PhantomData, time::{Duration, Instant}};
33+
use std::{io, marker::PhantomData, time::Duration};
3434
use tokio_io::{AsyncRead, AsyncWrite};
35-
use tokio_timer::{self, Delay};
35+
use wasm_timer::{Delay, Instant};
3636
use void::{Void, unreachable};
3737

3838
/// Delay between the moment we connect and the first time we identify.
@@ -90,7 +90,7 @@ where
9090
{
9191
type InEvent = Void;
9292
type OutEvent = PeriodicIdHandlerEvent;
93-
type Error = tokio_timer::Error;
93+
type Error = wasm_timer::Error;
9494
type Substream = TSubstream;
9595
type InboundProtocol = DeniedUpgrade;
9696
type OutboundProtocol = IdentifyProtocolConfig;

protocols/kad/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ rand = "0.6.0"
2727
smallvec = "0.6"
2828
tokio-codec = "0.1"
2929
tokio-io = "0.1"
30-
tokio-timer = "0.2.6"
30+
wasm-timer = "0.1"
3131
unsigned-varint = { version = "0.2.1", features = ["codec"] }
3232
void = "1.0"
3333

protocols/kad/src/behaviour.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ use libp2p_core::swarm::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourActio
3030
use libp2p_core::{protocols_handler::ProtocolsHandler, Multiaddr, PeerId};
3131
use multihash::Multihash;
3232
use smallvec::SmallVec;
33-
use std::{error, marker::PhantomData, num::NonZeroUsize, time::Duration, time::Instant};
33+
use std::{error, marker::PhantomData, num::NonZeroUsize, time::Duration};
3434
use tokio_io::{AsyncRead, AsyncWrite};
35-
use tokio_timer::Interval;
35+
use wasm_timer::{Instant, Interval};
3636

3737
mod test;
3838

protocols/kad/src/handler.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ use libp2p_core::protocols_handler::{
3232
};
3333
use libp2p_core::{upgrade, either::EitherOutput, InboundUpgrade, OutboundUpgrade, PeerId, upgrade::Negotiated};
3434
use multihash::Multihash;
35-
use std::{error, fmt, io, time::Duration, time::Instant};
35+
use std::{error, fmt, io, time::Duration};
3636
use tokio_io::{AsyncRead, AsyncWrite};
37+
use wasm_timer::Instant;
3738

3839
/// Protocol handler that handles Kademlia communications with the remote.
3940
///

protocols/kad/src/query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
use crate::kbucket::KBucketsPeerId;
2727
use futures::prelude::*;
2828
use smallvec::SmallVec;
29-
use std::{cmp::PartialEq, time::Duration, time::Instant};
30-
use tokio_timer::Delay;
29+
use std::{cmp::PartialEq, time::Duration};
30+
use wasm_timer::{Delay, Instant};
3131

3232
/// State of a query iterative process.
3333
///

protocols/ping/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ parking_lot = "0.7"
2020
rand = "0.6"
2121
tokio-codec = "0.1"
2222
tokio-io = "0.1"
23-
tokio-timer = "0.2.6"
23+
wasm-timer = "0.1"
2424
void = "1.0"
2525

2626
[dev-dependencies]

protocols/ping/src/handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ use libp2p_core::protocols_handler::{
2727
ProtocolsHandler,
2828
ProtocolsHandlerUpgrErr,
2929
};
30-
use std::{error::Error, io, fmt, num::NonZeroU32, time::{Duration, Instant}};
30+
use std::{error::Error, io, fmt, num::NonZeroU32, time::Duration};
3131
use std::collections::VecDeque;
3232
use tokio_io::{AsyncRead, AsyncWrite};
33-
use tokio_timer::Delay;
33+
use wasm_timer::{Delay, Instant};
3434
use void::Void;
3535

3636
/// The configuration for outbound pings.

protocols/ping/src/protocol.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ use futures::{prelude::*, future, try_ready};
2222
use libp2p_core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo, upgrade::Negotiated};
2323
use log::debug;
2424
use rand::{distributions, prelude::*};
25-
use std::{io, iter, time::Duration, time::Instant};
25+
use std::{io, iter, time::Duration};
2626
use tokio_io::{io as nio, AsyncRead, AsyncWrite};
27+
use wasm_timer::Instant;
2728

2829
/// Represents a prototype for an upgrade to handle the ping protocol.
2930
///

src/bandwidth.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ use futures::{prelude::*, try_ready};
2323
use lazy_static::lazy_static;
2424
use parking_lot::Mutex;
2525
use smallvec::{smallvec, SmallVec};
26-
use std::{cmp, io, io::Read, io::Write, sync::Arc, time::Duration, time::Instant};
26+
use std::{cmp, io, io::Read, io::Write, sync::Arc, time::Duration};
27+
use wasm_timer::Instant;
2728

2829
/// Wraps around a `Transport` and logs the bandwidth that goes through all the opened connections.
2930
#[derive(Clone)]

0 commit comments

Comments
 (0)