1use std::net::IpAddr;
4use thiserror::Error;
5
6#[derive(Debug, Error)]
8pub enum OverlayError {
9 #[error("Overlay transport not available: {0}")]
11 TransportNotAvailable(String),
12
13 #[error("Transport command failed: {0}")]
15 TransportCommand(String),
16
17 #[error("Boringtun device error: {0}")]
19 BoringtunDevice(String),
20
21 #[error("Invalid CIDR notation: {0}")]
23 InvalidCidr(String),
24
25 #[error("No available IP addresses in CIDR range")]
27 NoAvailableIps,
28
29 #[error("IP address {0} is already allocated")]
31 IpAlreadyAllocated(IpAddr),
32
33 #[error("IP address {0} is not within CIDR range {1}")]
35 IpNotInRange(IpAddr, String),
36
37 #[error("Overlay interface '{0}' already exists")]
39 InterfaceExists(String),
40
41 #[error("Overlay interface '{0}' not found")]
43 InterfaceNotFound(String),
44
45 #[error("Peer with public key '{0}' not found")]
47 PeerNotFound(String),
48
49 #[error("Peer at {ip} is unreachable: {reason}")]
51 PeerUnreachable { ip: IpAddr, reason: String },
52
53 #[error("Configuration error: {0}")]
55 Config(String),
56
57 #[error("IO error: {0}")]
59 Io(#[from] std::io::Error),
60
61 #[error("JSON error: {0}")]
63 Json(#[from] serde_json::Error),
64
65 #[error("Overlay network already initialized at {0}")]
67 AlreadyInitialized(String),
68
69 #[error("Overlay network not initialized. Run init_leader or join first")]
71 NotInitialized,
72
73 #[error("Permission denied: {0}. This operation typically requires root privileges")]
75 PermissionDenied(String),
76
77 #[error("Operation timed out: {0}")]
79 Timeout(String),
80
81 #[error("Invalid key format: {0}")]
83 InvalidKey(String),
84
85 #[error("Network configuration error: {0}")]
87 NetworkConfig(String),
88
89 #[error("DNS error: {0}")]
91 Dns(String),
92
93 #[error("STUN discovery failed: {0}")]
95 StunDiscovery(String),
96
97 #[error("Hole punch failed for peer {peer}: {reason}")]
99 HolePunchFailed { peer: String, reason: String },
100
101 #[error("TURN relay error: {0}")]
103 TurnRelay(String),
104
105 #[error("NAT traversal failed for peer {peer}: exhausted all candidates")]
107 NatTraversalFailed { peer: String },
108
109 #[error("No STUN servers configured")]
111 NoStunServers,
112}
113
114pub type Result<T> = std::result::Result<T, OverlayError>;