Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
ibigbug committed Dec 25, 2023
1 parent 7bee89f commit 210a4a4
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 23 deletions.
6 changes: 4 additions & 2 deletions clash_lib/src/app/dispatcher/tracked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,12 @@ pub struct TrackedStream {
}

impl TrackedStream {
#[allow(clippy::borrowed_box)]
pub async fn new(
inner: BoxedChainedStream,
manager: Arc<Manager>,
sess: Session,
#[allow(clippy::borrowed_box)] rule: Option<&Box<dyn RuleMatcher>>,
rule: Option<&Box<dyn RuleMatcher>>,
) -> Self {
let uuid = uuid::Uuid::new_v4();
let chain = inner.chain().clone();
Expand Down Expand Up @@ -355,11 +356,12 @@ pub struct TrackedDatagram {
}

impl TrackedDatagram {
#[allow(clippy::borrowed_box)]
pub async fn new(
inner: BoxedChainedDatagram,
manager: Arc<Manager>,
sess: Session,
#[allow(clippy::borrowed_box)] rule: Option<&Box<dyn RuleMatcher>>,
rule: Option<&Box<dyn RuleMatcher>>,
) -> Self {
let uuid = uuid::Uuid::new_v4();
let chain = inner.chain().clone();
Expand Down
2 changes: 1 addition & 1 deletion clash_lib/src/app/dns/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl Config {
let mut policy = HashMap::new();

for (domain, server) in policy_map {
let nameservers = Config::parse_nameserver(&vec![server.to_owned()])?;
let nameservers = Config::parse_nameserver(&[server.to_owned()])?;

let (_, valid) = trie::valid_and_split_domain(domain);
if !valid {
Expand Down
12 changes: 6 additions & 6 deletions clash_lib/src/app/outbound/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ pub type ThreadSafeOutboundManager = Arc<OutboundManager>;

impl OutboundManager {
pub async fn new(
outbounds: Vec<Box<OutboundProxyProtocol>>,
outbound_groups: Vec<Box<OutboundGroupProtocol>>,
outbounds: Vec<OutboundProxyProtocol>,
outbound_groups: Vec<OutboundGroupProtocol>,
proxy_providers: HashMap<String, OutboundProxyProviderDef>,
proxy_names: Vec<String>,
dns_resolver: ThreadSafeDNSResolver,
Expand Down Expand Up @@ -174,8 +174,8 @@ impl OutboundManager {

#[allow(clippy::too_many_arguments)]
async fn load_handlers(
outbounds: Vec<Box<OutboundProxyProtocol>>,
outbound_groups: Vec<Box<OutboundGroupProtocol>>,
outbounds: Vec<OutboundProxyProtocol>,
outbound_groups: Vec<OutboundGroupProtocol>,
proxy_names: Vec<String>,
proxy_manager: ProxyManager,
provider_registry: &mut HashMap<String, ThreadSafeProxyProvider>,
Expand All @@ -186,7 +186,7 @@ impl OutboundManager {
let mut proxy_providers = vec![];

for outbound in outbounds.iter() {
match outbound.as_ref() {
match outbound {
OutboundProxyProtocol::Direct => {
handlers.insert(PROXY_DIRECT.to_string(), direct::Handler::new());
}
Expand Down Expand Up @@ -269,7 +269,7 @@ impl OutboundManager {
}

for outbound_group in outbound_groups.iter() {
match outbound_group.as_ref() {
match outbound_group {
OutboundGroupProtocol::Relay(proto) => {
if proto.proxies.as_ref().map(|x| x.len()).unwrap_or_default()
+ proto
Expand Down
6 changes: 2 additions & 4 deletions clash_lib/src/app/outbound/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use std::{
use crate::{config::internal::proxy::OutboundGroupProtocol, Error};

// copy paste from https://github.com/Dreamacro/clash/blob/6a661bff0c185f38c4bd9d21c91a3233ba5fdb97/config/utils.go#L21
pub fn proxy_groups_dag_sort(groups: &mut Vec<Box<OutboundGroupProtocol>>) -> Result<(), Error> {
pub fn proxy_groups_dag_sort(groups: &mut Vec<OutboundGroupProtocol>) -> Result<(), Error> {
struct Node {
in_degree: i32,

// could be either group/proxy
proto: Option<Box<OutboundGroupProtocol>>,
proto: Option<OutboundGroupProtocol>,

outdegree: i32,

Expand Down Expand Up @@ -222,7 +222,6 @@ mod tests {
OutboundGroupProtocol::Select(g5),
]
.into_iter()
.map(|x| Box::new(x) as Box<OutboundGroupProtocol>)
.collect();

super::proxy_groups_dag_sort(&mut groups).unwrap();
Expand Down Expand Up @@ -266,7 +265,6 @@ mod tests {
OutboundGroupProtocol::Fallback(g3),
]
.into_iter()
.map(|x| Box::new(x) as Box<OutboundGroupProtocol>)
.collect();

let e = super::proxy_groups_dag_sort(&mut groups).unwrap_err();
Expand Down
15 changes: 7 additions & 8 deletions clash_lib/src/config/internal/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,15 @@ impl TryFrom<def::Config> for Config {
HashMap::from([
(
String::from(PROXY_DIRECT),
OutboundProxy::ProxyServer(Box::new(OutboundProxyProtocol::Direct)),
OutboundProxy::ProxyServer(OutboundProxyProtocol::Direct),
),
(
String::from(PROXY_REJECT),
OutboundProxy::ProxyServer(Box::new(OutboundProxyProtocol::Reject)),
OutboundProxy::ProxyServer(OutboundProxyProtocol::Reject),
),
]),
|mut rv, x| {
let proxy =
OutboundProxy::ProxyServer(Box::new(OutboundProxyProtocol::try_from(x)?));
let proxy = OutboundProxy::ProxyServer(OutboundProxyProtocol::try_from(x)?);
let name = proxy.name();
if rv.contains_key(name.as_str()) {
return Err(Error::InvalidConfig(format!(
Expand All @@ -163,8 +162,8 @@ impl TryFrom<def::Config> for Config {
proxy_groups: c.proxy_group.into_iter().try_fold(
HashMap::<String, OutboundProxy>::new(),
|mut rv, mapping| {
let group = OutboundProxy::ProxyGroup(Box::new(
mapping.clone().try_into().map_err(|x: Error| {
let group = OutboundProxy::ProxyGroup(mapping.clone().try_into().map_err(
|x: Error| {
if let Some(name) = mapping.get("name") {
Error::InvalidConfig(format!(
"proxy group: {}: {}",
Expand All @@ -174,8 +173,8 @@ impl TryFrom<def::Config> for Config {
} else {
Error::InvalidConfig("proxy group name missing".to_string())
}
})?,
));
},
)?);
proxy_names.push(group.name());
rv.insert(group.name().to_string(), group);
Ok::<HashMap<String, OutboundProxy>, Error>(rv)
Expand Down
5 changes: 3 additions & 2 deletions clash_lib/src/config/internal/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ pub const PROXY_DIRECT: &str = "DIRECT";
pub const PROXY_REJECT: &str = "REJECT";
pub const PROXY_GLOBAL: &str = "GLOBAL";

#[allow(clippy::large_enum_variant)]
pub enum OutboundProxy {
ProxyServer(Box<OutboundProxyProtocol>),
ProxyGroup(Box<OutboundGroupProtocol>),
ProxyServer(OutboundProxyProtocol),
ProxyGroup(OutboundGroupProtocol),
}

impl OutboundProxy {
Expand Down
1 change: 1 addition & 0 deletions clash_lib/src/proxy/datagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ pub struct OutboundDatagramImpl {
}

impl OutboundDatagramImpl {
#[allow(clippy::new_ret_no_self)]
pub fn new(udp: UdpSocket, resolver: ThreadSafeDNSResolver) -> AnyOutboundDatagram {
let s = Self {
inner: udp,
Expand Down
1 change: 1 addition & 0 deletions clash_lib/src/proxy/shadowsocks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ pub struct Handler {
}

impl Handler {
#[allow(clippy::new_ret_no_self)]
pub fn new(opts: HandlerOptions) -> AnyOutboundHandler {
Arc::new(Self { opts })
}
Expand Down

0 comments on commit 210a4a4

Please sign in to comment.