treat ConnectionError
same as io::Error
This commit is contained in:
parent
056f880a29
commit
e2a704408b
@ -11,8 +11,6 @@ pub enum Error {
|
|||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Connect(#[from] ConnectError),
|
Connect(#[from] ConnectError),
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Connection(#[from] ConnectionError),
|
|
||||||
#[error(transparent)]
|
|
||||||
Model(#[from] ModelError),
|
Model(#[from] ModelError),
|
||||||
#[error("load native certificates error: {0}")]
|
#[error("load native certificates error: {0}")]
|
||||||
LoadNativeCerts(IoError),
|
LoadNativeCerts(IoError),
|
||||||
@ -29,3 +27,9 @@ pub enum Error {
|
|||||||
#[error("invalid socks5 authentication")]
|
#[error("invalid socks5 authentication")]
|
||||||
InvalidSocks5Auth,
|
InvalidSocks5Auth,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<ConnectionError> for Error {
|
||||||
|
fn from(err: ConnectionError) -> Self {
|
||||||
|
Self::Io(IoError::from(err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -40,7 +40,7 @@ impl Connection {
|
|||||||
|
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
() = self.auth.clone() => {}
|
() = self.auth.clone() => {}
|
||||||
err = self.inner.closed() => return Err(Error::Connection(err)),
|
err = self.inner.closed() => return Err(Error::from(err)),
|
||||||
};
|
};
|
||||||
|
|
||||||
let same_pkt_src = matches!(task, Task::Packet(_))
|
let same_pkt_src = matches!(task, Task::Packet(_))
|
||||||
@ -101,7 +101,7 @@ impl Connection {
|
|||||||
|
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
() = self.auth.clone() => {}
|
() = self.auth.clone() => {}
|
||||||
err = self.inner.closed() => return Err(Error::Connection(err)),
|
err = self.inner.closed() => return Err(Error::from(err)),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(task)
|
Ok(task)
|
||||||
@ -135,7 +135,7 @@ impl Connection {
|
|||||||
|
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
() = self.auth.clone() => {}
|
() = self.auth.clone() => {}
|
||||||
err = self.inner.closed() => return Err(Error::Connection(err)),
|
err = self.inner.closed() => return Err(Error::from(err)),
|
||||||
};
|
};
|
||||||
|
|
||||||
let same_pkt_src = matches!(task, Task::Packet(_))
|
let same_pkt_src = matches!(task, Task::Packet(_))
|
||||||
|
@ -103,7 +103,7 @@ impl Connection {
|
|||||||
|
|
||||||
match handle_incoming.await {
|
match handle_incoming.await {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
Err(err) if err.is_locally_closed() || err.is_timeout_closed() => {
|
Err(err) if err.is_trivial() => {
|
||||||
log::debug!(
|
log::debug!(
|
||||||
"[{id:#010x}] [{addr}] [{user}] {err}",
|
"[{id:#010x}] [{addr}] [{user}] {err}",
|
||||||
id = conn.id(),
|
id = conn.id(),
|
||||||
@ -118,13 +118,16 @@ impl Connection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) if err.is_locally_closed() || err.is_timeout_closed() => {
|
Err(err) if err.is_trivial() => {
|
||||||
log::debug!("[{id:#010x}] [{addr}] [unauthenticated] {err}", id = 0);
|
log::debug!(
|
||||||
|
"[{id:#010x}] [{addr}] [unauthenticated] {err}",
|
||||||
|
id = u32::MAX,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log::warn!(
|
log::warn!(
|
||||||
"[{id:#010x}] [{addr}] [unauthenticated] connection establishing error: {err}",
|
"[{id:#010x}] [{addr}] [unauthenticated] {err}",
|
||||||
id = usize::MAX,
|
id = u32::MAX,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,10 @@ pub enum Error {
|
|||||||
Rustls(#[from] RustlsError),
|
Rustls(#[from] RustlsError),
|
||||||
#[error("invalid max idle time")]
|
#[error("invalid max idle time")]
|
||||||
InvalidMaxIdleTime,
|
InvalidMaxIdleTime,
|
||||||
#[error(transparent)]
|
#[error("connection timed out")]
|
||||||
Connection(#[from] ConnectionError),
|
TimedOut,
|
||||||
|
#[error("connection locally closed")]
|
||||||
|
LocallyClosed,
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Model(#[from] ModelError),
|
Model(#[from] ModelError),
|
||||||
#[error("duplicated authentication")]
|
#[error("duplicated authentication")]
|
||||||
@ -34,11 +36,17 @@ pub enum Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Error {
|
impl Error {
|
||||||
pub fn is_locally_closed(&self) -> bool {
|
pub fn is_trivial(&self) -> bool {
|
||||||
matches!(self, Self::Connection(ConnectionError::LocallyClosed))
|
matches!(self, Self::TimedOut | Self::LocallyClosed)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
pub fn is_timeout_closed(&self) -> bool {
|
|
||||||
matches!(self, Self::Connection(ConnectionError::TimedOut))
|
impl From<ConnectionError> for Error {
|
||||||
|
fn from(err: ConnectionError) -> Self {
|
||||||
|
match err {
|
||||||
|
ConnectionError::TimedOut => Self::TimedOut,
|
||||||
|
ConnectionError::LocallyClosed => Self::LocallyClosed,
|
||||||
|
_ => Self::Io(IoError::from(err)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user