1use crate::socket::SocketEndpoint;
2use futures::channel::mpsc::SendError;
3use futures::channel::oneshot::Canceled;
4use std::net::{AddrParseError, IpAddr};
5
6#[derive(thiserror::Error, Debug, PartialEq, Eq)]
7pub enum Error {
8 #[error("Invalid IP address: {0}")]
9 IpAddr(#[from] AddrParseError),
10 #[error("IP address not allowed: {0}")]
11 IpAddrNotAllowed(IpAddr),
12 #[error("IP address is malformed: {0}")]
13 IpAddrMalformed(String),
14 #[error("IP address is taken: {0}")]
15 IpAddrTaken(IpAddr),
16 #[error("Invalid network IP address: {0}")]
17 NetAddr(String),
18 #[error("Network IP address taken: {0}")]
19 NetAddrTaken(IpAddr),
20 #[error("Network not found for IP address: {0}")]
21 NetAddrMismatch(IpAddr),
22 #[error("Network is empty")]
23 NetEmpty,
24 #[error("Network not found")]
25 NetNotFound,
26 #[error("Invalid network CIDR: {0}/{1}")]
27 NetCidr(IpAddr, u8),
28 #[error("Network ID taken: {0}")]
29 NetIdTaken(String),
30 #[error("Invalid gateway address: {0}")]
31 GatewayMismatch(IpAddr),
32 #[error("Packet malformed: {0}")]
33 PacketMalformed(String),
34 #[error("Protocol not supported: {0}")]
35 ProtocolNotSupported(String),
36 #[error("Unknown protocol")]
37 ProtocolUnknown,
38 #[error("Endpoint taken: {0:?}")]
39 EndpointTaken(SocketEndpoint),
40 #[error("Invalid endpoint: {0:?}")]
41 EndpointInvalid(SocketEndpoint),
42 #[error("Socket closed")]
43 SocketClosed,
44 #[error("Connection error: {0}")]
45 ConnectionError(String),
46 #[error("Connection timed out")]
47 ConnectionTimeout,
48 #[error("Forbidden")]
49 Forbidden,
50 #[error("Cancelled")]
51 Cancelled,
52
53 #[error("{0}")]
54 Other(String),
55}
56
57impl From<Canceled> for Error {
58 fn from(_: Canceled) -> Self {
59 Self::Cancelled
60 }
61}
62
63impl From<SendError> for Error {
64 fn from(_: SendError) -> Self {
65 Self::Cancelled
66 }
67}