mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-13 01:51:23 +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:
@ -249,7 +249,8 @@ 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",
|
||||
@ -257,27 +258,24 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
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),
|
||||
..
|
||||
} => {
|
||||
println!("ping: timeout to {}", peer.to_base58());
|
||||
}
|
||||
ping::Event {
|
||||
peer,
|
||||
result: Result::Err(ping::Failure::Unsupported),
|
||||
..
|
||||
} => {
|
||||
println!("ping: {} does not support ping protocol", peer.to_base58());
|
||||
}
|
||||
ping::Event {
|
||||
peer,
|
||||
result: Result::Err(ping::Failure::Other { error }),
|
||||
..
|
||||
} => {
|
||||
println!("ping: ping::Failure with {}: {error}", peer.to_base58());
|
||||
}
|
||||
|
Reference in New Issue
Block a user