mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-30 18:21:33 +00:00
Produce an error if a node is unresponsive (#814)
This commit is contained in:
@ -38,7 +38,7 @@ use void::{Void, unreachable};
|
|||||||
|
|
||||||
/// Protocol handler that handles pinging the remote at a regular period.
|
/// Protocol handler that handles pinging the remote at a regular period.
|
||||||
///
|
///
|
||||||
/// If the remote doesn't respond, produces `Unresponsive` and closes the connection.
|
/// If the remote doesn't respond, produces an error that closes the connection.
|
||||||
pub struct PeriodicPingHandler<TSubstream> {
|
pub struct PeriodicPingHandler<TSubstream> {
|
||||||
/// Configuration for the ping protocol.
|
/// Configuration for the ping protocol.
|
||||||
ping_config: Ping<Instant>,
|
ping_config: Ping<Instant>,
|
||||||
@ -113,9 +113,6 @@ enum OutState<TSubstream> {
|
|||||||
/// Event produced by the periodic pinger.
|
/// Event produced by the periodic pinger.
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub enum OutEvent {
|
pub enum OutEvent {
|
||||||
/// The node has been determined to be unresponsive.
|
|
||||||
Unresponsive,
|
|
||||||
|
|
||||||
/// Started pinging the remote. This can be used to print a diagnostic message in the logs.
|
/// Started pinging the remote. This can be used to print a diagnostic message in the logs.
|
||||||
PingStart,
|
PingStart,
|
||||||
|
|
||||||
@ -262,8 +259,7 @@ where
|
|||||||
},
|
},
|
||||||
Ready => {
|
Ready => {
|
||||||
self.out_state = OutState::Shutdown;
|
self.out_state = OutState::Shutdown;
|
||||||
let ev = OutEvent::Unresponsive;
|
Err(io::Error::new(io::ErrorKind::Other, "unresponsive node"))
|
||||||
Ok(Async::Ready(ProtocolsHandlerEvent::Custom(ev)))
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
@ -297,8 +293,7 @@ where
|
|||||||
},
|
},
|
||||||
Ready => {
|
Ready => {
|
||||||
self.out_state = OutState::Shutdown;
|
self.out_state = OutState::Shutdown;
|
||||||
let ev = OutEvent::Unresponsive;
|
Err(io::Error::new(io::ErrorKind::Other, "unresponsive node"))
|
||||||
Ok(Async::Ready(ProtocolsHandlerEvent::Custom(ev)))
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user