mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-16 11:31:22 +00:00
protocols/ping: Properly deprecate types with Ping
prefix (#2937)
Co-authored-by: Elena Frank <elena.frank@protonmail.com> Co-authored-by: João Oliveira <hello@jxs.pt>
This commit is contained in:
@ -56,7 +56,7 @@ pub struct Config {
|
||||
}
|
||||
|
||||
impl Config {
|
||||
/// Creates a new `PingConfig` with the following default settings:
|
||||
/// Creates a new [`Config`] with the following default settings:
|
||||
///
|
||||
/// * [`Config::with_interval`] 15s
|
||||
/// * [`Config::with_timeout`] 20s
|
||||
@ -185,7 +185,7 @@ pub struct Handler {
|
||||
/// Each successful ping resets this counter to 0.
|
||||
failures: u32,
|
||||
/// The outbound ping state.
|
||||
outbound: Option<PingState>,
|
||||
outbound: Option<OutboundState>,
|
||||
/// The inbound pong handler, i.e. if there is an inbound
|
||||
/// substream, this is always a future that waits for the
|
||||
/// next inbound ping to be answered.
|
||||
@ -208,7 +208,7 @@ enum State {
|
||||
}
|
||||
|
||||
impl Handler {
|
||||
/// Builds a new `PingHandler` with the given configuration.
|
||||
/// Builds a new [`Handler`] with the given configuration.
|
||||
pub fn new(config: Config) -> Self {
|
||||
Handler {
|
||||
config,
|
||||
@ -241,7 +241,7 @@ impl ConnectionHandler for Handler {
|
||||
|
||||
fn inject_fully_negotiated_outbound(&mut self, stream: NegotiatedSubstream, (): ()) {
|
||||
self.timer.reset(self.config.timeout);
|
||||
self.outbound = Some(PingState::Ping(protocol::send_ping(stream).boxed()));
|
||||
self.outbound = Some(OutboundState::Ping(protocol::send_ping(stream).boxed()));
|
||||
}
|
||||
|
||||
fn inject_event(&mut self, _: Void) {}
|
||||
@ -330,19 +330,19 @@ impl ConnectionHandler for Handler {
|
||||
|
||||
// Continue outbound pings.
|
||||
match self.outbound.take() {
|
||||
Some(PingState::Ping(mut ping)) => match ping.poll_unpin(cx) {
|
||||
Some(OutboundState::Ping(mut ping)) => match ping.poll_unpin(cx) {
|
||||
Poll::Pending => {
|
||||
if self.timer.poll_unpin(cx).is_ready() {
|
||||
self.pending_errors.push_front(Failure::Timeout);
|
||||
} else {
|
||||
self.outbound = Some(PingState::Ping(ping));
|
||||
self.outbound = Some(OutboundState::Ping(ping));
|
||||
break;
|
||||
}
|
||||
}
|
||||
Poll::Ready(Ok((stream, rtt))) => {
|
||||
self.failures = 0;
|
||||
self.timer.reset(self.config.interval);
|
||||
self.outbound = Some(PingState::Idle(stream));
|
||||
self.outbound = Some(OutboundState::Idle(stream));
|
||||
return Poll::Ready(ConnectionHandlerEvent::Custom(Ok(Success::Ping {
|
||||
rtt,
|
||||
})));
|
||||
@ -352,22 +352,23 @@ impl ConnectionHandler for Handler {
|
||||
.push_front(Failure::Other { error: Box::new(e) });
|
||||
}
|
||||
},
|
||||
Some(PingState::Idle(stream)) => match self.timer.poll_unpin(cx) {
|
||||
Some(OutboundState::Idle(stream)) => match self.timer.poll_unpin(cx) {
|
||||
Poll::Pending => {
|
||||
self.outbound = Some(PingState::Idle(stream));
|
||||
self.outbound = Some(OutboundState::Idle(stream));
|
||||
break;
|
||||
}
|
||||
Poll::Ready(()) => {
|
||||
self.timer.reset(self.config.timeout);
|
||||
self.outbound = Some(PingState::Ping(protocol::send_ping(stream).boxed()));
|
||||
self.outbound =
|
||||
Some(OutboundState::Ping(protocol::send_ping(stream).boxed()));
|
||||
}
|
||||
},
|
||||
Some(PingState::OpenStream) => {
|
||||
self.outbound = Some(PingState::OpenStream);
|
||||
Some(OutboundState::OpenStream) => {
|
||||
self.outbound = Some(OutboundState::OpenStream);
|
||||
break;
|
||||
}
|
||||
None => {
|
||||
self.outbound = Some(PingState::OpenStream);
|
||||
self.outbound = Some(OutboundState::OpenStream);
|
||||
let protocol = SubstreamProtocol::new(ReadyUpgrade::new(PROTOCOL_NAME), ())
|
||||
.with_timeout(self.config.timeout);
|
||||
return Poll::Ready(ConnectionHandlerEvent::OutboundSubstreamRequest {
|
||||
@ -385,7 +386,7 @@ type PingFuture = BoxFuture<'static, Result<(NegotiatedSubstream, Duration), io:
|
||||
type PongFuture = BoxFuture<'static, Result<NegotiatedSubstream, io::Error>>;
|
||||
|
||||
/// The current state w.r.t. outbound pings.
|
||||
enum PingState {
|
||||
enum OutboundState {
|
||||
/// A new substream is being negotiated for the ping protocol.
|
||||
OpenStream,
|
||||
/// The substream is idle, waiting to send the next ping.
|
||||
|
Reference in New Issue
Block a user