Skip to content
Merged
3 changes: 2 additions & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ libp2p-server = { version = "0.12.7", path = "misc/server" }
libp2p-stream = { version = "0.3.0-alpha.1", path = "protocols/stream" }
libp2p-swarm = { version = "0.47.0", path = "swarm" }
libp2p-swarm-derive = { version = "=0.35.1", path = "swarm-derive" } # `libp2p-swarm-derive` may not be compatible with different `libp2p-swarm` non-breaking releases. E.g. `libp2p-swarm` might introduce a new enum variant `FromSwarm` (which is `#[non-exhaustive]`) in a non-breaking release. Older versions of `libp2p-swarm-derive` would not forward this enum variant within the `NetworkBehaviour` hierarchy. Thus the version pinning is required.
libp2p-swarm-test = { version = "0.5.0", path = "swarm-test" }
libp2p-swarm-test = { version = "0.6.0", path = "swarm-test" }
libp2p-tcp = { version = "0.43.0", path = "transports/tcp" }
libp2p-tls = { version = "0.6.2", path = "transports/tls" }
libp2p-uds = { version = "0.42.0", path = "transports/uds" }
Expand Down
32 changes: 16 additions & 16 deletions misc/allow-block-list/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ mod tests {

#[tokio::test]
async fn cannot_dial_blocked_peer() {
let mut dialer = Swarm::new_ephemeral(|_| Behaviour::<BlockedPeers>::default());
let mut listener = Swarm::new_ephemeral(|_| Behaviour::<BlockedPeers>::default());
let mut dialer = Swarm::new_ephemeral_tokio(|_| Behaviour::<BlockedPeers>::default());
let mut listener = Swarm::new_ephemeral_tokio(|_| Behaviour::<BlockedPeers>::default());
listener.listen().with_memory_addr_external().await;

dialer.behaviour_mut().block_peer(*listener.local_peer_id());
Expand All @@ -319,8 +319,8 @@ mod tests {

#[tokio::test]
async fn can_dial_unblocked_peer() {
let mut dialer = Swarm::new_ephemeral(|_| Behaviour::<BlockedPeers>::default());
let mut listener = Swarm::new_ephemeral(|_| Behaviour::<BlockedPeers>::default());
let mut dialer = Swarm::new_ephemeral_tokio(|_| Behaviour::<BlockedPeers>::default());
let mut listener = Swarm::new_ephemeral_tokio(|_| Behaviour::<BlockedPeers>::default());
listener.listen().with_memory_addr_external().await;

dialer.behaviour_mut().block_peer(*listener.local_peer_id());
Expand All @@ -333,8 +333,8 @@ mod tests {

#[tokio::test]
async fn blocked_peer_cannot_dial_us() {
let mut dialer = Swarm::new_ephemeral(|_| Behaviour::<BlockedPeers>::default());
let mut listener = Swarm::new_ephemeral(|_| Behaviour::<BlockedPeers>::default());
let mut dialer = Swarm::new_ephemeral_tokio(|_| Behaviour::<BlockedPeers>::default());
let mut listener = Swarm::new_ephemeral_tokio(|_| Behaviour::<BlockedPeers>::default());
listener.listen().with_memory_addr_external().await;

listener.behaviour_mut().block_peer(*dialer.local_peer_id());
Expand All @@ -355,8 +355,8 @@ mod tests {

#[tokio::test]
async fn connections_get_closed_upon_blocked() {
let mut dialer = Swarm::new_ephemeral(|_| Behaviour::<BlockedPeers>::default());
let mut listener = Swarm::new_ephemeral(|_| Behaviour::<BlockedPeers>::default());
let mut dialer = Swarm::new_ephemeral_tokio(|_| Behaviour::<BlockedPeers>::default());
let mut listener = Swarm::new_ephemeral_tokio(|_| Behaviour::<BlockedPeers>::default());
listener.listen().with_memory_addr_external().await;
dialer.connect(&mut listener).await;

Expand All @@ -381,8 +381,8 @@ mod tests {

#[tokio::test]
async fn cannot_dial_peer_unless_allowed() {
let mut dialer = Swarm::new_ephemeral(|_| Behaviour::<AllowedPeers>::default());
let mut listener = Swarm::new_ephemeral(|_| Behaviour::<AllowedPeers>::default());
let mut dialer = Swarm::new_ephemeral_tokio(|_| Behaviour::<AllowedPeers>::default());
let mut listener = Swarm::new_ephemeral_tokio(|_| Behaviour::<AllowedPeers>::default());
listener.listen().with_memory_addr_external().await;

let DialError::Denied { cause } = dial(&mut dialer, &listener).unwrap_err() else {
Expand All @@ -396,8 +396,8 @@ mod tests {

#[tokio::test]
async fn cannot_dial_disallowed_peer() {
let mut dialer = Swarm::new_ephemeral(|_| Behaviour::<AllowedPeers>::default());
let mut listener = Swarm::new_ephemeral(|_| Behaviour::<AllowedPeers>::default());
let mut dialer = Swarm::new_ephemeral_tokio(|_| Behaviour::<AllowedPeers>::default());
let mut listener = Swarm::new_ephemeral_tokio(|_| Behaviour::<AllowedPeers>::default());
listener.listen().with_memory_addr_external().await;

dialer.behaviour_mut().allow_peer(*listener.local_peer_id());
Expand All @@ -413,8 +413,8 @@ mod tests {

#[tokio::test]
async fn not_allowed_peer_cannot_dial_us() {
let mut dialer = Swarm::new_ephemeral(|_| Behaviour::<AllowedPeers>::default());
let mut listener = Swarm::new_ephemeral(|_| Behaviour::<AllowedPeers>::default());
let mut dialer = Swarm::new_ephemeral_tokio(|_| Behaviour::<AllowedPeers>::default());
let mut listener = Swarm::new_ephemeral_tokio(|_| Behaviour::<AllowedPeers>::default());
listener.listen().with_memory_addr_external().await;

dialer
Expand Down Expand Up @@ -450,8 +450,8 @@ mod tests {

#[tokio::test]
async fn connections_get_closed_upon_disallow() {
let mut dialer = Swarm::new_ephemeral(|_| Behaviour::<AllowedPeers>::default());
let mut listener = Swarm::new_ephemeral(|_| Behaviour::<AllowedPeers>::default());
let mut dialer = Swarm::new_ephemeral_tokio(|_| Behaviour::<AllowedPeers>::default());
let mut listener = Swarm::new_ephemeral_tokio(|_| Behaviour::<AllowedPeers>::default());
listener.listen().with_memory_addr_external().await;
dialer.behaviour_mut().allow_peer(*listener.local_peer_id());
listener.behaviour_mut().allow_peer(*dialer.local_peer_id());
Expand Down
25 changes: 13 additions & 12 deletions misc/connection-limits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ mod tests {

let outgoing_limit = rand::thread_rng().gen_range(1..10);

let mut network = Swarm::new_ephemeral(|_| {
let mut network = Swarm::new_ephemeral_tokio(|_| {
Behaviour::new(
ConnectionLimits::default().with_max_pending_outgoing(Some(outgoing_limit)),
)
Expand All @@ -439,8 +439,8 @@ mod tests {
(network, addr, outgoing_limit)
}

#[test]
fn max_outgoing() {
#[tokio::test]
async fn max_outgoing() {
let (mut network, addr, outgoing_limit) = fill_outgoing();
match network
.dial(
Expand Down Expand Up @@ -469,8 +469,8 @@ mod tests {
);
}

#[test]
fn outgoing_limit_bypass() {
#[tokio::test]
async fn outgoing_limit_bypass() {
let (mut network, addr, _) = fill_outgoing();
let bypassed_peer = PeerId::random();
network
Expand Down Expand Up @@ -513,12 +513,12 @@ mod tests {
#[test]
fn max_established_incoming() {
fn prop(Limit(limit): Limit) {
let mut swarm1 = Swarm::new_ephemeral(|_| {
let mut swarm1 = Swarm::new_ephemeral_tokio(|_| {
Behaviour::new(
ConnectionLimits::default().with_max_established_incoming(Some(limit)),
)
});
let mut swarm2 = Swarm::new_ephemeral(|_| {
let mut swarm2 = Swarm::new_ephemeral_tokio(|_| {
Behaviour::new(
ConnectionLimits::default().with_max_established_incoming(Some(limit)),
)
Expand Down Expand Up @@ -556,17 +556,17 @@ mod tests {
#[test]
fn bypass_established_incoming() {
fn prop(Limit(limit): Limit) {
let mut swarm1 = Swarm::new_ephemeral(|_| {
let mut swarm1 = Swarm::new_ephemeral_tokio(|_| {
Behaviour::new(
ConnectionLimits::default().with_max_established_incoming(Some(limit)),
)
});
let mut swarm2 = Swarm::new_ephemeral(|_| {
let mut swarm2 = Swarm::new_ephemeral_tokio(|_| {
Behaviour::new(
ConnectionLimits::default().with_max_established_incoming(Some(limit)),
)
});
let mut swarm3 = Swarm::new_ephemeral(|_| {
let mut swarm3 = Swarm::new_ephemeral_tokio(|_| {
Behaviour::new(
ConnectionLimits::default().with_max_established_incoming(Some(limit)),
)
Expand Down Expand Up @@ -623,10 +623,11 @@ mod tests {
/// ([`SwarmEvent::ConnectionEstablished`]) can the connection be seen as established.
#[tokio::test]
async fn support_other_behaviour_denying_connection() {
let mut swarm1 = Swarm::new_ephemeral(|_| {
let mut swarm1 = Swarm::new_ephemeral_tokio(|_| {
Behaviour::new_with_connection_denier(ConnectionLimits::default())
});
let mut swarm2 = Swarm::new_ephemeral(|_| Behaviour::new(ConnectionLimits::default()));
let mut swarm2 =
Swarm::new_ephemeral_tokio(|_| Behaviour::new(ConnectionLimits::default()));

// Have swarm2 dial swarm1.
let (listen_addr, _) = swarm1.listen().await;
Expand Down
1 change: 1 addition & 0 deletions misc/memory-connection-limits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ sysinfo = "0.33"
tracing = { workspace = true }

[dev-dependencies]
tokio = { workspace = true, features = ["macros", "time"] }
libp2p-identify = { workspace = true }
libp2p-swarm-derive = { path = "../../swarm-derive" }
libp2p-swarm-test = { path = "../../swarm-test" }
Expand Down
11 changes: 6 additions & 5 deletions misc/memory-connection-limits/tests/max_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ use libp2p_swarm::{dial_opts::DialOpts, DialError, Swarm};
use libp2p_swarm_test::SwarmExt;
use util::*;

#[test]
fn max_bytes() {
#[tokio::test]
async fn max_bytes() {
const CONNECTION_LIMIT: usize = 20;
let max_allowed_bytes = CONNECTION_LIMIT * 1024 * 1024;

let mut network = Swarm::new_ephemeral(|_| TestBehaviour {
let mut network = Swarm::new_ephemeral_tokio(|_| TestBehaviour {
connection_limits: Behaviour::with_max_bytes(max_allowed_bytes),
mem_consumer: ConsumeMemoryBehaviour1MBPending0Established::default(),
});
Expand Down Expand Up @@ -69,8 +69,9 @@ fn max_bytes() {
.expect("Unexpected connection limit.");
}

std::thread::sleep(Duration::from_millis(100)); // Memory stats are only updated every 100ms internally, ensure they are up-to-date when we try
// to exceed it.
// Memory stats are only updated every 100ms internally,
// ensure they are up-to-date when we try to exceed it.
tokio::time::sleep(Duration::from_millis(100)).await;

match network
.dial(
Expand Down
8 changes: 4 additions & 4 deletions misc/memory-connection-limits/tests/max_percentage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ use libp2p_swarm_test::SwarmExt;
use sysinfo::{MemoryRefreshKind, RefreshKind};
use util::*;

#[test]
fn max_percentage() {
#[tokio::test]
async fn max_percentage() {
const CONNECTION_LIMIT: usize = 20;
let system_info = sysinfo::System::new_with_specifics(
RefreshKind::default().with_memory(MemoryRefreshKind::default().with_ram()),
);

let mut network = Swarm::new_ephemeral(|_| TestBehaviour {
let mut network = Swarm::new_ephemeral_tokio(|_| TestBehaviour {
connection_limits: Behaviour::with_max_percentage(0.1),
mem_consumer: ConsumeMemoryBehaviour1MBPending0Established::default(),
});
Expand Down Expand Up @@ -78,7 +78,7 @@ fn max_percentage() {

// Memory stats are only updated every 100ms internally,
// ensure they are up-to-date when we try to exceed it.
std::thread::sleep(Duration::from_millis(100));
tokio::time::sleep(Duration::from_millis(100)).await;

match network
.dial(
Expand Down
6 changes: 3 additions & 3 deletions protocols/autonat/tests/autonatv2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ async fn dial_back_to_not_supporting() {
}

async fn new_server() -> Swarm<CombinedServer> {
let mut node = Swarm::new_ephemeral(|identity| CombinedServer {
let mut node = Swarm::new_ephemeral_tokio(|identity| CombinedServer {
autonat: libp2p_autonat::v2::server::Behaviour::default(),
identify: libp2p_identify::Behaviour::new(libp2p_identify::Config::new(
"/libp2p-test/1.0.0".into(),
Expand All @@ -427,7 +427,7 @@ async fn new_server() -> Swarm<CombinedServer> {
}

async fn new_client() -> Swarm<CombinedClient> {
let mut node = Swarm::new_ephemeral(|identity| CombinedClient {
let mut node = Swarm::new_ephemeral_tokio(|identity| CombinedClient {
autonat: libp2p_autonat::v2::client::Behaviour::new(
OsRng,
Config::default().with_probe_interval(Duration::from_millis(100)),
Expand Down Expand Up @@ -456,7 +456,7 @@ struct CombinedClient {
}

async fn new_dummy() -> Swarm<libp2p_identify::Behaviour> {
let mut node = Swarm::new_ephemeral(|identity| {
let mut node = Swarm::new_ephemeral_tokio(|identity| {
libp2p_identify::Behaviour::new(libp2p_identify::Config::new(
"/libp2p-test/1.0.0".into(),
identity.public().clone(),
Expand Down
14 changes: 7 additions & 7 deletions protocols/autonat/tests/test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const TEST_REFRESH_INTERVAL: Duration = Duration::from_secs(2);

#[tokio::test]
async fn test_auto_probe() {
let mut client = Swarm::new_ephemeral(|key| {
let mut client = Swarm::new_ephemeral_tokio(|key| {
Behaviour::new(
key.public().to_peer_id(),
Config {
Expand Down Expand Up @@ -137,7 +137,7 @@ async fn test_auto_probe() {

#[tokio::test]
async fn test_confidence() {
let mut client = Swarm::new_ephemeral(|key| {
let mut client = Swarm::new_ephemeral_tokio(|key| {
Behaviour::new(
key.public().to_peer_id(),
Config {
Expand Down Expand Up @@ -221,7 +221,7 @@ async fn test_confidence() {

#[tokio::test]
async fn test_throttle_server_period() {
let mut client = Swarm::new_ephemeral(|key| {
let mut client = Swarm::new_ephemeral_tokio(|key| {
Behaviour::new(
key.public().to_peer_id(),
Config {
Expand Down Expand Up @@ -272,7 +272,7 @@ async fn test_throttle_server_period() {

#[tokio::test]
async fn test_use_connected_as_server() {
let mut client = Swarm::new_ephemeral(|key| {
let mut client = Swarm::new_ephemeral_tokio(|key| {
Behaviour::new(
key.public().to_peer_id(),
Config {
Expand Down Expand Up @@ -310,7 +310,7 @@ async fn test_use_connected_as_server() {

#[tokio::test]
async fn test_outbound_failure() {
let mut client = Swarm::new_ephemeral(|key| {
let mut client = Swarm::new_ephemeral_tokio(|key| {
Behaviour::new(
key.public().to_peer_id(),
Config {
Expand Down Expand Up @@ -379,7 +379,7 @@ async fn test_outbound_failure() {

#[tokio::test]
async fn test_global_ips_config() {
let mut client = Swarm::new_ephemeral(|key| {
let mut client = Swarm::new_ephemeral_tokio(|key| {
Behaviour::new(
key.public().to_peer_id(),
Config {
Expand Down Expand Up @@ -413,7 +413,7 @@ async fn test_global_ips_config() {
}

async fn new_server_swarm() -> (PeerId, Multiaddr, JoinHandle<()>) {
let mut swarm = Swarm::new_ephemeral(|key| {
let mut swarm = Swarm::new_ephemeral_tokio(|key| {
Behaviour::new(
key.public().to_peer_id(),
Config {
Expand Down
5 changes: 3 additions & 2 deletions protocols/autonat/tests/test_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,15 +359,16 @@ async fn new_server_swarm(config: Option<Config>) -> (Swarm<Behaviour>, PeerId,
// Don't do any outbound probes.
config.boot_delay = Duration::from_secs(60);

let mut server = Swarm::new_ephemeral(|key| Behaviour::new(key.public().to_peer_id(), config));
let mut server =
Swarm::new_ephemeral_tokio(|key| Behaviour::new(key.public().to_peer_id(), config));
let peer_id = *server.local_peer_id();
let (_, addr) = server.listen().await;

(server, peer_id, addr)
}

async fn new_client_swarm(server_id: PeerId, server_addr: Multiaddr) -> (Swarm<Behaviour>, PeerId) {
let mut client = Swarm::new_ephemeral(|key| {
let mut client = Swarm::new_ephemeral_tokio(|key| {
Behaviour::new(
key.public().to_peer_id(),
Config {
Expand Down
4 changes: 2 additions & 2 deletions protocols/dcutr/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ async fn connect() {
}

fn build_relay() -> Swarm<Relay> {
Swarm::new_ephemeral(|identity| {
Swarm::new_ephemeral_tokio(|identity| {
let local_peer_id = identity.public().to_peer_id();

Relay {
Expand Down Expand Up @@ -152,7 +152,7 @@ fn build_client() -> Swarm<Client> {
)),
},
local_peer_id,
Config::with_async_std_executor(),
Config::with_tokio_executor(),
)
}

Expand Down
2 changes: 1 addition & 1 deletion protocols/gossipsub/tests/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ async fn build_node() -> Swarm<gossipsub::Behaviour> {
// reduce the default values of the heartbeat, so that all nodes will receive gossip in a
// timely fashion.

let mut swarm = Swarm::new_ephemeral(|identity| {
let mut swarm = Swarm::new_ephemeral_tokio(|identity| {
let peer_id = identity.public().to_peer_id();

let config = gossipsub::ConfigBuilder::default()
Expand Down
Loading
Loading