1use super::*;
2
3#[derive(thiserror::Error)]
5pub enum QuicTransportError<A: AddressResolver> {
6 #[error("no private IP address found, and explicit IP not provided")]
8 NoPrivateIP,
9 #[error("at least one bind address is required")]
11 EmptyBindAddresses,
12 #[error("the ip {0} is blocked")]
14 BlockedIp(IpAddr),
15 #[error("failed to start listener on {0}: {1}")]
17 Listen(SocketAddr, std::io::Error),
18 #[error("failed to create resolver: {0}")]
20 Resolver(A::Error),
21 #[error("failed to resolve address {addr}: {err}")]
23 Resolve {
24 addr: A::Address,
26 err: A::Error,
28 },
29 #[error(transparent)]
31 Io(#[from] std::io::Error),
32 #[error("packet too large, the maximum packet can be sent is 65535, got {0}")]
34 PacketTooLarge(usize),
35 #[error("{0}")]
37 Custom(std::borrow::Cow<'static, str>),
38}
39
40impl<A: AddressResolver> core::fmt::Debug for QuicTransportError<A> {
41 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42 core::fmt::Display::fmt(&self, f)
43 }
44}
45
46impl<A> TransportError for QuicTransportError<A>
47where
48 A: AddressResolver,
49 A::Address: Send + Sync + 'static,
50{
51 fn is_remote_failure(&self) -> bool {
52 use std::io::ErrorKind;
53
54 match &self {
55 Self::Io(e) => matches!(
56 e.kind(),
57 ErrorKind::ConnectionRefused
58 | ErrorKind::ConnectionReset
59 | ErrorKind::ConnectionAborted
60 | ErrorKind::BrokenPipe
61 | ErrorKind::TimedOut
62 | ErrorKind::NotConnected
63 ),
64 _ => false,
65 }
66 }
67
68 fn custom(err: std::borrow::Cow<'static, str>) -> Self {
69 Self::Custom(err)
70 }
71}