mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-04-25 11:02:12 +00:00
Merge branch 'master' into rand-feature
This commit is contained in:
commit
ee4f2f55b0
6
.github/workflows/interop-test.yml
vendored
6
.github/workflows/interop-test.yml
vendored
@ -10,8 +10,8 @@ concurrency:
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
run-multidim-interop:
|
||||
name: Run multidimensional interoperability tests
|
||||
run-transport-interop:
|
||||
name: Run transport interoperability tests
|
||||
runs-on: ${{ fromJSON(github.repository == 'libp2p/rust-libp2p' && '["self-hosted", "linux", "x64", "4xlarge"]' || '"ubuntu-latest"') }}
|
||||
strategy:
|
||||
matrix:
|
||||
@ -29,7 +29,7 @@ jobs:
|
||||
FLAVOUR: ${{ matrix.flavour }}
|
||||
|
||||
- name: Run ${{ matrix.flavour }} tests
|
||||
uses: libp2p/test-plans/.github/actions/run-interop-ping-test@master
|
||||
uses: libp2p/test-plans/.github/actions/run-transport-interop-test@master
|
||||
with:
|
||||
test-filter: ${{ matrix.flavour }}-rust-libp2p-head
|
||||
extra-versions: ${{ github.workspace }}/interop-tests/${{ matrix.flavour }}-ping-version.json
|
||||
|
106
Cargo.lock
generated
106
Cargo.lock
generated
@ -2094,9 +2094,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "if-watch"
|
||||
version = "3.0.1"
|
||||
version = "3.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a9465340214b296cd17a0009acdb890d6160010b8adf8f78a00d0d7ab270f79f"
|
||||
checksum = "bbb892e5777fe09e16f3d44de7802f4daa7267ecbe8c466f19d94e25bb0c303e"
|
||||
dependencies = [
|
||||
"async-io",
|
||||
"core-foundation",
|
||||
@ -2918,7 +2918,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libp2p-quic"
|
||||
version = "0.9.2"
|
||||
version = "0.9.3"
|
||||
dependencies = [
|
||||
"async-std",
|
||||
"bytes",
|
||||
@ -5013,18 +5013,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.188"
|
||||
version = "1.0.189"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e"
|
||||
checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.188"
|
||||
version = "1.0.189"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2"
|
||||
checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -6469,15 +6469,21 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows"
|
||||
version = "0.34.0"
|
||||
version = "0.51.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "45296b64204227616fdbf2614cefa4c236b98ee64dfaaaa435207ed99fe7829f"
|
||||
checksum = "ca229916c5ee38c2f2bc1e9d8f04df975b4bd93f9955dc69fabb5d91270045c9"
|
||||
dependencies = [
|
||||
"windows_aarch64_msvc 0.34.0",
|
||||
"windows_i686_gnu 0.34.0",
|
||||
"windows_i686_msvc 0.34.0",
|
||||
"windows_x86_64_gnu 0.34.0",
|
||||
"windows_x86_64_msvc 0.34.0",
|
||||
"windows-core",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.51.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -6491,90 +6497,60 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.48.1"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f"
|
||||
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc 0.48.0",
|
||||
"windows_i686_gnu 0.48.0",
|
||||
"windows_i686_msvc 0.48.0",
|
||||
"windows_x86_64_gnu 0.48.0",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc 0.48.0",
|
||||
"windows_x86_64_msvc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.48.0"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc"
|
||||
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.34.0"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "17cffbe740121affb56fad0fc0e421804adf0ae00891205213b5cecd30db881d"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3"
|
||||
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.34.0"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2564fde759adb79129d9b4f54be42b32c89970c18ebf93124ca8870a498688ed"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241"
|
||||
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.34.0"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9cd9d32ba70453522332c14d38814bceeb747d80b3958676007acadd7e166956"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00"
|
||||
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.34.0"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cfce6deae227ee8d356d19effc141a509cc503dfd1f850622ec4b0f84428e1f4"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1"
|
||||
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.48.0"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953"
|
||||
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.34.0"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d19538ccc21819d01deaf88d6a17eae6596a12e9aafdbb97916fb49896d89de9"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
|
||||
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
|
||||
|
||||
[[package]]
|
||||
name = "winreg"
|
||||
|
@ -95,7 +95,7 @@ libp2p-perf = { version = "0.2.0", path = "protocols/perf" }
|
||||
libp2p-ping = { version = "0.43.1", path = "protocols/ping" }
|
||||
libp2p-plaintext = { version = "0.40.1", path = "transports/plaintext" }
|
||||
libp2p-pnet = { version = "0.23.0", path = "transports/pnet" }
|
||||
libp2p-quic = { version = "0.9.2", path = "transports/quic" }
|
||||
libp2p-quic = { version = "0.9.3", path = "transports/quic" }
|
||||
libp2p-relay = { version = "0.16.1", path = "protocols/relay" }
|
||||
libp2p-rendezvous = { version = "0.13.0", path = "protocols/rendezvous" }
|
||||
libp2p-upnp = { version = "0.1.1", path = "protocols/upnp" }
|
||||
|
@ -66,6 +66,8 @@ pub struct SwarmBuilder<Provider, Phase> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::SwarmBuilder;
|
||||
use libp2p_core::{muxing::StreamMuxerBox, transport::dummy::DummyTransport};
|
||||
use libp2p_identity::PeerId;
|
||||
use libp2p_swarm::{NetworkBehaviour, Swarm};
|
||||
|
||||
#[test]
|
||||
@ -228,9 +230,6 @@ mod tests {
|
||||
#[test]
|
||||
#[cfg(feature = "tokio")]
|
||||
fn other_transport() -> Result<(), Box<dyn std::error::Error>> {
|
||||
use libp2p_core::{muxing::StreamMuxerBox, transport::dummy::DummyTransport};
|
||||
use libp2p_identity::PeerId;
|
||||
|
||||
let _ = SwarmBuilder::with_new_identity()
|
||||
.with_tokio()
|
||||
// Closure can either return a Transport directly.
|
||||
@ -319,4 +318,56 @@ mod tests {
|
||||
.unwrap()
|
||||
.build();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(all(feature = "tokio", feature = "tcp", feature = "tls", feature = "yamux"))]
|
||||
fn tcp_bandwidth_logging() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let (builder, _logging) = SwarmBuilder::with_new_identity()
|
||||
.with_tokio()
|
||||
.with_tcp(
|
||||
Default::default(),
|
||||
libp2p_tls::Config::new,
|
||||
libp2p_yamux::Config::default,
|
||||
)?
|
||||
.with_bandwidth_logging();
|
||||
|
||||
builder
|
||||
.with_behaviour(|_| libp2p_swarm::dummy::Behaviour)
|
||||
.unwrap()
|
||||
.build();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(all(feature = "tokio", feature = "quic"))]
|
||||
fn quic_bandwidth_logging() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let (builder, _logging) = SwarmBuilder::with_new_identity()
|
||||
.with_tokio()
|
||||
.with_quic()
|
||||
.with_bandwidth_logging();
|
||||
|
||||
builder
|
||||
.with_behaviour(|_| libp2p_swarm::dummy::Behaviour)
|
||||
.unwrap()
|
||||
.build();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "tokio")]
|
||||
fn other_transport_bandwidth_logging() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let (builder, _logging) = SwarmBuilder::with_new_identity()
|
||||
.with_tokio()
|
||||
.with_other_transport(|_| DummyTransport::<(PeerId, StreamMuxerBox)>::new())?
|
||||
.with_bandwidth_logging();
|
||||
|
||||
builder
|
||||
.with_behaviour(|_| libp2p_swarm::dummy::Behaviour)
|
||||
.unwrap()
|
||||
.build();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ use libp2p_core::muxing::StreamMuxer;
|
||||
all(not(target_arch = "wasm32"), feature = "websocket")
|
||||
))]
|
||||
use libp2p_core::{InboundUpgrade, Negotiated, OutboundUpgrade, UpgradeInfo};
|
||||
use std::marker::PhantomData;
|
||||
use std::{marker::PhantomData, sync::Arc};
|
||||
|
||||
pub struct QuicPhase<T> {
|
||||
pub(crate) transport: T,
|
||||
@ -237,3 +237,21 @@ impl_quic_phase_with_websocket!(
|
||||
super::provider::Tokio,
|
||||
rw_stream_sink::RwStreamSink<libp2p_websocket::BytesConnection<libp2p_tcp::tokio::TcpStream>>
|
||||
);
|
||||
impl<Provider, T: AuthenticatedMultiplexedTransport> SwarmBuilder<Provider, QuicPhase<T>> {
|
||||
pub fn with_bandwidth_logging(
|
||||
self,
|
||||
) -> (
|
||||
SwarmBuilder<
|
||||
Provider,
|
||||
BehaviourPhase<impl AuthenticatedMultiplexedTransport, NoRelayBehaviour>,
|
||||
>,
|
||||
Arc<crate::bandwidth::BandwidthSinks>,
|
||||
) {
|
||||
self.without_quic()
|
||||
.without_any_other_transports()
|
||||
.without_dns()
|
||||
.without_relay()
|
||||
.without_websocket()
|
||||
.with_bandwidth_logging()
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ publish = false
|
||||
[dependencies]
|
||||
clap = { version = "4.3.23", features = ["derive"] }
|
||||
zeroize = "1"
|
||||
serde = { version = "1.0.188", features = ["derive"] }
|
||||
serde = { version = "1.0.189", features = ["derive"] }
|
||||
serde_json = "1.0.107"
|
||||
libp2p-core = { workspace = true }
|
||||
base64 = "0.21.4"
|
||||
|
@ -1,10 +1,5 @@
|
||||
# Changelog
|
||||
All notable changes to this project will be documented in this file.
|
||||
## 0.12.3
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [0.12.3]
|
||||
### Changed
|
||||
- Add libp2p-lookup to Dockerfile to enable healthchecks.
|
||||
|
||||
@ -16,14 +11,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
[PR 4467]: https://github.com/libp2p/rust-libp2p/pull/4467
|
||||
|
||||
## [0.12.2]
|
||||
## 0.12.2
|
||||
### Fixed
|
||||
- Adhere to `--metrics-path` flag and listen on `0.0.0.0:8888` (default IPFS metrics port).
|
||||
[PR 4392]
|
||||
|
||||
[PR 4392]: https://github.com/libp2p/rust-libp2p/pull/4392
|
||||
|
||||
## [0.12.1]
|
||||
## 0.12.1
|
||||
### Changed
|
||||
- Move to tokio and hyper.
|
||||
See [PR 4311].
|
||||
@ -32,40 +27,40 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
[PR 4311]: https://github.com/libp2p/rust-libp2p/pull/4311
|
||||
|
||||
## [0.8.0]
|
||||
## 0.8.0
|
||||
### Changed
|
||||
- Remove mplex support.
|
||||
|
||||
## [0.7.0]
|
||||
## 0.7.0
|
||||
### Changed
|
||||
- Update to libp2p v0.47.0.
|
||||
|
||||
## [0.6.0] - [2022-05-05]
|
||||
## 0.6.0 - 2022-05-05
|
||||
### Changed
|
||||
- Update to libp2p v0.44.0.
|
||||
|
||||
## [0.5.4] - [2022-01-11]
|
||||
## 0.5.4 - 2022-01-11
|
||||
### Changed
|
||||
- Pull latest autonat changes.
|
||||
|
||||
## [0.5.3] - [2021-12-25]
|
||||
## 0.5.3 - 2021-12-25
|
||||
### Changed
|
||||
- Update dependencies.
|
||||
- Pull in autonat fixes.
|
||||
|
||||
## [0.5.2] - [2021-12-20]
|
||||
## 0.5.2 - 2021-12-20
|
||||
### Added
|
||||
- Add support for libp2p autonat protocol via `--enable-autonat`.
|
||||
|
||||
## [0.5.1] - [2021-12-20]
|
||||
## 0.5.1 - 2021-12-20
|
||||
### Fixed
|
||||
- Update dependencies.
|
||||
- Fix typo in command line flag `--enable-kademlia`.
|
||||
|
||||
## [0.5.0] - 2021-11-18
|
||||
## 0.5.0 - 2021-11-18
|
||||
### Changed
|
||||
- Disable Kademlia protocol by default.
|
||||
|
||||
## [0.4.0] - 2021-11-18
|
||||
## 0.4.0 - 2021-11-18
|
||||
### Fixed
|
||||
- Update dependencies.
|
||||
|
@ -20,7 +20,7 @@ hyper = { version = "0.14", features = ["server", "tcp", "http1"] }
|
||||
libp2p = { workspace = true, features = ["autonat", "dns", "tokio", "noise", "tcp", "yamux", "identify", "kad", "ping", "relay", "metrics", "rsa", "macros", "quic"] }
|
||||
log = "0.4"
|
||||
prometheus-client = "0.21.2"
|
||||
serde = "1.0.188"
|
||||
serde = "1.0.189"
|
||||
serde_derive = "1.0.125"
|
||||
serde_json = "1.0"
|
||||
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
|
||||
|
@ -87,6 +87,7 @@ struct PeriodicJob<T> {
|
||||
}
|
||||
|
||||
impl<T> PeriodicJob<T> {
|
||||
#[cfg(test)]
|
||||
fn is_running(&self) -> bool {
|
||||
match self.state {
|
||||
PeriodicJobState::Running(..) => true,
|
||||
@ -96,6 +97,7 @@ impl<T> PeriodicJob<T> {
|
||||
|
||||
/// Cuts short the remaining delay, if the job is currently waiting
|
||||
/// for the delay to expire.
|
||||
#[cfg(test)]
|
||||
fn asap(&mut self) {
|
||||
if let PeriodicJobState::Waiting(delay, deadline) = &mut self.state {
|
||||
let new_deadline = Instant::now().checked_sub(Duration::from_secs(1)).unwrap();
|
||||
@ -169,6 +171,7 @@ impl PutRecordJob {
|
||||
}
|
||||
|
||||
/// Checks whether the job is currently running.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn is_running(&self) -> bool {
|
||||
self.inner.is_running()
|
||||
}
|
||||
@ -177,6 +180,7 @@ impl PutRecordJob {
|
||||
/// for the delay to expire.
|
||||
///
|
||||
/// The job is guaranteed to run on the next invocation of `poll`.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn asap(&mut self, publish: bool) {
|
||||
if publish {
|
||||
self.next_publish = Some(Instant::now().checked_sub(Duration::from_secs(1)).unwrap())
|
||||
@ -273,6 +277,7 @@ impl AddProviderJob {
|
||||
}
|
||||
|
||||
/// Checks whether the job is currently running.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn is_running(&self) -> bool {
|
||||
self.inner.is_running()
|
||||
}
|
||||
@ -281,6 +286,7 @@ impl AddProviderJob {
|
||||
/// for the delay to expire.
|
||||
///
|
||||
/// The job is guaranteed to run on the next invocation of `poll`.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn asap(&mut self) {
|
||||
self.inner.asap()
|
||||
}
|
||||
|
@ -54,10 +54,6 @@ pub enum NodeStatus {
|
||||
}
|
||||
|
||||
impl<TKey, TVal> PendingNode<TKey, TVal> {
|
||||
pub(crate) fn key(&self) -> &TKey {
|
||||
&self.node.key
|
||||
}
|
||||
|
||||
pub(crate) fn status(&self) -> NodeStatus {
|
||||
self.status
|
||||
}
|
||||
@ -70,6 +66,7 @@ impl<TKey, TVal> PendingNode<TKey, TVal> {
|
||||
Instant::now() >= self.replace
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn set_ready_at(&mut self, t: Instant) {
|
||||
self.replace = t;
|
||||
}
|
||||
@ -191,11 +188,6 @@ where
|
||||
.filter(|p| p.node.key.as_ref() == key.as_ref())
|
||||
}
|
||||
|
||||
/// Returns a reference to a node in the bucket.
|
||||
pub(crate) fn get(&self, key: &TKey) -> Option<&Node<TKey, TVal>> {
|
||||
self.position(key).map(|p| &self.nodes[p.0])
|
||||
}
|
||||
|
||||
/// Returns an iterator over the nodes in the bucket, together with their status.
|
||||
pub(crate) fn iter(&self) -> impl Iterator<Item = (&Node<TKey, TVal>, NodeStatus)> {
|
||||
self.nodes
|
||||
@ -398,22 +390,19 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks whether the given position refers to a connected node.
|
||||
pub(crate) fn is_connected(&self, pos: Position) -> bool {
|
||||
self.status(pos) == NodeStatus::Connected
|
||||
}
|
||||
|
||||
/// Gets the number of entries currently in the bucket.
|
||||
pub(crate) fn num_entries(&self) -> usize {
|
||||
self.nodes.len()
|
||||
}
|
||||
|
||||
/// Gets the number of entries in the bucket that are considered connected.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn num_connected(&self) -> usize {
|
||||
self.first_connected_pos.map_or(0, |i| self.nodes.len() - i)
|
||||
}
|
||||
|
||||
/// Gets the number of entries in the bucket that are considered disconnected.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn num_disconnected(&self) -> usize {
|
||||
self.nodes.len() - self.num_connected()
|
||||
}
|
||||
|
@ -135,20 +135,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the key of the entry.
|
||||
///
|
||||
/// Returns `None` if the `Key` used to construct this `Entry` is not a valid
|
||||
/// key for an entry in a bucket, which is the case for the `local_key` of
|
||||
/// the `KBucketsTable` referring to the local node.
|
||||
pub(crate) fn key(&self) -> Option<&TKey> {
|
||||
match self {
|
||||
Entry::Present(entry, _) => Some(entry.key()),
|
||||
Entry::Pending(entry, _) => Some(entry.key()),
|
||||
Entry::Absent(entry) => Some(entry.key()),
|
||||
Entry::SelfEntry => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the value associated with the entry.
|
||||
///
|
||||
/// Returns `None` if the entry is absent from any bucket or refers to the
|
||||
@ -175,11 +161,6 @@ where
|
||||
PresentEntry(EntryRef { bucket, key })
|
||||
}
|
||||
|
||||
/// Returns the key of the entry.
|
||||
pub(crate) fn key(&self) -> &TKey {
|
||||
self.0.key
|
||||
}
|
||||
|
||||
/// Returns the value associated with the key.
|
||||
pub(crate) fn value(&mut self) -> &mut TVal {
|
||||
&mut self
|
||||
@ -218,11 +199,6 @@ where
|
||||
PendingEntry(EntryRef { bucket, key })
|
||||
}
|
||||
|
||||
/// Returns the key of the entry.
|
||||
pub(crate) fn key(&self) -> &TKey {
|
||||
self.0.key
|
||||
}
|
||||
|
||||
/// Returns the value associated with the key.
|
||||
pub(crate) fn value(&mut self) -> &mut TVal {
|
||||
self.0
|
||||
@ -262,11 +238,6 @@ where
|
||||
AbsentEntry(EntryRef { bucket, key })
|
||||
}
|
||||
|
||||
/// Returns the key of the entry.
|
||||
pub(crate) fn key(&self) -> &TKey {
|
||||
self.0.key
|
||||
}
|
||||
|
||||
/// Attempts to insert the entry into a bucket.
|
||||
pub(crate) fn insert(self, value: TVal, status: NodeStatus) -> InsertResult<TKey> {
|
||||
self.0.bucket.insert(
|
||||
|
@ -33,9 +33,6 @@
|
||||
//! existing nodes in the kademlia network cannot obtain the listen addresses
|
||||
//! of nodes querying them, and thus will not be able to add them to their routing table.
|
||||
|
||||
// TODO: we allow dead_code for now because this library contains a lot of unused code that will
|
||||
// be useful later for record store
|
||||
#![allow(dead_code)]
|
||||
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
|
||||
|
||||
mod record_priv;
|
||||
|
@ -326,15 +326,6 @@ impl<TInner> Query<TInner> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks whether the query is currently waiting for a result from `peer`.
|
||||
pub(crate) fn is_waiting(&self, peer: &PeerId) -> bool {
|
||||
match &self.peer_iter {
|
||||
QueryPeerIter::Closest(iter) => iter.is_waiting(peer),
|
||||
QueryPeerIter::ClosestDisjoint(iter) => iter.is_waiting(peer),
|
||||
QueryPeerIter::Fixed(iter) => iter.is_waiting(peer),
|
||||
}
|
||||
}
|
||||
|
||||
/// Advances the state of the underlying peer iterator.
|
||||
fn next(&mut self, now: Instant) -> PeersIterState<'_> {
|
||||
let state = match &mut self.peer_iter {
|
||||
|
@ -788,6 +788,7 @@ mod tests {
|
||||
QuickCheck::new().tests(10).quickcheck(prop as fn(_))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stalled_at_capacity() {
|
||||
fn prop(mut iter: ClosestPeersIter) {
|
||||
iter.state = State::Stalled;
|
||||
|
@ -31,7 +31,6 @@ use std::{
|
||||
/// Wraps around a set of [`ClosestPeersIter`], enforcing a disjoint discovery
|
||||
/// path per configured parallelism according to the S/Kademlia paper.
|
||||
pub(crate) struct ClosestDisjointPeersIter {
|
||||
config: ClosestPeersIterConfig,
|
||||
target: KeyBytes,
|
||||
|
||||
/// The set of wrapped [`ClosestPeersIter`].
|
||||
@ -51,6 +50,7 @@ pub(crate) struct ClosestDisjointPeersIter {
|
||||
|
||||
impl ClosestDisjointPeersIter {
|
||||
/// Creates a new iterator with a default configuration.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn new<I>(target: KeyBytes, known_closest_peers: I) -> Self
|
||||
where
|
||||
I: IntoIterator<Item = Key<PeerId>>,
|
||||
@ -88,7 +88,6 @@ impl ClosestDisjointPeersIter {
|
||||
let iters_len = iters.len();
|
||||
|
||||
ClosestDisjointPeersIter {
|
||||
config,
|
||||
target: target.into(),
|
||||
iters,
|
||||
iter_order: (0..iters_len)
|
||||
@ -190,10 +189,6 @@ impl ClosestDisjointPeersIter {
|
||||
updated
|
||||
}
|
||||
|
||||
pub(crate) fn is_waiting(&self, peer: &PeerId) -> bool {
|
||||
self.iters.iter().any(|i| i.is_waiting(peer))
|
||||
}
|
||||
|
||||
pub(crate) fn next(&mut self, now: Instant) -> PeersIterState<'_> {
|
||||
let mut state = None;
|
||||
|
||||
|
@ -115,10 +115,6 @@ impl FixedPeersIter {
|
||||
false
|
||||
}
|
||||
|
||||
pub(crate) fn is_waiting(&self, peer: &PeerId) -> bool {
|
||||
self.peers.get(peer) == Some(&PeerState::Waiting)
|
||||
}
|
||||
|
||||
pub(crate) fn finish(&mut self) {
|
||||
if let State::Waiting { .. } = self.state {
|
||||
self.state = State::Finished
|
||||
|
@ -2,8 +2,10 @@ use libp2p_identify as identify;
|
||||
use libp2p_identity as identity;
|
||||
use libp2p_kad::store::MemoryStore;
|
||||
use libp2p_kad::{Behaviour, Config, Event, Mode};
|
||||
use libp2p_swarm::Swarm;
|
||||
use libp2p_swarm::{Swarm, SwarmEvent};
|
||||
use libp2p_swarm_test::SwarmExt;
|
||||
use Event::*;
|
||||
use MyBehaviourEvent::*;
|
||||
|
||||
#[async_std::test]
|
||||
async fn server_gets_added_to_routing_table_by_client() {
|
||||
@ -16,16 +18,16 @@ async fn server_gets_added_to_routing_table_by_client() {
|
||||
client.connect(&mut server).await;
|
||||
|
||||
let server_peer_id = *server.local_peer_id();
|
||||
async_std::task::spawn(server.loop_on_next());
|
||||
|
||||
match libp2p_swarm_test::drive(&mut client, &mut server).await {
|
||||
(
|
||||
[MyBehaviourEvent::Identify(_), MyBehaviourEvent::Identify(_), MyBehaviourEvent::Kad(Event::RoutingUpdated { peer, .. })],
|
||||
[MyBehaviourEvent::Identify(_), MyBehaviourEvent::Identify(_)],
|
||||
) => {
|
||||
assert_eq!(peer, server_peer_id)
|
||||
}
|
||||
other => panic!("Unexpected events: {other:?}"),
|
||||
}
|
||||
let peer = client
|
||||
.wait(|e| match e {
|
||||
SwarmEvent::Behaviour(Kad(RoutingUpdated { peer, .. })) => Some(peer),
|
||||
_ => None,
|
||||
})
|
||||
.await;
|
||||
|
||||
assert_eq!(peer, server_peer_id);
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
@ -41,12 +43,10 @@ async fn two_servers_add_each_other_to_routing_table() {
|
||||
let server1_peer_id = *server1.local_peer_id();
|
||||
let server2_peer_id = *server2.local_peer_id();
|
||||
|
||||
use Event::*;
|
||||
use MyBehaviourEvent::*;
|
||||
|
||||
match libp2p_swarm_test::drive(&mut server1, &mut server2).await {
|
||||
(
|
||||
[Identify(_), Identify(_), Kad(RoutingUpdated { peer: peer1, .. })],
|
||||
[Identify(_), Identify(_), Kad(RoutingUpdated { peer: peer1, .. })]
|
||||
| [Identify(_), Kad(RoutingUpdated { peer: peer1, .. }), Identify(_)],
|
||||
[Identify(_), Identify(_)],
|
||||
) => {
|
||||
assert_eq!(peer1, server2_peer_id);
|
||||
@ -57,19 +57,16 @@ async fn two_servers_add_each_other_to_routing_table() {
|
||||
server1.listen().await;
|
||||
server2.connect(&mut server1).await;
|
||||
|
||||
match libp2p_swarm_test::drive(&mut server2, &mut server1).await {
|
||||
(
|
||||
[Identify(_), Kad(RoutingUpdated { peer: peer2, .. }), Identify(_)],
|
||||
[Identify(_), Identify(_)],
|
||||
)
|
||||
| (
|
||||
[Identify(_), Identify(_), Kad(RoutingUpdated { peer: peer2, .. })],
|
||||
[Identify(_), Identify(_)],
|
||||
) => {
|
||||
assert_eq!(peer2, server1_peer_id);
|
||||
}
|
||||
other => panic!("Unexpected events: {other:?}"),
|
||||
}
|
||||
async_std::task::spawn(server1.loop_on_next());
|
||||
|
||||
let peer = server2
|
||||
.wait(|e| match e {
|
||||
SwarmEvent::Behaviour(Kad(RoutingUpdated { peer, .. })) => Some(peer),
|
||||
_ => None,
|
||||
})
|
||||
.await;
|
||||
|
||||
assert_eq!(peer, server1_peer_id);
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
@ -85,17 +82,12 @@ async fn adding_an_external_addresses_activates_server_mode_on_existing_connecti
|
||||
// Remove memory address to simulate a server that doesn't know its external address.
|
||||
server.remove_external_address(&memory_addr);
|
||||
client.dial(memory_addr.clone()).unwrap();
|
||||
|
||||
use MyBehaviourEvent::*;
|
||||
|
||||
// Do the usual identify send/receive dance.
|
||||
match libp2p_swarm_test::drive(&mut client, &mut server).await {
|
||||
([Identify(_), Identify(_)], [Identify(_), Identify(_)]) => {}
|
||||
other => panic!("Unexpected events: {other:?}"),
|
||||
}
|
||||
|
||||
use Event::*;
|
||||
|
||||
// Server learns its external address (this could be through AutoNAT or some other mechanism).
|
||||
server.add_external_address(memory_addr);
|
||||
|
||||
@ -125,34 +117,38 @@ async fn set_client_to_server_mode() {
|
||||
|
||||
let server_peer_id = *server.local_peer_id();
|
||||
|
||||
match libp2p_swarm_test::drive(&mut client, &mut server).await {
|
||||
(
|
||||
[MyBehaviourEvent::Identify(_), MyBehaviourEvent::Identify(_), MyBehaviourEvent::Kad(Event::RoutingUpdated { peer, .. })],
|
||||
[MyBehaviourEvent::Identify(_), MyBehaviourEvent::Identify(identify::Event::Received { info, .. })],
|
||||
) => {
|
||||
assert_eq!(peer, server_peer_id);
|
||||
assert!(info
|
||||
.protocols
|
||||
.iter()
|
||||
.all(|proto| libp2p_kad::PROTOCOL_NAME.ne(proto)))
|
||||
}
|
||||
other => panic!("Unexpected events: {other:?}"),
|
||||
}
|
||||
let client_event = client.wait(|e| match e {
|
||||
SwarmEvent::Behaviour(Kad(RoutingUpdated { peer, .. })) => Some(peer),
|
||||
_ => None,
|
||||
});
|
||||
let server_event = server.wait(|e| match e {
|
||||
SwarmEvent::Behaviour(Identify(identify::Event::Received { info, .. })) => Some(info),
|
||||
_ => None,
|
||||
});
|
||||
|
||||
let (peer, info) = futures::future::join(client_event, server_event).await;
|
||||
|
||||
assert_eq!(peer, server_peer_id);
|
||||
assert!(info
|
||||
.protocols
|
||||
.iter()
|
||||
.all(|proto| libp2p_kad::PROTOCOL_NAME.ne(proto)));
|
||||
|
||||
client.behaviour_mut().kad.set_mode(Some(Mode::Server));
|
||||
|
||||
match libp2p_swarm_test::drive(&mut client, &mut server).await {
|
||||
(
|
||||
[MyBehaviourEvent::Identify(_)],
|
||||
[MyBehaviourEvent::Identify(identify::Event::Received { info, .. }), MyBehaviourEvent::Kad(_)],
|
||||
) => {
|
||||
assert!(info
|
||||
.protocols
|
||||
.iter()
|
||||
.any(|proto| libp2p_kad::PROTOCOL_NAME.eq(proto)))
|
||||
}
|
||||
other => panic!("Unexpected events: {other:?}"),
|
||||
}
|
||||
async_std::task::spawn(client.loop_on_next());
|
||||
|
||||
let info = server
|
||||
.wait(|e| match e {
|
||||
SwarmEvent::Behaviour(Identify(identify::Event::Received { info, .. })) => Some(info),
|
||||
_ => None,
|
||||
})
|
||||
.await;
|
||||
|
||||
assert!(info
|
||||
.protocols
|
||||
.iter()
|
||||
.any(|proto| libp2p_kad::PROTOCOL_NAME.eq(proto)));
|
||||
}
|
||||
|
||||
#[derive(libp2p_swarm::NetworkBehaviour)]
|
||||
|
@ -14,7 +14,7 @@ categories = ["network-programming", "asynchronous"]
|
||||
async-io = { version = "1.13.0", optional = true }
|
||||
data-encoding = "2.4.0"
|
||||
futures = "0.3.28"
|
||||
if-watch = "3.0.1"
|
||||
if-watch = "3.1.0"
|
||||
libp2p-core = { workspace = true }
|
||||
libp2p-swarm = { workspace = true }
|
||||
libp2p-identity = { workspace = true }
|
||||
|
@ -4,6 +4,8 @@
|
||||
Most users should use `libp2p::SwarmBuilder`.
|
||||
In some special cases, users may need to use `Swarm::new` and `Config` instead of the new `libp2p::SwarmBuilder`.
|
||||
See [PR 4120].
|
||||
- Make the `Debug` implementation of `StreamProtocol` more concise.
|
||||
See [PR 4631](https://github.com/libp2p/rust-libp2p/pull/4631).
|
||||
|
||||
[PR 4120]: https://github.com/libp2p/rust-libp2p/pull/4120
|
||||
|
||||
|
@ -7,7 +7,7 @@ use std::sync::Arc;
|
||||
///
|
||||
/// libp2p nodes use stream protocols to negotiate what to do with a newly opened stream.
|
||||
/// Stream protocols are string-based and must start with a forward slash: `/`.
|
||||
#[derive(Debug, Clone, Eq)]
|
||||
#[derive(Clone, Eq)]
|
||||
pub struct StreamProtocol {
|
||||
inner: Either<&'static str, Arc<str>>,
|
||||
}
|
||||
@ -50,6 +50,12 @@ impl AsRef<str> for StreamProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for StreamProtocol {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
either::for_both!(&self.inner, s => s.fmt(f))
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for StreamProtocol {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
self.inner.fmt(f)
|
||||
@ -102,3 +108,25 @@ impl fmt::Display for InvalidProtocol {
|
||||
}
|
||||
|
||||
impl std::error::Error for InvalidProtocol {}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn stream_protocol_print() {
|
||||
let protocol = StreamProtocol::new("/foo/bar/1.0.0");
|
||||
|
||||
let debug = format!("{protocol:?}");
|
||||
let display = format!("{protocol}");
|
||||
|
||||
assert_eq!(
|
||||
debug, r#""/foo/bar/1.0.0""#,
|
||||
"protocol to debug print as string with quotes"
|
||||
);
|
||||
assert_eq!(
|
||||
display, "/foo/bar/1.0.0",
|
||||
"protocol to display print as string without quotes"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,11 @@
|
||||
## 0.9.3 - unreleased
|
||||
|
||||
- No longer report error when explicit closing of a QUIC endpoint succeeds.
|
||||
See [PR 4621].
|
||||
|
||||
- Support QUIC stateless resets for supported `libp2p_identity::Keypair`s. See [PR 4554].
|
||||
|
||||
[PR 4621]: https://github.com/libp2p/rust-libp2p/pull/4621
|
||||
[PR 4554]: https://github.com/libp2p/rust-libp2p/pull/4554
|
||||
|
||||
## 0.9.2
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "libp2p-quic"
|
||||
version = "0.9.2"
|
||||
version = "0.9.3"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2021"
|
||||
rust-version = { workspace = true }
|
||||
@ -13,7 +13,7 @@ async-std = { version = "1.12.0", optional = true }
|
||||
bytes = "1.5.0"
|
||||
futures = "0.3.28"
|
||||
futures-timer = "3.0.2"
|
||||
if-watch = "3.0.1"
|
||||
if-watch = "3.1.0"
|
||||
libp2p-core = { workspace = true }
|
||||
libp2p-tls = { workspace = true }
|
||||
libp2p-identity = { workspace = true }
|
||||
|
@ -91,6 +91,7 @@ pub enum Error {
|
||||
Io(#[from] std::io::Error),
|
||||
|
||||
/// The task to drive a quic endpoint has crashed.
|
||||
#[deprecated(since = "0.9.3", note = "No longer emitted")]
|
||||
#[error("Endpoint driver crashed")]
|
||||
EndpointDriverCrashed,
|
||||
|
||||
|
@ -588,7 +588,7 @@ impl<P: Provider> Stream for Listener<P> {
|
||||
return Poll::Ready(Some(event));
|
||||
}
|
||||
Poll::Ready(None) => {
|
||||
self.close(Err(Error::EndpointDriverCrashed));
|
||||
self.close(Ok(()));
|
||||
continue;
|
||||
}
|
||||
Poll::Pending => {}
|
||||
|
@ -39,24 +39,6 @@ async fn async_std_smoke() {
|
||||
smoke::<quic::async_std::Provider>().await
|
||||
}
|
||||
|
||||
#[cfg(feature = "async-std")]
|
||||
#[async_std::test]
|
||||
async fn dial_failure() {
|
||||
let _ = env_logger::try_init();
|
||||
let mut a = create_default_transport::<quic::async_std::Provider>().1;
|
||||
let mut b = create_default_transport::<quic::async_std::Provider>().1;
|
||||
|
||||
let addr = start_listening(&mut a, "/ip4/127.0.0.1/udp/0/quic-v1").await;
|
||||
drop(a); // stop a so b can never reach it
|
||||
|
||||
match dial(&mut b, addr).await {
|
||||
Ok(_) => panic!("Expected dial to fail"),
|
||||
Err(error) => {
|
||||
assert_eq!("Handshake with the remote timed out.", error.to_string())
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(feature = "tokio")]
|
||||
#[tokio::test]
|
||||
async fn endpoint_reuse() {
|
||||
|
@ -14,7 +14,7 @@ categories = ["network-programming", "asynchronous"]
|
||||
async-io = { version = "1.13.0", optional = true }
|
||||
futures = "0.3.28"
|
||||
futures-timer = "3.0"
|
||||
if-watch = "3.0.1"
|
||||
if-watch = "3.1.0"
|
||||
libc = "0.2.149"
|
||||
libp2p-core = { workspace = true }
|
||||
libp2p-identity = { workspace = true }
|
||||
|
@ -16,7 +16,7 @@ bytes = "1"
|
||||
futures = "0.3"
|
||||
futures-timer = "3"
|
||||
hex = "0.4"
|
||||
if-watch = "3.0"
|
||||
if-watch = "3.1"
|
||||
libp2p-core = { workspace = true }
|
||||
libp2p-noise = { workspace = true }
|
||||
libp2p-identity = { workspace = true }
|
||||
|
@ -1,7 +1,7 @@
|
||||
# 0.2.0 - unreleased
|
||||
## 0.2.0 - unreleased
|
||||
|
||||
- Add Websys Websocket transport.
|
||||
|
||||
# 0.1.0
|
||||
## 0.1.0
|
||||
|
||||
- Crate claimed.
|
||||
|
Loading…
x
Reference in New Issue
Block a user