memberlist_core/delegate/ping.rs
1use std::{future::Future, sync::Arc};
2
3use bytes::Bytes;
4use nodecraft::{CheapClone, Id};
5
6use crate::proto::NodeState;
7
8/// Used to notify an observer how long it took for a ping message to
9/// complete a round trip. It can also be used for writing arbitrary byte slices
10/// into ack messages. Note that in order to be meaningful for RTT estimates, this
11/// delegate does not apply to indirect pings, nor fallback pings sent over promised connection.
12#[auto_impl::auto_impl(Box, Arc)]
13pub trait PingDelegate: Send + Sync + 'static {
14 /// The id type of the delegate
15 type Id: Id;
16
17 /// The address type of the delegate
18 type Address: CheapClone + Send + Sync + 'static;
19
20 /// Invoked when an ack is being sent; the returned bytes will be appended to the ack
21 fn ack_payload(&self) -> impl Future<Output = Bytes> + Send;
22
23 /// Invoked when an ack for a ping is received
24 fn notify_ping_complete(
25 &self,
26 node: Arc<NodeState<Self::Id, Self::Address>>,
27 rtt: std::time::Duration,
28 payload: Bytes,
29 ) -> impl Future<Output = ()> + Send;
30
31 /// Invoked when we want to send a ping message to target by promised connection.
32 /// Return true if the target node does not expect ping message from promised connection.
33 fn disable_reliable_pings(&self, _target: &Self::Id) -> bool {
34 false
35 }
36}