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(ping): don't close connections upon failures #3947

Merged
merged 26 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6481aa8
Handle unreachable case explicitly
thomaseizinger May 15, 2023
a1d9a53
ReadyUpgrade cannot time out
thomaseizinger May 15, 2023
dcb2256
Directly map error to `Failure::Other`
thomaseizinger May 15, 2023
61f4b1c
fixup! ReadyUpgrade cannot time out
thomaseizinger May 15, 2023
6840638
Embed timeout in `send_ping`
thomaseizinger May 15, 2023
da502da
Exhaustively match
thomaseizinger May 15, 2023
3e9d527
fixup! Embed timeout in `send_ping`
thomaseizinger May 15, 2023
6ea4e75
Remove `Result` type alias
thomaseizinger May 15, 2023
ceb7121
Remove unnecessary path prefixes
thomaseizinger May 15, 2023
ceb9899
Move logging to handler
thomaseizinger May 15, 2023
c854561
Remove `Pong` event
thomaseizinger May 15, 2023
3240725
Don't close connection
thomaseizinger May 15, 2023
458b35a
Apply suggestions from code review
thomaseizinger May 15, 2023
f0b230c
Merge branch 'master' into feat/no-close-connection-ping-failures
thomaseizinger May 16, 2023
45605b0
Merge branch 'feat/no-close-connection-ping-failures' of github.com:l…
thomaseizinger May 16, 2023
b6540fe
Merge branch 'master' into feat/no-close-connection-ping-failures
thomaseizinger May 17, 2023
60f250e
Merge branch 'master' into feat/no-close-connection-ping-failures
thomaseizinger May 23, 2023
2a910fa
Add `Swarm::close_connection` API
thomaseizinger May 23, 2023
772c891
Expose connection ID on event
thomaseizinger May 23, 2023
ea7c01c
Update protocols/ping/CHANGELOG.md
thomaseizinger May 23, 2023
c1fe6a1
Document health check / connection management with ping
thomaseizinger May 23, 2023
6e12acf
Merge branch 'feat/no-close-connection-ping-failures' of github.com:l…
thomaseizinger May 23, 2023
ad6a882
Fix compile errors
thomaseizinger May 24, 2023
9c4a656
Tidy up docs
thomaseizinger May 24, 2023
5c79d30
Fix typo
thomaseizinger May 24, 2023
198d164
Merge branch 'master' into feat/no-close-connection-ping-failures
mergify[bot] May 24, 2023
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
8 changes: 1 addition & 7 deletions examples/ipfs-private/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,20 +249,14 @@ async fn main() -> Result<(), Box<dyn Error>> {
match event {
ping::Event {
peer,
result: Result::Ok(ping::Success::Ping { rtt }),
result: Result::Ok(rtt),
} => {
println!(
"ping: rtt to {} is {} ms",
peer.to_base58(),
rtt.as_millis()
);
}
ping::Event {
peer,
result: Result::Ok(ping::Success::Pong),
} => {
println!("ping: pong from {}", peer.to_base58());
}
ping::Event {
peer,
result: Result::Err(ping::Failure::Timeout),
Expand Down
2 changes: 1 addition & 1 deletion examples/rendezvous/src/bin/rzv-discover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async fn main() {
}
SwarmEvent::Behaviour(MyBehaviourEvent::Ping(ping::Event {
peer,
result: Ok(ping::Success::Ping { rtt }),
result: Ok(rtt),
})) if peer != rendezvous_point => {
log::info!("Ping to {} is {}ms", peer, rtt.as_millis())
}
Expand Down
2 changes: 1 addition & 1 deletion examples/rendezvous/src/bin/rzv-identify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ async fn main() {
}
SwarmEvent::Behaviour(MyBehaviourEvent::Ping(ping::Event {
peer,
result: Ok(ping::Success::Ping { rtt }),
result: Ok(rtt),
})) if peer != rendezvous_point => {
log::info!("Ping to {} is {}ms", peer, rtt.as_millis())
}
Expand Down
2 changes: 1 addition & 1 deletion examples/rendezvous/src/bin/rzv-register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ async fn main() {
}
SwarmEvent::Behaviour(MyBehaviourEvent::Ping(ping::Event {
peer,
result: Ok(ping::Success::Ping { rtt }),
result: Ok(rtt),
})) if peer != rendezvous_point => {
log::info!("Ping to {} is {}ms", peer, rtt.as_millis())
}
Expand Down
2 changes: 1 addition & 1 deletion interop-tests/src/bin/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ async fn main() -> Result<()> {
let rtt = loop {
if let Some(SwarmEvent::Behaviour(BehaviourEvent::Ping(ping::Event {
peer: _,
result: Ok(ping::Success::Ping { rtt }),
result: Ok(rtt),
}))) = swarm.next().await
{
log::info!("Ping successful: {rtt:?}");
Expand Down
2 changes: 2 additions & 0 deletions misc/metrics/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
- Raise MSRV to 1.65.
See [PR 3715].

- TODO: Removed `pong_received`.
thomaseizinger marked this conversation as resolved.
Show resolved Hide resolved

[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715
[PR 3325]: https://github.com/libp2p/rust-libp2p/pull/3325
thomaseizinger marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
19 changes: 2 additions & 17 deletions misc/metrics/src/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ enum Failure {
pub(crate) struct Metrics {
rtt: Histogram,
failure: Family<FailureLabels, Counter>,
pong_received: Counter,
}

impl Metrics {
Expand All @@ -77,28 +76,14 @@ impl Metrics {
failure.clone(),
);

let pong_received = Counter::default();
sub_registry.register(
"pong_received",
"Number of 'pong's received",
pong_received.clone(),
);

Self {
rtt,
failure,
pong_received,
}
Self { rtt, failure }
}
}

impl super::Recorder<libp2p_ping::Event> for Metrics {
fn record(&self, event: &libp2p_ping::Event) {
match &event.result {
Ok(libp2p_ping::Success::Pong) => {
self.pong_received.inc();
}
Ok(libp2p_ping::Success::Ping { rtt }) => {
Ok(rtt) => {
self.rtt.observe(rtt.as_secs_f64());
}
Err(failure) => {
Expand Down
6 changes: 6 additions & 0 deletions protocols/ping/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

- Raise MSRV to 1.65.
See [PR 3715].

- Remove deprecated items. See [PR 3702].

- Don't close connections on ping failures.
thomaseizinger marked this conversation as resolved.
Show resolved Hide resolved
This also removes the `max_failures` config option.
See [PR XXXX].

[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715
[PR 3702]: https://github.com/libp2p/rust-libp2p/pull/3702
[PR XXXX]: https://github.com/libp2p/rust-libp2p/pull/XXXX
thomaseizinger marked this conversation as resolved.
Show resolved Hide resolved

## 0.42.0

Expand Down
Loading