mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-15 11:01:21 +00:00
feat(gossipsub): allow compiling for WASM
This modification removes deprecated dependency `wasm_timer` and enables wasm compatibility on the gossibsup protocol by simply substituting the `wasm_timer::Instant` with `instant::Instant`(which supports `fn checked_add`) and `wasm_timer::Interval` with `futures_ticker::Ticker`. Pull-Request: #3973.
This commit is contained in:
74
Cargo.lock
generated
74
Cargo.lock
generated
@ -1739,6 +1739,17 @@ version = "0.3.28"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65"
|
checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-ticker"
|
||||||
|
version = "0.0.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9763058047f713632a52e916cc7f6a4b3fc6e9fc1ff8c5b1dc49e5a89041682e"
|
||||||
|
dependencies = [
|
||||||
|
"futures",
|
||||||
|
"futures-timer",
|
||||||
|
"instant",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-timer"
|
name = "futures-timer"
|
||||||
version = "3.0.2"
|
version = "3.0.2"
|
||||||
@ -2486,7 +2497,7 @@ dependencies = [
|
|||||||
"multihash",
|
"multihash",
|
||||||
"multistream-select",
|
"multistream-select",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"parking_lot 0.12.1",
|
"parking_lot",
|
||||||
"pin-project",
|
"pin-project",
|
||||||
"quick-protobuf",
|
"quick-protobuf",
|
||||||
"quickcheck-ext",
|
"quickcheck-ext",
|
||||||
@ -2556,7 +2567,7 @@ dependencies = [
|
|||||||
"libp2p-core",
|
"libp2p-core",
|
||||||
"libp2p-identity",
|
"libp2p-identity",
|
||||||
"log",
|
"log",
|
||||||
"parking_lot 0.12.1",
|
"parking_lot",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"tokio",
|
"tokio",
|
||||||
"trust-dns-resolver",
|
"trust-dns-resolver",
|
||||||
@ -2594,6 +2605,8 @@ dependencies = [
|
|||||||
"env_logger 0.10.0",
|
"env_logger 0.10.0",
|
||||||
"fnv",
|
"fnv",
|
||||||
"futures",
|
"futures",
|
||||||
|
"futures-ticker",
|
||||||
|
"getrandom 0.2.9",
|
||||||
"hex",
|
"hex",
|
||||||
"hex_fmt",
|
"hex_fmt",
|
||||||
"instant",
|
"instant",
|
||||||
@ -2615,7 +2628,6 @@ dependencies = [
|
|||||||
"smallvec",
|
"smallvec",
|
||||||
"unsigned-varint",
|
"unsigned-varint",
|
||||||
"void",
|
"void",
|
||||||
"wasm-timer",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -2762,7 +2774,7 @@ dependencies = [
|
|||||||
"libp2p-tcp",
|
"libp2p-tcp",
|
||||||
"log",
|
"log",
|
||||||
"nohash-hasher",
|
"nohash-hasher",
|
||||||
"parking_lot 0.12.1",
|
"parking_lot",
|
||||||
"quickcheck-ext",
|
"quickcheck-ext",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
@ -2906,7 +2918,7 @@ dependencies = [
|
|||||||
"libp2p-tls",
|
"libp2p-tls",
|
||||||
"libp2p-yamux",
|
"libp2p-yamux",
|
||||||
"log",
|
"log",
|
||||||
"parking_lot 0.12.1",
|
"parking_lot",
|
||||||
"quickcheck",
|
"quickcheck",
|
||||||
"quinn-proto",
|
"quinn-proto",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
@ -3174,7 +3186,7 @@ dependencies = [
|
|||||||
"libp2p-identity",
|
"libp2p-identity",
|
||||||
"libp2p-tcp",
|
"libp2p-tcp",
|
||||||
"log",
|
"log",
|
||||||
"parking_lot 0.12.1",
|
"parking_lot",
|
||||||
"quicksink",
|
"quicksink",
|
||||||
"rcgen 0.9.3",
|
"rcgen 0.9.3",
|
||||||
"rw-stream-sink",
|
"rw-stream-sink",
|
||||||
@ -3706,17 +3718,6 @@ version = "2.0.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72"
|
checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "parking_lot"
|
|
||||||
version = "0.11.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99"
|
|
||||||
dependencies = [
|
|
||||||
"instant",
|
|
||||||
"lock_api",
|
|
||||||
"parking_lot_core 0.8.6",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parking_lot"
|
name = "parking_lot"
|
||||||
version = "0.12.1"
|
version = "0.12.1"
|
||||||
@ -3724,21 +3725,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
|
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lock_api",
|
"lock_api",
|
||||||
"parking_lot_core 0.9.6",
|
"parking_lot_core",
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "parking_lot_core"
|
|
||||||
version = "0.8.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"instant",
|
|
||||||
"libc",
|
|
||||||
"redox_syscall 0.2.16",
|
|
||||||
"smallvec",
|
|
||||||
"winapi",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -4021,7 +4008,7 @@ checksum = "78c2f43e8969d51935d2a7284878ae053ba30034cd563f673cde37ba5205685e"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"dtoa",
|
"dtoa",
|
||||||
"itoa",
|
"itoa",
|
||||||
"parking_lot 0.12.1",
|
"parking_lot",
|
||||||
"prometheus-client-derive-encode",
|
"prometheus-client-derive-encode",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -5103,7 +5090,7 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
"mio",
|
"mio",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
"parking_lot 0.12.1",
|
"parking_lot",
|
||||||
"pin-project-lite 0.2.9",
|
"pin-project-lite 0.2.9",
|
||||||
"signal-hook-registry",
|
"signal-hook-registry",
|
||||||
"socket2 0.4.9",
|
"socket2 0.4.9",
|
||||||
@ -5240,7 +5227,7 @@ dependencies = [
|
|||||||
"ipconfig",
|
"ipconfig",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"lru-cache",
|
"lru-cache",
|
||||||
"parking_lot 0.12.1",
|
"parking_lot",
|
||||||
"resolv-conf",
|
"resolv-conf",
|
||||||
"rustls 0.20.8",
|
"rustls 0.20.8",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
@ -5525,21 +5512,6 @@ version = "0.2.86"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ed9d5b4305409d1fc9482fee2d7f9bcbf24b3972bf59817ef757e23982242a93"
|
checksum = "ed9d5b4305409d1fc9482fee2d7f9bcbf24b3972bf59817ef757e23982242a93"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wasm-timer"
|
|
||||||
version = "0.2.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "be0ecb0db480561e9a7642b5d3e4187c128914e58aa84330b9493e3eb68c5e7f"
|
|
||||||
dependencies = [
|
|
||||||
"futures",
|
|
||||||
"js-sys",
|
|
||||||
"parking_lot 0.11.2",
|
|
||||||
"pin-utils",
|
|
||||||
"wasm-bindgen",
|
|
||||||
"wasm-bindgen-futures",
|
|
||||||
"web-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "web-sys"
|
name = "web-sys"
|
||||||
version = "0.3.60"
|
version = "0.3.60"
|
||||||
@ -6114,7 +6086,7 @@ dependencies = [
|
|||||||
"futures",
|
"futures",
|
||||||
"log",
|
"log",
|
||||||
"nohash-hasher",
|
"nohash-hasher",
|
||||||
"parking_lot 0.12.1",
|
"parking_lot",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"static_assertions",
|
"static_assertions",
|
||||||
]
|
]
|
||||||
|
@ -15,7 +15,7 @@ either = "1.5"
|
|||||||
fnv = "1.0"
|
fnv = "1.0"
|
||||||
futures = { version = "0.3.28", features = ["executor", "thread-pool"] }
|
futures = { version = "0.3.28", features = ["executor", "thread-pool"] }
|
||||||
futures-timer = "3"
|
futures-timer = "3"
|
||||||
instant = "0.1.11"
|
instant = "0.1.12"
|
||||||
libp2p-identity = { workspace = true, features = ["peerid", "ed25519"] }
|
libp2p-identity = { workspace = true, features = ["peerid", "ed25519"] }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
multiaddr = { version = "0.17.1" }
|
multiaddr = { version = "0.17.1" }
|
||||||
|
@ -80,7 +80,7 @@ tcp = ["dep:libp2p-tcp"]
|
|||||||
tls = ["dep:libp2p-tls"]
|
tls = ["dep:libp2p-tls"]
|
||||||
tokio = ["libp2p-swarm/tokio", "libp2p-mdns?/tokio", "libp2p-tcp?/tokio", "libp2p-dns?/tokio", "libp2p-quic?/tokio", "libp2p-webrtc?/tokio"]
|
tokio = ["libp2p-swarm/tokio", "libp2p-mdns?/tokio", "libp2p-tcp?/tokio", "libp2p-dns?/tokio", "libp2p-quic?/tokio", "libp2p-webrtc?/tokio"]
|
||||||
uds = ["dep:libp2p-uds"]
|
uds = ["dep:libp2p-uds"]
|
||||||
wasm-bindgen = ["futures-timer/wasm-bindgen", "instant/wasm-bindgen", "getrandom/js", "libp2p-swarm/wasm-bindgen"]
|
wasm-bindgen = ["futures-timer/wasm-bindgen", "instant/wasm-bindgen", "getrandom/js", "libp2p-swarm/wasm-bindgen", "libp2p-gossipsub?/wasm-bindgen"]
|
||||||
wasm-ext = ["dep:libp2p-wasm-ext"]
|
wasm-ext = ["dep:libp2p-wasm-ext"]
|
||||||
wasm-ext-websocket = ["wasm-ext", "libp2p-wasm-ext?/websocket"]
|
wasm-ext-websocket = ["wasm-ext", "libp2p-wasm-ext?/websocket"]
|
||||||
webrtc = ["dep:libp2p-webrtc", "libp2p-webrtc?/pem"]
|
webrtc = ["dep:libp2p-webrtc", "libp2p-webrtc?/pem"]
|
||||||
@ -92,7 +92,7 @@ bytes = "1"
|
|||||||
futures = "0.3.26"
|
futures = "0.3.26"
|
||||||
futures-timer = "3.0.2" # 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
|
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
|
instant = "0.1.12" # Explicit dependency to be used in `wasm-bindgen` feature
|
||||||
|
|
||||||
libp2p-allow-block-list = { workspace = true }
|
libp2p-allow-block-list = { workspace = true }
|
||||||
libp2p-autonat = { workspace = true, optional = true }
|
libp2p-autonat = { workspace = true, optional = true }
|
||||||
@ -100,6 +100,7 @@ libp2p-connection-limits = { workspace = true }
|
|||||||
libp2p-core = { workspace = true }
|
libp2p-core = { workspace = true }
|
||||||
libp2p-dcutr = { workspace = true, optional = true }
|
libp2p-dcutr = { workspace = true, optional = true }
|
||||||
libp2p-floodsub = { workspace = true, optional = true }
|
libp2p-floodsub = { workspace = true, optional = true }
|
||||||
|
libp2p-gossipsub = { workspace = true, optional = true }
|
||||||
libp2p-identify = { workspace = true, optional = true }
|
libp2p-identify = { workspace = true, optional = true }
|
||||||
libp2p-identity = { workspace = true }
|
libp2p-identity = { workspace = true }
|
||||||
libp2p-kad = { workspace = true, optional = true }
|
libp2p-kad = { workspace = true, optional = true }
|
||||||
@ -130,9 +131,6 @@ libp2p-uds = { workspace = true, optional = true }
|
|||||||
libp2p-webrtc = { workspace = true, optional = true }
|
libp2p-webrtc = { workspace = true, optional = true }
|
||||||
libp2p-websocket = { workspace = true, optional = true }
|
libp2p-websocket = { workspace = true, optional = true }
|
||||||
|
|
||||||
[target.'cfg(not(target_os = "unknown"))'.dependencies]
|
|
||||||
libp2p-gossipsub = { workspace = true, optional = true }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
async-std = { version = "1.6.2", features = ["attributes"] }
|
async-std = { version = "1.6.2", features = ["attributes"] }
|
||||||
async-trait = "0.1"
|
async-trait = "0.1"
|
||||||
|
@ -19,7 +19,7 @@ relay = ["libp2p-relay"]
|
|||||||
dcutr = ["libp2p-dcutr"]
|
dcutr = ["libp2p-dcutr"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
instant = "0.1.11"
|
instant = "0.1.12"
|
||||||
libp2p-core = { workspace = true }
|
libp2p-core = { workspace = true }
|
||||||
libp2p-dcutr = { workspace = true, optional = true }
|
libp2p-dcutr = { workspace = true, optional = true }
|
||||||
libp2p-identify = { workspace = true, optional = true }
|
libp2p-identify = { workspace = true, optional = true }
|
||||||
|
@ -15,7 +15,7 @@ asynchronous-codec = "0.6"
|
|||||||
either = "1.6.0"
|
either = "1.6.0"
|
||||||
futures = "0.3.28"
|
futures = "0.3.28"
|
||||||
futures-timer = "3.0"
|
futures-timer = "3.0"
|
||||||
instant = "0.1.11"
|
instant = "0.1.12"
|
||||||
libp2p-core = { workspace = true }
|
libp2p-core = { workspace = true }
|
||||||
libp2p-swarm = { workspace = true }
|
libp2p-swarm = { workspace = true }
|
||||||
libp2p-identity = { workspace = true }
|
libp2p-identity = { workspace = true }
|
||||||
|
@ -10,30 +10,35 @@ repository = "https://github.com/libp2p/rust-libp2p"
|
|||||||
keywords = ["peer-to-peer", "libp2p", "networking"]
|
keywords = ["peer-to-peer", "libp2p", "networking"]
|
||||||
categories = ["network-programming", "asynchronous"]
|
categories = ["network-programming", "asynchronous"]
|
||||||
|
|
||||||
|
[features]
|
||||||
|
wasm-bindgen = ["getrandom/js", "instant/wasm-bindgen"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
either = "1.5"
|
asynchronous-codec = "0.6"
|
||||||
libp2p-swarm = { workspace = true }
|
base64 = "0.21.0"
|
||||||
libp2p-core = { workspace = true }
|
|
||||||
libp2p-identity = { workspace = true }
|
|
||||||
bytes = "1.4"
|
|
||||||
byteorder = "1.3.4"
|
byteorder = "1.3.4"
|
||||||
|
bytes = "1.4"
|
||||||
|
either = "1.5"
|
||||||
fnv = "1.0.7"
|
fnv = "1.0.7"
|
||||||
futures = "0.3.28"
|
futures = "0.3.28"
|
||||||
rand = "0.8"
|
futures-ticker = "0.0.3"
|
||||||
asynchronous-codec = "0.6"
|
getrandom = "0.2.9"
|
||||||
unsigned-varint = { version = "0.7.0", features = ["asynchronous_codec"] }
|
hex_fmt = "0.3.0"
|
||||||
|
instant = "0.1.12"
|
||||||
|
libp2p-core = { workspace = true }
|
||||||
|
libp2p-identity = { workspace = true }
|
||||||
|
libp2p-swarm = { workspace = true }
|
||||||
log = "0.4.11"
|
log = "0.4.11"
|
||||||
sha2 = "0.10.0"
|
|
||||||
base64 = "0.21.0"
|
|
||||||
smallvec = "1.6.1"
|
|
||||||
quick-protobuf = "0.8"
|
quick-protobuf = "0.8"
|
||||||
quick-protobuf-codec = { workspace = true }
|
quick-protobuf-codec = { workspace = true }
|
||||||
hex_fmt = "0.3.0"
|
rand = "0.8"
|
||||||
regex = "1.8.1"
|
regex = "1.8.1"
|
||||||
serde = { version = "1", optional = true, features = ["derive"] }
|
serde = { version = "1", optional = true, features = ["derive"] }
|
||||||
wasm-timer = "0.2.5"
|
sha2 = "0.10.0"
|
||||||
instant = "0.1.11"
|
smallvec = "1.6.1"
|
||||||
|
unsigned-varint = { version = "0.7.0", features = ["asynchronous_codec"] }
|
||||||
void = "1.0.2"
|
void = "1.0.2"
|
||||||
|
|
||||||
# Metrics dependencies
|
# Metrics dependencies
|
||||||
prometheus-client = "0.21.0"
|
prometheus-client = "0.21.0"
|
||||||
|
|
||||||
|
@ -20,13 +20,13 @@
|
|||||||
|
|
||||||
//! Data structure for efficiently storing known back-off's when pruning peers.
|
//! Data structure for efficiently storing known back-off's when pruning peers.
|
||||||
use crate::topic::TopicHash;
|
use crate::topic::TopicHash;
|
||||||
|
use instant::Instant;
|
||||||
use libp2p_identity::PeerId;
|
use libp2p_identity::PeerId;
|
||||||
use std::collections::{
|
use std::collections::{
|
||||||
hash_map::{Entry, HashMap},
|
hash_map::{Entry, HashMap},
|
||||||
HashSet,
|
HashSet,
|
||||||
};
|
};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use wasm_timer::Instant;
|
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
struct HeartbeatIndex(usize);
|
struct HeartbeatIndex(usize);
|
||||||
|
@ -30,10 +30,12 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
|
use futures_ticker::Ticker;
|
||||||
use log::{debug, error, trace, warn};
|
use log::{debug, error, trace, warn};
|
||||||
use prometheus_client::registry::Registry;
|
use prometheus_client::registry::Registry;
|
||||||
use rand::{seq::SliceRandom, thread_rng};
|
use rand::{seq::SliceRandom, thread_rng};
|
||||||
|
|
||||||
|
use instant::Instant;
|
||||||
use libp2p_core::{multiaddr::Protocol::Ip4, multiaddr::Protocol::Ip6, Endpoint, Multiaddr};
|
use libp2p_core::{multiaddr::Protocol::Ip4, multiaddr::Protocol::Ip6, Endpoint, Multiaddr};
|
||||||
use libp2p_identity::Keypair;
|
use libp2p_identity::Keypair;
|
||||||
use libp2p_identity::PeerId;
|
use libp2p_identity::PeerId;
|
||||||
@ -43,7 +45,6 @@ use libp2p_swarm::{
|
|||||||
ConnectionDenied, ConnectionId, NetworkBehaviour, NotifyHandler, PollParameters, THandler,
|
ConnectionDenied, ConnectionId, NetworkBehaviour, NotifyHandler, PollParameters, THandler,
|
||||||
THandlerInEvent, THandlerOutEvent, ToSwarm,
|
THandlerInEvent, THandlerOutEvent, ToSwarm,
|
||||||
};
|
};
|
||||||
use wasm_timer::Instant;
|
|
||||||
|
|
||||||
use crate::backoff::BackoffStorage;
|
use crate::backoff::BackoffStorage;
|
||||||
use crate::config::{Config, ValidationMode};
|
use crate::config::{Config, ValidationMode};
|
||||||
@ -67,7 +68,6 @@ use crate::{PublishError, SubscriptionError, ValidationError};
|
|||||||
use instant::SystemTime;
|
use instant::SystemTime;
|
||||||
use quick_protobuf::{MessageWrite, Writer};
|
use quick_protobuf::{MessageWrite, Writer};
|
||||||
use std::{cmp::Ordering::Equal, fmt::Debug};
|
use std::{cmp::Ordering::Equal, fmt::Debug};
|
||||||
use wasm_timer::Interval;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
@ -289,7 +289,7 @@ pub struct Behaviour<D = IdentityTransform, F = AllowAllSubscriptionFilter> {
|
|||||||
mcache: MessageCache,
|
mcache: MessageCache,
|
||||||
|
|
||||||
/// Heartbeat interval stream.
|
/// Heartbeat interval stream.
|
||||||
heartbeat: Interval,
|
heartbeat: Ticker,
|
||||||
|
|
||||||
/// Number of heartbeats since the beginning of time; this allows us to amortize some resource
|
/// Number of heartbeats since the beginning of time; this allows us to amortize some resource
|
||||||
/// clean up -- eg backoff clean up.
|
/// clean up -- eg backoff clean up.
|
||||||
@ -307,7 +307,7 @@ pub struct Behaviour<D = IdentityTransform, F = AllowAllSubscriptionFilter> {
|
|||||||
|
|
||||||
/// Stores optional peer score data together with thresholds, decay interval and gossip
|
/// Stores optional peer score data together with thresholds, decay interval and gossip
|
||||||
/// promises.
|
/// promises.
|
||||||
peer_score: Option<(PeerScore, PeerScoreThresholds, Interval, GossipPromises)>,
|
peer_score: Option<(PeerScore, PeerScoreThresholds, Ticker, GossipPromises)>,
|
||||||
|
|
||||||
/// Counts the number of `IHAVE` received from each peer since the last heartbeat.
|
/// Counts the number of `IHAVE` received from each peer since the last heartbeat.
|
||||||
count_received_ihave: HashMap<PeerId, usize>,
|
count_received_ihave: HashMap<PeerId, usize>,
|
||||||
@ -460,9 +460,9 @@ where
|
|||||||
config.backoff_slack(),
|
config.backoff_slack(),
|
||||||
),
|
),
|
||||||
mcache: MessageCache::new(config.history_gossip(), config.history_length()),
|
mcache: MessageCache::new(config.history_gossip(), config.history_length()),
|
||||||
heartbeat: Interval::new_at(
|
heartbeat: Ticker::new_with_next(
|
||||||
Instant::now() + config.heartbeat_initial_delay(),
|
|
||||||
config.heartbeat_interval(),
|
config.heartbeat_interval(),
|
||||||
|
config.heartbeat_initial_delay(),
|
||||||
),
|
),
|
||||||
heartbeat_ticks: 0,
|
heartbeat_ticks: 0,
|
||||||
px_peers: HashSet::new(),
|
px_peers: HashSet::new(),
|
||||||
@ -908,7 +908,7 @@ where
|
|||||||
return Err("Peer score set twice".into());
|
return Err("Peer score set twice".into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let interval = Interval::new(params.decay_interval);
|
let interval = Ticker::new(params.decay_interval);
|
||||||
let peer_score = PeerScore::new_with_message_delivery_time_callback(params, callback);
|
let peer_score = PeerScore::new_with_message_delivery_time_callback(params, callback);
|
||||||
self.peer_score = Some((peer_score, threshold, interval, GossipPromises::default()));
|
self.peer_score = Some((peer_score, threshold, interval, GossipPromises::default()));
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -1175,7 +1175,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn score_below_threshold_from_scores(
|
fn score_below_threshold_from_scores(
|
||||||
peer_score: &Option<(PeerScore, PeerScoreThresholds, Interval, GossipPromises)>,
|
peer_score: &Option<(PeerScore, PeerScoreThresholds, Ticker, GossipPromises)>,
|
||||||
peer_id: &PeerId,
|
peer_id: &PeerId,
|
||||||
threshold: impl Fn(&PeerScoreThresholds) -> f64,
|
threshold: impl Fn(&PeerScoreThresholds) -> f64,
|
||||||
) -> (bool, f64) {
|
) -> (bool, f64) {
|
||||||
@ -3472,12 +3472,12 @@ where
|
|||||||
|
|
||||||
// update scores
|
// update scores
|
||||||
if let Some((peer_score, _, interval, _)) = &mut self.peer_score {
|
if let Some((peer_score, _, interval, _)) = &mut self.peer_score {
|
||||||
while let Poll::Ready(Some(())) = interval.poll_next_unpin(cx) {
|
while let Poll::Ready(Some(_)) = interval.poll_next_unpin(cx) {
|
||||||
peer_score.refresh_scores();
|
peer_score.refresh_scores();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while let Poll::Ready(Some(())) = self.heartbeat.poll_next_unpin(cx) {
|
while let Poll::Ready(Some(_)) = self.heartbeat.poll_next_unpin(cx) {
|
||||||
self.heartbeat();
|
self.heartbeat();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,10 +21,10 @@
|
|||||||
use crate::peer_score::RejectReason;
|
use crate::peer_score::RejectReason;
|
||||||
use crate::MessageId;
|
use crate::MessageId;
|
||||||
use crate::ValidationError;
|
use crate::ValidationError;
|
||||||
|
use instant::Instant;
|
||||||
use libp2p_identity::PeerId;
|
use libp2p_identity::PeerId;
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use wasm_timer::Instant;
|
|
||||||
|
|
||||||
/// Tracks recently sent `IWANT` messages and checks if peers respond to them.
|
/// Tracks recently sent `IWANT` messages and checks if peers respond to them.
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
@ -24,12 +24,12 @@
|
|||||||
use crate::metrics::{Metrics, Penalty};
|
use crate::metrics::{Metrics, Penalty};
|
||||||
use crate::time_cache::TimeCache;
|
use crate::time_cache::TimeCache;
|
||||||
use crate::{MessageId, TopicHash};
|
use crate::{MessageId, TopicHash};
|
||||||
|
use instant::Instant;
|
||||||
use libp2p_identity::PeerId;
|
use libp2p_identity::PeerId;
|
||||||
use log::{debug, trace, warn};
|
use log::{debug, trace, warn};
|
||||||
use std::collections::{hash_map, HashMap, HashSet};
|
use std::collections::{hash_map, HashMap, HashSet};
|
||||||
use std::net::IpAddr;
|
use std::net::IpAddr;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use wasm_timer::Instant;
|
|
||||||
|
|
||||||
mod params;
|
mod params;
|
||||||
use crate::ValidationError;
|
use crate::ValidationError;
|
||||||
|
@ -21,13 +21,13 @@
|
|||||||
//! This implements a time-based LRU cache for checking gossipsub message duplicates.
|
//! This implements a time-based LRU cache for checking gossipsub message duplicates.
|
||||||
|
|
||||||
use fnv::FnvHashMap;
|
use fnv::FnvHashMap;
|
||||||
|
use instant::Instant;
|
||||||
use std::collections::hash_map::{
|
use std::collections::hash_map::{
|
||||||
self,
|
self,
|
||||||
Entry::{Occupied, Vacant},
|
Entry::{Occupied, Vacant},
|
||||||
};
|
};
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use wasm_timer::Instant;
|
|
||||||
|
|
||||||
struct ExpiringElement<Element> {
|
struct ExpiringElement<Element> {
|
||||||
/// The element that expires
|
/// The element that expires
|
||||||
|
@ -29,7 +29,7 @@ uint = "0.9"
|
|||||||
unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] }
|
unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] }
|
||||||
void = "1.0"
|
void = "1.0"
|
||||||
futures-timer = "3.0.2"
|
futures-timer = "3.0.2"
|
||||||
instant = "0.1.11"
|
instant = "0.1.12"
|
||||||
serde = { version = "1.0", optional = true, features = ["derive"] }
|
serde = { version = "1.0", optional = true, features = ["derive"] }
|
||||||
thiserror = "1"
|
thiserror = "1"
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ async-std = { version = "1.9.0", features = ["attributes"] }
|
|||||||
clap = { version = "4.3.0", features = ["derive"] }
|
clap = { version = "4.3.0", features = ["derive"] }
|
||||||
env_logger = "0.10.0"
|
env_logger = "0.10.0"
|
||||||
futures = "0.3.28"
|
futures = "0.3.28"
|
||||||
instant = "0.1.11"
|
instant = "0.1.12"
|
||||||
libp2p-core = { workspace = true }
|
libp2p-core = { workspace = true }
|
||||||
libp2p-dns = { workspace = true, features = ["async-std"] }
|
libp2p-dns = { workspace = true, features = ["async-std"] }
|
||||||
libp2p-identity = { workspace = true }
|
libp2p-identity = { workspace = true }
|
||||||
|
@ -14,7 +14,7 @@ categories = ["network-programming", "asynchronous"]
|
|||||||
either = "1.8.0"
|
either = "1.8.0"
|
||||||
futures = "0.3.28"
|
futures = "0.3.28"
|
||||||
futures-timer = "3.0.2"
|
futures-timer = "3.0.2"
|
||||||
instant = "0.1.11"
|
instant = "0.1.12"
|
||||||
libp2p-core = { workspace = true }
|
libp2p-core = { workspace = true }
|
||||||
libp2p-swarm = { workspace = true }
|
libp2p-swarm = { workspace = true }
|
||||||
libp2p-identity = { workspace = true }
|
libp2p-identity = { workspace = true }
|
||||||
|
@ -16,7 +16,7 @@ bytes = "1"
|
|||||||
either = "1.6.0"
|
either = "1.6.0"
|
||||||
futures = "0.3.28"
|
futures = "0.3.28"
|
||||||
futures-timer = "3"
|
futures-timer = "3"
|
||||||
instant = "0.1.11"
|
instant = "0.1.12"
|
||||||
libp2p-core = { workspace = true }
|
libp2p-core = { workspace = true }
|
||||||
libp2p-swarm = { workspace = true, features = ["async-std"] }
|
libp2p-swarm = { workspace = true, features = ["async-std"] }
|
||||||
libp2p-identity = { workspace = true }
|
libp2p-identity = { workspace = true }
|
||||||
|
@ -15,7 +15,7 @@ asynchronous-codec = "0.6"
|
|||||||
bimap = "0.6.3"
|
bimap = "0.6.3"
|
||||||
futures = { version = "0.3", default-features = false, features = ["std"] }
|
futures = { version = "0.3", default-features = false, features = ["std"] }
|
||||||
futures-timer = "3.0.2"
|
futures-timer = "3.0.2"
|
||||||
instant = "0.1.11"
|
instant = "0.1.12"
|
||||||
libp2p-core = { workspace = true }
|
libp2p-core = { workspace = true }
|
||||||
libp2p-swarm = { workspace = true }
|
libp2p-swarm = { workspace = true }
|
||||||
libp2p-identity = { workspace = true }
|
libp2p-identity = { workspace = true }
|
||||||
|
@ -13,7 +13,7 @@ categories = ["network-programming", "asynchronous"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
async-trait = "0.1"
|
async-trait = "0.1"
|
||||||
futures = "0.3.28"
|
futures = "0.3.28"
|
||||||
instant = "0.1.11"
|
instant = "0.1.12"
|
||||||
libp2p-core = { workspace = true }
|
libp2p-core = { workspace = true }
|
||||||
libp2p-swarm = { workspace = true }
|
libp2p-swarm = { workspace = true }
|
||||||
libp2p-identity = { workspace = true }
|
libp2p-identity = { workspace = true }
|
||||||
|
@ -15,7 +15,7 @@ either = "1.6.0"
|
|||||||
fnv = "1.0"
|
fnv = "1.0"
|
||||||
futures = "0.3.28"
|
futures = "0.3.28"
|
||||||
futures-timer = "3.0.2"
|
futures-timer = "3.0.2"
|
||||||
instant = "0.1.11"
|
instant = "0.1.12"
|
||||||
libp2p-core = { workspace = true }
|
libp2p-core = { workspace = true }
|
||||||
libp2p-identity = { workspace = true }
|
libp2p-identity = { workspace = true }
|
||||||
libp2p-swarm-derive = { workspace = true, optional = true }
|
libp2p-swarm-derive = { workspace = true, optional = true }
|
||||||
|
Reference in New Issue
Block a user