mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-28 09:11:34 +00:00
feat(ping): don't close connections upon failures
Previously, the `libp2p-ping` module came with a policy to close a connection after X failed pings. This is only one of many possible policies on how users would want to do connection management. We remove this policy without a replacement. If users wish to restore this functionality, they can easily implement such policy themselves: The default value of `max_failures` was 1. To restore the previous functionality users can simply close the connection upon the first received ping error. In this same patch, we also simplify the API of `ping::Event` by removing the layer of `ping::Success` and instead reporting the RTT to the peer directly. Related: #3591. Pull-Request: #3947.
This commit is contained in:
@ -55,7 +55,6 @@ enum Failure {
|
||||
pub(crate) struct Metrics {
|
||||
rtt: Histogram,
|
||||
failure: Family<FailureLabels, Counter>,
|
||||
pong_received: Counter,
|
||||
}
|
||||
|
||||
impl Metrics {
|
||||
@ -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) => {
|
||||
|
Reference in New Issue
Block a user