1pub mod inbound;
2pub mod outbound;
3mod protocol;
4
5use std::time::Duration;
6
7use volans_core::PeerId;
8use volans_swarm::ConnectionId;
9
10#[derive(Debug, Clone)]
11pub struct Config {
12 timeout: Duration,
13 interval: Duration,
14 failures: u32,
15}
16
17impl Default for Config {
18 fn default() -> Self {
19 Self {
20 timeout: Duration::from_secs(1),
21 interval: Duration::from_secs(10),
22 failures: 3,
23 }
24 }
25}
26
27#[derive(Debug, thiserror::Error)]
28pub enum Failure {
29 #[error("Ping timeout")]
30 Timeout,
31 #[error("Ping protocol not supported")]
32 Unsupported,
33 #[error("Ping protocol error: {error}")]
34 Other {
35 error: Box<dyn std::error::Error + Send + Sync + 'static>,
36 },
37}
38
39impl Failure {
40 fn other(e: impl std::error::Error + Send + Sync + 'static) -> Self {
41 Self::Other { error: Box::new(e) }
42 }
43}
44
45#[derive(Debug)]
46pub struct Event {
47 pub connection: ConnectionId,
48 pub peer_id: PeerId,
49 pub result: Result<Duration, Failure>,
50}