Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(libp2p-swarm-test): Support tokio #5489

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions swarm-test/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
## 0.4.1

- Add `tokio` support.

## 0.4.0

<!-- Update to libp2p-swarm v0.45.0 -->


## 0.3.0


Expand Down
11 changes: 8 additions & 3 deletions swarm-test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "libp2p-swarm-test"
version = "0.4.0"
version = "0.4.1"
edition = "2021"
rust-version = { workspace = true }
license = "MIT"
Expand All @@ -16,8 +16,8 @@ async-trait = "0.1.80"
libp2p-core = { workspace = true }
libp2p-identity = { workspace = true, features = ["rand"] }
libp2p-plaintext = { workspace = true }
libp2p-swarm = { workspace = true, features = ["async-std"] }
libp2p-tcp = { workspace = true, features = ["async-io"] }
libp2p-swarm = { workspace = true }
libp2p-tcp = { workspace = true }
libp2p-yamux = { workspace = true }
futures = { workspace = true }
rand = "0.8.5"
Expand All @@ -26,3 +26,8 @@ futures-timer = "3.0.3"

[lints]
workspace = true

[features]
default = ["async-std"]
async-std = ["libp2p-swarm/async-std", "libp2p-tcp/async-io"]
tokio = ["libp2p-swarm/tokio", "libp2p-tcp/tokio"]
25 changes: 17 additions & 8 deletions swarm-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,21 +207,30 @@
let identity = Keypair::generate_ed25519();
let peer_id = PeerId::from(identity.public());

#[cfg(feature = "async-std")]
let fallback_transport = libp2p_tcp::async_io::Transport::default();

Check failure on line 211 in swarm-test/src/lib.rs

View workflow job for this annotation

GitHub Actions / Compile with MSRV

unused variable: `fallback_transport`

Check failure on line 211 in swarm-test/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (1.78.0)

unused variable: `fallback_transport`

Check failure on line 211 in swarm-test/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (beta)

unused variable: `fallback_transport`

Check failure on line 211 in swarm-test/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test libp2p-swarm-test

unused variable: `fallback_transport`

#[cfg(feature = "tokio")]
let fallback_transport = libp2p_tcp::tokio::Transport::default();

let transport = MemoryTransport::default()
.or_transport(libp2p_tcp::async_io::Transport::default())
.or_transport(fallback_transport)
.upgrade(Version::V1)
.authenticate(plaintext::Config::new(&identity))
.multiplex(yamux::Config::default())
.timeout(Duration::from_secs(20))
.boxed();

Swarm::new(
transport,
behaviour_fn(identity),
peer_id,
swarm::Config::with_async_std_executor()
.with_idle_connection_timeout(Duration::from_secs(5)), // Some tests need connections to be kept alive beyond what the individual behaviour configures.,
)
#[cfg(feature = "async-std")]
let mut config = swarm::Config::with_async_std_executor();

Check failure on line 225 in swarm-test/src/lib.rs

View workflow job for this annotation

GitHub Actions / Compile with MSRV

unused variable: `config`

Check failure on line 225 in swarm-test/src/lib.rs

View workflow job for this annotation

GitHub Actions / Compile with MSRV

variable does not need to be mutable

Check failure on line 225 in swarm-test/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (1.78.0)

unused variable: `config`

Check failure on line 225 in swarm-test/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (1.78.0)

variable does not need to be mutable

Check failure on line 225 in swarm-test/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (beta)

unused variable: `config`

Check failure on line 225 in swarm-test/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (beta)

variable does not need to be mutable

Check failure on line 225 in swarm-test/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test libp2p-swarm-test

unused variable: `config`

Check failure on line 225 in swarm-test/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test libp2p-swarm-test

variable does not need to be mutable

#[cfg(feature = "tokio")]
let mut config = swarm::Config::with_tokio_executor();

// Some tests need connections to be kept alive beyond what the individual behaviour configures.
config = config.with_idle_connection_timeout(Duration::from_secs(5));

Swarm::new(transport, behaviour_fn(identity), peer_id, config)
}

async fn connect<T>(&mut self, other: &mut Swarm<T>)
Expand Down
Loading