Skip to content

Commit

Permalink
Address PR comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Ermolaev committed Nov 30, 2021
1 parent 6ab883c commit 1d4cf27
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
10 changes: 4 additions & 6 deletions protocols/mdns/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# 0.35.0 [unreleased]

- Fix generation of the peer expiration event, see [PR 2359]

[PR 2359]: https://github.com/libp2p/rust-libp2p/pull/2359

# 0.34.0 [unreleased]

- Update dependencies.
Expand All @@ -17,10 +11,14 @@

- Migrate to Rust edition 2021 (see [PR 2339]).

- Fix generation of peer expiration event and listen on specified IP version (see [PR 2359]).

[PR 2339]: https://github.com/libp2p/rust-libp2p/pull/2339

[PR 2311]: https://github.com/libp2p/rust-libp2p/pull/2311/

[PR 2359]: https://github.com/libp2p/rust-libp2p/pull/2359

# 0.33.0 [2021-11-16]

- Update dependencies.
Expand Down
2 changes: 1 addition & 1 deletion protocols/mdns/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ void = "1.0.2"
[dev-dependencies]
async-std = { version = "1.9.0", features = ["attributes"] }
libp2p = { path = "../.." }
tokio = { version = "1.2.0", default-features = false, features = ["macros", "rt", "rt-multi-thread"] }
tokio = { version = "1.2.0", default-features = false, features = ["macros", "rt", "rt-multi-thread", "time"] }
6 changes: 5 additions & 1 deletion protocols/mdns/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ pub struct MdnsConfig {
/// peer joins the network. Receiving an mdns packet resets the timer
/// preventing unnecessary traffic.
pub query_interval: Duration,
/// IP address for multicast.
/// Internet protocol version (v4 or v6) to use.
///
/// Note that the provided IP address itself is ignored and instead the
/// unspecified address (`0.0.0.0` or `::`) of the corresponding version is
/// used.
pub multicast_addr: IpAddr,
}

Expand Down
25 changes: 18 additions & 7 deletions protocols/mdns/tests/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ async fn test_expired_async_std_ipv4() -> Result<(), Box<dyn Error>> {
};

run_timebound_test(
TestRuntime::StdAsync,
run_peer_expiration_test(config),
Duration::from_secs(6)
).await
Expand All @@ -156,6 +157,7 @@ async fn test_expired_async_std_ipv6() -> Result<(), Box<dyn Error>> {
};

run_timebound_test(
TestRuntime::StdAsync,
run_peer_expiration_test(config),
Duration::from_secs(6)
).await
Expand All @@ -170,6 +172,7 @@ async fn test_expired_tokio_ipv4() -> Result<(), Box<dyn Error>> {
};

run_timebound_test(
TestRuntime::Tokio,
run_peer_expiration_test(config),
Duration::from_secs(6)
).await
Expand All @@ -184,17 +187,25 @@ async fn test_expired_tokio_ipv6() -> Result<(), Box<dyn Error>> {
};

run_timebound_test(
TestRuntime::Tokio,
run_peer_expiration_test(config),
Duration::from_secs(6)
).await
}

async fn run_timebound_test(fut: impl Future<Output=Result<(), Box<dyn Error>>>, bound: Duration) -> Result<(), Box<dyn Error>> {
let result = async_std::future::timeout(bound, fut)
.await;
async fn run_timebound_test(runtime: TestRuntime, fut: impl Future<Output=Result<(), Box<dyn Error>>>, bound: Duration) -> Result<(), Box<dyn Error>> {
match runtime {
TestRuntime::Tokio => tokio::time::timeout(bound, fut)
.await
.map_err(|e| Box::new(e) as Box<dyn Error>),
TestRuntime::StdAsync => async_std::future::timeout(bound, fut)
.await
.map_err(|e| Box::new(e) as Box<dyn Error>),
}.map(|_| ())

match result {
Ok(res) => res,
Err(err) => Err::<(), Box<dyn Error>>(Box::new(err))
}
}

enum TestRuntime {
Tokio,
StdAsync,
}

0 comments on commit 1d4cf27

Please sign in to comment.