mirror of
https://github.com/shadowsocks/shadowsocks-rust.git
synced 2026-10-28 10:15:08 +08:00
chore: fix clippy 1.95 lints (io_other_error, collapsible_match, large_enum_variant)
This commit is contained in:
1 parent
dc43297211
commit
e697eb292b
5 files changed
+32
-40
No files matched your search
@@ -1338,30 +1338,24 @@ impl LocalConfig {
|
||||
|
||||
match self.protocol {
|
||||
#[cfg(feature = "local-dns")]
|
||||
ProtocolType::Dns => {
|
||||
if self.local_dns_addr.is_none() || self.remote_dns_addr.is_none() {
|
||||
let err = Error::new(
|
||||
ErrorKind::MissingField,
|
||||
"missing `local_dns_addr` or `remote_dns_addr` in configuration",
|
||||
None,
|
||||
);
|
||||
return Err(err);
|
||||
}
|
||||
ProtocolType::Dns if self.local_dns_addr.is_none() || self.remote_dns_addr.is_none() => {
|
||||
let err = Error::new(
|
||||
ErrorKind::MissingField,
|
||||
"missing `local_dns_addr` or `remote_dns_addr` in configuration",
|
||||
None,
|
||||
);
|
||||
return Err(err);
|
||||
}
|
||||
#[cfg(feature = "local-tunnel")]
|
||||
ProtocolType::Tunnel => {
|
||||
if self.forward_addr.is_none() {
|
||||
let err = Error::new(ErrorKind::MissingField, "missing `forward_addr` in configuration", None);
|
||||
return Err(err);
|
||||
}
|
||||
ProtocolType::Tunnel if self.forward_addr.is_none() => {
|
||||
let err = Error::new(ErrorKind::MissingField, "missing `forward_addr` in configuration", None);
|
||||
return Err(err);
|
||||
}
|
||||
|
||||
#[cfg(feature = "local-http")]
|
||||
ProtocolType::Http => {
|
||||
if !self.mode.enable_tcp() {
|
||||
let err = Error::new(ErrorKind::Invalid, "TCP mode have to be enabled for http", None);
|
||||
return Err(err);
|
||||
}
|
||||
ProtocolType::Http if !self.mode.enable_tcp() => {
|
||||
let err = Error::new(ErrorKind::Invalid, "TCP mode have to be enabled for http", None);
|
||||
return Err(err);
|
||||
}
|
||||
|
||||
_ => {}
|
||||
|
||||
@@ -76,7 +76,7 @@ impl DnsResolver {
|
||||
{
|
||||
Ok(msg) => return Ok(msg),
|
||||
Err(err) => {
|
||||
last_err = io::Error::new(io::ErrorKind::Other, err);
|
||||
last_err = io::Error::other(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,7 +85,7 @@ impl DnsResolver {
|
||||
match self.client_cache.lookup_local(ns, msg, &self.connect_opts, false).await {
|
||||
Ok(msg) => return Ok(msg),
|
||||
Err(err) => {
|
||||
last_err = io::Error::new(io::ErrorKind::Other, err);
|
||||
last_err = io::Error::other(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -98,7 +98,7 @@ impl DnsResolver {
|
||||
.client_cache
|
||||
.lookup_unix_stream(path, msg)
|
||||
.await
|
||||
.map_err(|err| io::Error::new(io::ErrorKind::Other, err)),
|
||||
.map_err(io::Error::other),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -321,7 +321,7 @@ impl DnsTcpServer {
|
||||
Ok(m) => m,
|
||||
Err(err) => {
|
||||
error!("dns tcp {} parse message failed, error: {}", peer_addr, err);
|
||||
return Err(io::Error::new(io::ErrorKind::Other, err));
|
||||
return Err(io::Error::other(err));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -329,13 +329,13 @@ impl DnsTcpServer {
|
||||
Ok(m) => m,
|
||||
Err(err) => {
|
||||
error!("dns tcp {} lookup error: {}", peer_addr, err);
|
||||
return Err(io::Error::new(io::ErrorKind::Other, err));
|
||||
return Err(io::Error::other(err));
|
||||
}
|
||||
};
|
||||
|
||||
let mut buf = match respond_message.to_vec() {
|
||||
Ok(buf) => buf,
|
||||
Err(err) => return Err(io::Error::new(io::ErrorKind::Other, err)),
|
||||
Err(err) => return Err(io::Error::other(err)),
|
||||
};
|
||||
let length = buf.len();
|
||||
buf.resize(length + 2, 0);
|
||||
@@ -485,7 +485,7 @@ impl DnsUdpServer {
|
||||
|
||||
let buf = match respond_message.to_vec() {
|
||||
Ok(buf) => buf,
|
||||
Err(err) => return Err(io::Error::new(io::ErrorKind::Other, err)),
|
||||
Err(err) => return Err(io::Error::other(err)),
|
||||
};
|
||||
listener.send_to(&buf, peer_addr).await?;
|
||||
|
||||
@@ -877,14 +877,14 @@ impl DnsClient {
|
||||
self.client_cache
|
||||
.lookup_remote(&self.context, server.server_config(), remote_addr, message, false)
|
||||
.await
|
||||
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))
|
||||
.map_err(io::Error::other)
|
||||
}
|
||||
Mode::UdpOnly => {
|
||||
let server = self.balancer.best_udp_server();
|
||||
self.client_cache
|
||||
.lookup_remote(&self.context, server.server_config(), remote_addr, message, true)
|
||||
.await
|
||||
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))
|
||||
.map_err(io::Error::other)
|
||||
}
|
||||
Mode::TcpAndUdp => {
|
||||
// Query TCP & UDP simultaneously
|
||||
@@ -916,11 +916,11 @@ impl DnsClient {
|
||||
match future::select(tcp_fut, udp_fut).await {
|
||||
Either::Left((res, next)) => match res {
|
||||
Ok(o) => Ok(o),
|
||||
Err(..) => next.await.map_err(|err| io::Error::new(io::ErrorKind::Other, err)),
|
||||
Err(..) => next.await.map_err(io::Error::other),
|
||||
},
|
||||
Either::Right((res, next)) => match res {
|
||||
Ok(o) => Ok(o),
|
||||
Err(..) => next.await.map_err(|err| io::Error::new(io::ErrorKind::Other, err)),
|
||||
Err(..) => next.await.map_err(io::Error::other),
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -968,13 +968,9 @@ impl DnsClient {
|
||||
|
||||
match future::select(udp_query, tcp_query).await {
|
||||
Either::Left((Ok(m), ..)) => Ok(m),
|
||||
Either::Left((Err(..), next)) => {
|
||||
next.await.map_err(|err| io::Error::new(io::ErrorKind::Other, err))
|
||||
}
|
||||
Either::Left((Err(..), next)) => next.await.map_err(io::Error::other),
|
||||
Either::Right((Ok(m), ..)) => Ok(m),
|
||||
Either::Right((Err(..), next)) => {
|
||||
next.await.map_err(|err| io::Error::new(io::ErrorKind::Other, err))
|
||||
}
|
||||
Either::Right((Err(..), next)) => next.await.map_err(io::Error::other),
|
||||
}
|
||||
}
|
||||
#[cfg(unix)]
|
||||
@@ -982,7 +978,7 @@ impl DnsClient {
|
||||
.client_cache
|
||||
.lookup_unix_stream(path, message)
|
||||
.await
|
||||
.map_err(|err| io::Error::new(io::ErrorKind::Other, err)),
|
||||
.map_err(io::Error::other),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,8 @@ impl<'a> TcpDialer for ServerTcpDialer<'a> {
|
||||
}
|
||||
|
||||
/// Unified outbound stream: either direct or through the outbound proxy chain.
|
||||
// Not boxed: one instance per connection, boxing would add an allocation on the hot path
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
enum RemoteStream {
|
||||
Direct(OutboundTcpStream),
|
||||
Proxied(OutboundProxyStream),
|
||||
|
||||
@@ -161,7 +161,7 @@ pub async fn create_resolver(
|
||||
Ok(resolver) => Ok(resolver),
|
||||
Err(err) => {
|
||||
error!("initialize DNS resolver with config failed, error: {}", err);
|
||||
Err(io::Error::new(io::ErrorKind::Other, err))
|
||||
Err(io::Error::other(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -186,13 +186,13 @@ pub async fn create_resolver(
|
||||
Ok(resolver) => Ok(resolver),
|
||||
Err(err) => {
|
||||
error!("initialize DNS resolver with config failed, error: {}", err);
|
||||
Err(io::Error::new(io::ErrorKind::Other, err))
|
||||
Err(io::Error::other(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
error!("initialize DNS resolver with system-config failed, error: {}", err);
|
||||
Err(io::Error::new(io::ErrorKind::Other, err))
|
||||
Err(io::Error::other(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user