From 20d2156b6dad5f5bc3a43f8e1070b72ba6b029ad Mon Sep 17 00:00:00 2001 From: bdbai Date: Tue, 16 Jan 2024 17:16:24 +0800 Subject: [PATCH] fix clippy --- .../src/edit/views/new_proxy_group.rs | 2 +- .../src/edit/views/proxy_group.rs | 2 +- .../src/edit/views/proxy_type.rs | 4 +- .../src/storage_resource_loader.rs | 4 +- ytflow-uwp-plugin/src/vpn_plugin.rs | 19 ++-- ytflow/src/config/factory.rs | 8 +- ytflow/src/config/plugin.rs | 2 +- ytflow/src/config/plugin/dyn_outbound.rs | 1 - ytflow/src/config/plugin/host_resolver.rs | 2 +- ytflow/src/config/plugin/list_dispatcher.rs | 3 +- ytflow/src/config/plugin/rule_dispatcher.rs | 23 ++--- ytflow/src/config/plugin/socket_listener.rs | 4 +- ytflow/src/config/plugin/switch.rs | 1 - ytflow/src/config/set.rs | 2 +- ytflow/src/control/plugin.rs | 2 +- ytflow/src/control/rpc.rs | 12 +-- ytflow/src/data/db.rs | 4 +- ytflow/src/data/error.rs | 16 +++- ytflow/src/data/mod.rs | 2 +- ytflow/src/data/profile.rs | 2 +- ytflow/src/data/proxy.rs | 4 +- ytflow/src/data/proxy_group.rs | 8 +- ytflow/src/data/resource.rs | 4 +- ytflow/src/ffi.rs | 1 + ytflow/src/ffi/config.rs | 2 +- ytflow/src/ffi/data.rs | 92 +++++++++++-------- ytflow/src/ffi/interop.rs | 2 +- ytflow/src/ffi/runtime.rs | 2 +- ytflow/src/plugin.rs | 2 +- ytflow/src/plugin/dns_server/map_back.rs | 5 +- ytflow/src/plugin/dyn_outbound/select.rs | 6 +- ytflow/src/plugin/forward/stream.rs | 2 +- ytflow/src/plugin/host_resolver/mod.rs | 2 +- ytflow/src/plugin/ip_stack/mod.rs | 2 +- ytflow/src/plugin/netif/resolver.rs | 2 +- ytflow/src/plugin/netif/responder.rs | 2 +- ytflow/src/plugin/netif/selector.rs | 2 +- ytflow/src/plugin/netif/sys/win.rs | 2 +- ytflow/src/plugin/obfs/simple_http.rs | 2 +- ytflow/src/plugin/obfs/simple_tls.rs | 2 +- ytflow/src/plugin/rule_dispatcher.rs | 4 +- .../rule_dispatcher/builder/quanx_filter.rs | 6 +- ytflow/src/plugin/shadowsocks/crypto/aead.rs | 4 +- .../src/plugin/shadowsocks/factory/stream.rs | 2 +- ytflow/src/plugin/shadowsocks/mod.rs | 2 +- ytflow/src/plugin/shadowsocks/stream.rs | 5 +- ytflow/src/plugin/shadowsocks/util.rs | 2 +- ytflow/src/plugin/socket/mod.rs | 3 +- ytflow/src/plugin/socket/tcp.rs | 14 +-- ytflow/src/plugin/socket/udp.rs | 10 +- ytflow/src/plugin/system_resolver.rs | 3 +- ytflow/src/plugin/tls/stream.rs | 3 +- ytflow/src/plugin/vmess/client.rs | 19 ++-- ytflow/src/plugin/vmess/protocol/body/aead.rs | 4 +- .../src/plugin/vmess/protocol/header/aead.rs | 35 ++++--- .../plugin/vmess/protocol/header/aes_cfb.rs | 6 +- .../plugin/vmess/protocol/header/crypto.rs | 4 +- .../plugin/vmess/protocol/header/hmac_hash.rs | 4 +- ytflow/src/plugin/ws.rs | 6 +- ytflow/src/resource.rs | 6 +- 60 files changed, 213 insertions(+), 190 deletions(-) diff --git a/ytflow-bin-shared/src/edit/views/new_proxy_group.rs b/ytflow-bin-shared/src/edit/views/new_proxy_group.rs index d303da6..ea7d6d7 100644 --- a/ytflow-bin-shared/src/edit/views/new_proxy_group.rs +++ b/ytflow-bin-shared/src/edit/views/new_proxy_group.rs @@ -13,7 +13,7 @@ use crate::edit; use ytflow::data::proxy_group::{ProxyGroup, PROXY_GROUP_TYPE_MANUAL}; thread_local! { - static SHOULD_RETURN: Cell = Cell::new(false); + static SHOULD_RETURN: Cell = const { Cell::new(false) }; } fn state_index_to_type(index: usize) -> Option<&'static str> { diff --git a/ytflow-bin-shared/src/edit/views/proxy_group.rs b/ytflow-bin-shared/src/edit/views/proxy_group.rs index 2977922..e5e5bcd 100644 --- a/ytflow-bin-shared/src/edit/views/proxy_group.rs +++ b/ytflow-bin-shared/src/edit/views/proxy_group.rs @@ -254,7 +254,7 @@ fn edit_proxy(ctx: &mut edit::AppContext, bytes: &[u8]) -> Result let val = EditProxy { tcp_entry: proxy.tcp_entry, udp_entry: proxy.udp_entry, - plugins: plugins, + plugins, }; // Serialize cborium Value into bytes using cbor4ii and deserialize into cbor4ii Value diff --git a/ytflow-bin-shared/src/edit/views/proxy_type.rs b/ytflow-bin-shared/src/edit/views/proxy_type.rs index cfe89e5..7fbe18f 100644 --- a/ytflow-bin-shared/src/edit/views/proxy_type.rs +++ b/ytflow-bin-shared/src/edit/views/proxy_type.rs @@ -13,8 +13,8 @@ use crate::edit; use ytflow::data::{Proxy, ProxyGroupId}; thread_local! { - static SHOULD_RETURN: Cell = Cell::new(false); - static LAST_NEW_PROXY_NAME: Cell = Cell::new(String::new()); + static SHOULD_RETURN: Cell = const { Cell::new(false) }; + static LAST_NEW_PROXY_NAME: Cell = const { Cell::new(String::new()) }; } pub fn run_proxy_type_view( diff --git a/ytflow-uwp-plugin/src/storage_resource_loader.rs b/ytflow-uwp-plugin/src/storage_resource_loader.rs index bfd173e..2f256ca 100644 --- a/ytflow-uwp-plugin/src/storage_resource_loader.rs +++ b/ytflow-uwp-plugin/src/storage_resource_loader.rs @@ -22,7 +22,7 @@ unsafe impl Send for StorageResourceLoader {} unsafe impl Sync for StorageResourceLoader {} fn hresult_to_resource(r: windows::core::Error) -> ResourceError { - ResourceError::IoError(io::Error::from_raw_os_error(r.code().0 as i32)) + ResourceError::IoError(io::Error::from_raw_os_error(r.code().0)) } impl FileResourceLoader for StorageResourceLoader { @@ -36,7 +36,7 @@ impl FileResourceLoader for StorageResourceLoader { let handle_access: IStorageItemHandleAccess = storage_file.cast().unwrap(); unsafe { let handle = handle_access - .Create(HAO_READ.into(), HSO_SHARE_READ.into(), HO_NONE.into(), None) + .Create(HAO_READ, HSO_SHARE_READ, HO_NONE, None) .map_err(hresult_to_resource)?; let file = fs::File::from_raw_handle(handle.0 as _); Ok(file) diff --git a/ytflow-uwp-plugin/src/vpn_plugin.rs b/ytflow-uwp-plugin/src/vpn_plugin.rs index a6cc9e8..1f7ae20 100644 --- a/ytflow-uwp-plugin/src/vpn_plugin.rs +++ b/ytflow-uwp-plugin/src/vpn_plugin.rs @@ -126,7 +126,7 @@ async fn run_rpc(control_hub: ytflow::control::ControlHub) -> std::io::Result<() let s = TcpSocket::new_v4()?; s.set_reuseaddr(true)?; s.bind(SocketAddr::new(Ipv4Addr::LOCALHOST.into(), 0))?; - let port = HSTRING::try_from(s.local_addr()?.port().to_string()).unwrap(); + let port = HSTRING::from(s.local_addr()?.port().to_string()); let _ = APP_SETTINGS.get().unwrap().Values()?.Insert( h!("YTFLOW_CORE_RPC_PORT"), &IInspectable::try_from(port).unwrap(), @@ -166,7 +166,7 @@ impl Drop for Runtime { fn drop(&mut self) { let _enter_guard = self.rt.enter(); unsafe { - let _ = self.rpc_task.abort(); + self.rpc_task.abort(); let _rx_buf_tx = ManuallyDrop::take(&mut self.rx_buf_tx); let _plugin_set = ManuallyDrop::take(&mut self.plugin_set); } @@ -252,7 +252,7 @@ impl VpnPlugIn { .as_wide(), ) .into(); - let db = match ytflow::data::Database::open(&db_path) { + let db = match ytflow::data::Database::open(db_path) { Ok(db) => db, Err(e) => return Err(format!("Cannot open database: {}", e).into()), }; @@ -268,7 +268,7 @@ impl VpnPlugIn { std::result::Result<(Vec, Vec), String>, > { use ytflow::data::{Plugin, Profile}; - let profile_id = match Profile::query_by_id(profile_id, &conn)? { + let profile_id = match Profile::query_by_id(profile_id, conn)? { Some(p) => p.id, None => return Ok(Err(format!("Profile {} not found", profile_id))), }; @@ -361,7 +361,7 @@ impl VpnPlugIn { .collect::, _>>(); res.map(|_| loader) })?; - factory.load_all(&rt_handle, Box::new(loader), Some(&db)) + factory.load_all(rt_handle, Box::new(loader), Some(&db)) }; let mut error_str = if errors.is_empty() { String::from("There must be exactly one vpn-tun entry plugin in a profile") @@ -374,10 +374,10 @@ impl VpnPlugIn { loop { if let (Some(vpn_items), []) = (vpn_items_cell.borrow_mut().take(), &*errors) { let (tx_buf_rx, rx_buf_tx, vpn_tun_factory) = vpn_items; - match connect_with_factory(&transport, &vpn_tun_factory, &channel) { + match connect_with_factory(&transport, &vpn_tun_factory, channel) { Ok(()) => { *inner = VpnPlugInInner::Running { - tx_buf_rx: tx_buf_rx, + tx_buf_rx, runtime: Runtime { rx_buf_tx: ManuallyDrop::new(rx_buf_tx), plugin_set: ManuallyDrop::new(set), @@ -408,8 +408,7 @@ impl VpnPlugIn { impl IVpnPlugIn_Impl for VpnPlugIn { fn Connect(&self, channel: Option<&VpnChannel>) -> Result<()> { let channel = channel.unwrap(); - if let Err(crate::error::ConnectError(e)) = self.connect_core(channel) { - let err_msg = format!("{}", e); + if let Err(crate::error::ConnectError(err_msg)) = self.connect_core(channel) { APP_SETTINGS.get().unwrap().Values()?.Insert( h!("YTFLOW_CORE_ERROR_LOAD"), &IInspectable::try_from(HSTRING::from(&err_msg))?, @@ -458,7 +457,7 @@ impl IVpnPlugIn_Impl for VpnPlugIn { std::ptr::copy_nonoverlapping(slice.as_mut_ptr(), buf.as_mut_ptr(), len); buf.set_len(len); } - if let Err(_) = rx_buf_tx.send(buf) { + if rx_buf_tx.send(buf).is_err() { return Ok(()); } packets.Append(&vpn_buffer)?; diff --git a/ytflow/src/config/factory.rs b/ytflow/src/config/factory.rs index 8572636..243304c 100644 --- a/ytflow/src/config/factory.rs +++ b/ytflow/src/config/factory.rs @@ -51,10 +51,10 @@ pub(super) trait Factory { fn load(&mut self, plugin_name: String, set: &mut PartialPluginSet<'_>) -> LoadResult<()>; } -impl<'de, 'f> Factory for Box { +impl<'f> Factory for Box { #[cfg(feature = "plugins")] fn load(&mut self, plugin_name: String, set: &mut PartialPluginSet) -> LoadResult<()> { - (&mut **self).load(plugin_name, set) + (**self).load(plugin_name, set) } } @@ -184,7 +184,7 @@ impl<'de> AccessPointResolver<'de> { descriptor: ap.to_owned(), }); } - self.demanding_aps.entry(ap).or_insert(vec![]).push(demand); + self.demanding_aps.entry(ap).or_default().push(demand); Ok(()) } fn process_plugin( @@ -207,7 +207,7 @@ impl<'de> AccessPointResolver<'de> { .errors .extend(requires.into_iter().filter_map(|d| { self.insert_demand( - &*d.descriptor, + d.descriptor, Demand { initiator: &plugin.name, ap_type: d.r#type, diff --git a/ytflow/src/config/plugin.rs b/ytflow/src/config/plugin.rs index 754e67d..83b224b 100644 --- a/ytflow/src/config/plugin.rs +++ b/ytflow/src/config/plugin.rs @@ -12,7 +12,7 @@ mod null; mod redirect; mod reject; mod resolve_dest; -pub(self) mod rule_dispatcher; +mod rule_dispatcher; mod shadowsocks; mod simple_dispatcher; mod socket; diff --git a/ytflow/src/config/plugin/dyn_outbound.rs b/ytflow/src/config/plugin/dyn_outbound.rs index 2aaef15..c6d7f3d 100644 --- a/ytflow/src/config/plugin/dyn_outbound.rs +++ b/ytflow/src/config/plugin/dyn_outbound.rs @@ -72,7 +72,6 @@ impl<'de> Factory for DynOutboundFactory<'de> { let db = set .db - .as_deref() .ok_or_else(|| LoadError::DatabaseRequired { plugin: plugin_name.clone(), })? diff --git a/ytflow/src/config/plugin/host_resolver.rs b/ytflow/src/config/plugin/host_resolver.rs index 969477a..62614b5 100644 --- a/ytflow/src/config/plugin/host_resolver.rs +++ b/ytflow/src/config/plugin/host_resolver.rs @@ -121,7 +121,7 @@ impl<'de> Factory for HostResolverFactory<'de> { let udp = self .udp .iter() - .map(|c| set.get_or_create_datagram_outbound(plugin_name.clone(), *c)) + .map(|c| set.get_or_create_datagram_outbound(plugin_name.clone(), c)) .filter_map(|d| match d { Ok(d) => Some(d), Err(e) => { diff --git a/ytflow/src/config/plugin/list_dispatcher.rs b/ytflow/src/config/plugin/list_dispatcher.rs index e2872cc..aa86e29 100644 --- a/ytflow/src/config/plugin/list_dispatcher.rs +++ b/ytflow/src/config/plugin/list_dispatcher.rs @@ -115,7 +115,7 @@ fn load_rule_set( }; match metadata.r#type.as_str() { RESOURCE_TYPE_SURGE_DOMAINSET => { - let text = validate_text(&bytes, &plugin_name, set); + let text = validate_text(&bytes, plugin_name, set); match rd::RuleSet::build_surge_domainset(text.lines(), action) { Some(ruleset) => return ruleset, // TODO: log ruleset build error @@ -197,7 +197,6 @@ impl<'de> Factory for ListDispatcherFactory<'de> { let resolver = self .config .resolver - .clone() .map(|resolver| load_resolver(resolver, set, &plugin_name)); let me = weak.clone(); builder.set_resolver(resolver); diff --git a/ytflow/src/config/plugin/rule_dispatcher.rs b/ytflow/src/config/plugin/rule_dispatcher.rs index 7082ce3..bddfc28 100644 --- a/ytflow/src/config/plugin/rule_dispatcher.rs +++ b/ytflow/src/config/plugin/rule_dispatcher.rs @@ -86,13 +86,11 @@ impl<'de> RuleDispatcherFactory<'de> { } } - if let Some(geoip_source) = &config.geoip { - if let ResourceSource::Literal { .. } = geoip_source { - return Err(ConfigError::InvalidParam { - plugin: name.to_string(), - field: "geoip", - }); - } + if let Some(ResourceSource::Literal { .. }) = &config.geoip { + return Err(ConfigError::InvalidParam { + plugin: name.to_string(), + field: "geoip", + }); } if config.actions.len() > rd::ACTION_LIMIT { @@ -292,8 +290,8 @@ fn load_rule_set( set: &mut PartialPluginSet, ) -> rd::RuleSet { let rule_action_map = rules - .into_iter() - .map(|(rule, action)| (*rule, action_map[*action].clone())) + .iter() + .map(|(rule, action)| (*rule, action_map[*action])) .collect(); let resource_key; let resource_type; @@ -325,8 +323,8 @@ fn load_rule_set( RESOURCE_TYPE_GEOIP_COUNTRY => { match rd::RuleSet::build_dst_geoip_rule( rules - .into_iter() - .map(|(rule, action)| (rule.to_string(), action_map[action].clone())), + .iter() + .map(|(rule, action)| (rule.to_string(), action_map[action])), bytes, ) { Some(ruleset) => return ruleset, @@ -341,7 +339,7 @@ fn load_rule_set( } } RESOURCE_TYPE_QUANX_FILTER => { - let text = validate_text(&bytes, &plugin_name, set); + let text = validate_text(&bytes, plugin_name, set); match rd::RuleSet::load_quanx_filter( text.lines(), &rule_action_map, @@ -442,7 +440,6 @@ impl<'de> Factory for RuleDispatcherFactory<'de> { let resolver = self .config .resolver - .clone() .map(|resolver| load_resolver(resolver, set, &plugin_name)); let fallback = load_action(&self.config.fallback, set, &plugin_name); let me = weak.clone(); diff --git a/ytflow/src/config/plugin/socket_listener.rs b/ytflow/src/config/plugin/socket_listener.rs index 744cc40..2573478 100644 --- a/ytflow/src/config/plugin/socket_listener.rs +++ b/ytflow/src/config/plugin/socket_listener.rs @@ -21,12 +21,12 @@ impl<'de> SocketListenerFactory<'de> { let config: Self = parse_param(name, param)?; Ok(ParsedPlugin { requires: (!config.tcp_listen.is_empty()) - .then(|| Descriptor { + .then_some(Descriptor { descriptor: config.tcp_next, r#type: AccessPointType::STREAM_HANDLER, }) .into_iter() - .chain((!config.udp_listen.is_empty()).then(|| Descriptor { + .chain((!config.udp_listen.is_empty()).then_some(Descriptor { descriptor: config.udp_next, r#type: AccessPointType::DATAGRAM_SESSION_HANDLER, })) diff --git a/ytflow/src/config/plugin/switch.rs b/ytflow/src/config/plugin/switch.rs index b2deb76..50a4333 100644 --- a/ytflow/src/config/plugin/switch.rs +++ b/ytflow/src/config/plugin/switch.rs @@ -85,7 +85,6 @@ impl<'de> Factory for SwitchFactory<'de> { let db = set .db - .as_deref() .ok_or_else(|| LoadError::DatabaseRequired { plugin: plugin_name.clone(), })? diff --git a/ytflow/src/config/set.rs b/ytflow/src/config/set.rs index c8616da..8152daa 100644 --- a/ytflow/src/config/set.rs +++ b/ytflow/src/config/set.rs @@ -41,7 +41,7 @@ fn lookup( strong_map .get(descriptor) .map(Arc::downgrade) - .or_else(|| weak_map.get(descriptor).map(Weak::clone)) + .or_else(|| weak_map.get(descriptor).cloned()) } macro_rules! impl_get_or_create { diff --git a/ytflow/src/control/plugin.rs b/ytflow/src/control/plugin.rs index e4f2b59..15618db 100644 --- a/ytflow/src/control/plugin.rs +++ b/ytflow/src/control/plugin.rs @@ -59,7 +59,7 @@ impl PluginController { .map(|info| PluginInfo { id: self.id, name: Cow::Borrowed(&self.name), - plugin: Cow::Borrowed(&self.plugin), + plugin: Cow::Borrowed(self.plugin), info: ByteBuf::from(info), hashcode, }) diff --git a/ytflow/src/control/rpc.rs b/ytflow/src/control/rpc.rs index d94c159..b76f150 100644 --- a/ytflow/src/control/rpc.rs +++ b/ytflow/src/control/rpc.rs @@ -63,16 +63,16 @@ impl<'h> ControlHubService<'h> { let req: ControlHubRequest = match from_slice(req) { Ok(req) => req, Err(e) => { - return Ok(to_writer( + return to_writer( res, &ControlHubResponse::<(), _>::Err { error: e.to_string(), }, - )?); + ); } }; - Ok(match req { + match req { ControlHubRequest::CollectAllPluginInfo { hashcodes } => { let data = self.collect_all_plugin_info(hashcodes); to_writer(res, &ControlHubResponse::<_, ()>::Ok { data }) @@ -84,7 +84,7 @@ impl<'h> ControlHubService<'h> { .into(); to_writer(res, &response) } - }?) + } } fn collect_all_plugin_info(&mut self, hashcodes: BTreeMap) -> Vec { @@ -106,7 +106,7 @@ impl<'h> ControlHubService<'h> { .iter() .find(|p| p.id == id) .ok_or(plugin::PluginRequestError::NoSuchPlugin) - .and_then(|p| p.responder.on_request(&func, ¶ms)) + .and_then(|p| p.responder.on_request(func, params)) } } @@ -143,7 +143,7 @@ where D: Sink, Error = E> + TryStream, Error = E> + Unpin, { while let Some(req) = io.try_next().await? { - if req.len() == 0 { + if req.is_empty() { continue; } let mut res = Vec::with_capacity(128); diff --git a/ytflow/src/data/db.rs b/ytflow/src/data/db.rs index 710ee44..17ee9f7 100644 --- a/ytflow/src/data/db.rs +++ b/ytflow/src/data/db.rs @@ -52,7 +52,7 @@ pub struct Database { fn connect(path: impl AsRef) -> DataResult { setup_temp(); let db = Connection::open(&path)?; - db.pragma_update(None, "foreign_keys", &"ON")?; + db.pragma_update(None, "foreign_keys", "ON")?; Ok(db) } @@ -72,7 +72,7 @@ impl Database { pub fn connect_temp() -> DataResult { setup_temp(); let mut db = Connection::open_in_memory()?; - db.pragma_update(None, "foreign_keys", &"ON")?; + db.pragma_update(None, "foreign_keys", "ON")?; embedded_migrations::migrations::runner().run(&mut db)?; Ok(db) } diff --git a/ytflow/src/data/error.rs b/ytflow/src/data/error.rs index 4d16833..1c2e0ad 100644 --- a/ytflow/src/data/error.rs +++ b/ytflow/src/data/error.rs @@ -3,9 +3,9 @@ use thiserror::Error; #[derive(Debug, Error)] pub enum DataError { #[error("cannot migrate")] - Migration(#[from] refinery::Error), + Migration(Box), #[error("error performing sqlite operations")] - Database(#[from] rusqlite::Error), + Database(Box), #[error("field \"{field:?}\" for \"{domain:?}\" is not valid")] InvalidData { domain: &'static str, @@ -13,4 +13,16 @@ pub enum DataError { }, } +impl From for DataError { + fn from(e: refinery::Error) -> Self { + DataError::Migration(Box::new(e)) + } +} + +impl From for DataError { + fn from(e: rusqlite::Error) -> Self { + DataError::Database(Box::new(e)) + } +} + pub type DataResult = Result; diff --git a/ytflow/src/data/mod.rs b/ytflow/src/data/mod.rs index c912ea4..d7b339a 100644 --- a/ytflow/src/data/mod.rs +++ b/ytflow/src/data/mod.rs @@ -17,7 +17,7 @@ pub struct Id(pub u32, PhantomData); impl Clone for Id { fn clone(&self) -> Id { - Self(self.0, PhantomData) + *self } } impl Copy for Id {} diff --git a/ytflow/src/data/profile.rs b/ytflow/src/data/profile.rs index 8516580..59405bc 100644 --- a/ytflow/src/data/profile.rs +++ b/ytflow/src/data/profile.rs @@ -43,7 +43,7 @@ impl Profile { .query_row_and_then( r"SELECT `id`, `permanent_id`, `name`, `locale`, `last_used_at`, `created_at` FROM `yt_profiles` WHERE `id` = ?", - &[&id], + [&id], map_from_row, ) .optional()?) diff --git a/ytflow/src/data/proxy.rs b/ytflow/src/data/proxy.rs index ad6a4ee..8c0e104 100644 --- a/ytflow/src/data/proxy.rs +++ b/ytflow/src/data/proxy.rs @@ -36,7 +36,7 @@ fn map_from_row(row: &Row) -> Result { } fn are_proxies_equivalent(old: &Proxy, new: &ProxyInput) -> bool { - old.name == new.name && &old.proxy == &*new.proxy && old.proxy_version == new.proxy_version + old.name == new.name && old.proxy == *new.proxy && old.proxy_version == new.proxy_version } impl Proxy { @@ -168,7 +168,7 @@ impl Proxy { let old_proxies = Self::query_all_by_group(proxy_group_id, &tx)?; // Delete all proxies starting from the first proxy that is not in the new list, and then insert all new proxies from that point. - let mut zipped = old_proxies.iter().zip_longest(new_proxies.into_iter()); + let mut zipped = old_proxies.iter().zip_longest(new_proxies); let mut proxy_to_insert_from = loop { let mut proxy_to_insert_from = None; let proxy_to_delete_from = match zipped.next() { diff --git a/ytflow/src/data/proxy_group.rs b/ytflow/src/data/proxy_group.rs index 30d9436..d7350d2 100644 --- a/ytflow/src/data/proxy_group.rs +++ b/ytflow/src/data/proxy_group.rs @@ -25,8 +25,8 @@ pub struct ProxySubscription { pub retrieved_at: Option, } -pub const PROXY_GROUP_TYPE_MANUAL: &'static str = "manual"; -pub const PROXY_GROUP_TYPE_SUBSCRIPTION: &'static str = "subscription"; +pub const PROXY_GROUP_TYPE_MANUAL: &str = "manual"; +pub const PROXY_GROUP_TYPE_SUBSCRIPTION: &str = "subscription"; fn map_from_row(row: &Row) -> Result { Ok(ProxyGroup { @@ -55,7 +55,7 @@ impl ProxyGroup { .query_row_and_then( r"SELECT `id`, `name`, `type`, `created_at` FROM `yt_proxy_groups` WHERE `id` = ?", - &[&id], + [&id], map_from_row, ) .optional()?) @@ -118,7 +118,7 @@ impl ProxySubscription { .query_row_and_then( r"SELECT `format`, `url`, `upload_bytes_used`, `download_bytes_used`, `bytes_total`, `expires_at`, `retrieved_at` FROM `yt_proxy_subscriptions` WHERE `proxy_group_id` = ?", - &[&proxy_group_id], + [&proxy_group_id], map_subscription_from_row, )?) } diff --git a/ytflow/src/data/resource.rs b/ytflow/src/data/resource.rs index bc3b936..21d4bce 100644 --- a/ytflow/src/data/resource.rs +++ b/ytflow/src/data/resource.rs @@ -157,7 +157,7 @@ impl ResourceUrl { .query_row_and_then( r"SELECT `id`, `url`, `etag`, `last_modified`, `retrieved_at` FROM `yt_resources_url` WHERE `resource_id` = ?", - &[&resource_id], + [&resource_id], map_resource_url_from_row, ) .optional()?) @@ -185,7 +185,7 @@ impl ResourceGitHubRelease { .query_row_and_then( r"SELECT `id`, `github_username`, `github_repo`, `asset_name`, `git_tag`, `release_title`, `retrieved_at` FROM `yt_resources_github_release` WHERE `resource_id` = ?", - &[&resource_id], + [&resource_id], map_resource_github_release_from_row, ) .optional()?) diff --git a/ytflow/src/ffi.rs b/ytflow/src/ffi.rs index 2bcca90..2d5e40a 100644 --- a/ytflow/src/ffi.rs +++ b/ytflow/src/ffi.rs @@ -1,3 +1,4 @@ +#![allow(clippy::missing_safety_doc)] pub mod config; pub mod data; pub mod error; diff --git a/ytflow/src/ffi/config.rs b/ytflow/src/ffi/config.rs index 2dfe7e3..391d36b 100644 --- a/ytflow/src/ffi/config.rs +++ b/ytflow/src/ffi/config.rs @@ -7,7 +7,7 @@ use crate::config::verify::verify_plugin; use crate::config::Plugin; #[no_mangle] -pub extern "C" fn ytflow_plugin_verify( +pub unsafe extern "C" fn ytflow_plugin_verify( plugin: *const c_char, plugin_version: u16, param: *const u8, diff --git a/ytflow/src/ffi/data.rs b/ytflow/src/ffi/data.rs index aafe207..bf681ea 100644 --- a/ytflow/src/ffi/data.rs +++ b/ytflow/src/ffi/data.rs @@ -12,7 +12,7 @@ use crate::data::{ #[no_mangle] #[cfg(windows)] -pub extern "C" fn ytflow_db_new_win32(path: *const u16, len: usize) -> FfiResult { +pub unsafe extern "C" fn ytflow_db_new_win32(path: *const u16, len: usize) -> FfiResult { use std::ffi::OsString; use std::os::windows::ffi::OsStringExt; FfiResult::catch_result_unwind(move || { @@ -23,7 +23,7 @@ pub extern "C" fn ytflow_db_new_win32(path: *const u16, len: usize) -> FfiResult #[no_mangle] #[cfg(unix)] -pub extern "C" fn ytflow_db_new_unix(path: *const u8, len: usize) -> FfiResult { +pub unsafe extern "C" fn ytflow_db_new_unix(path: *const u8, len: usize) -> FfiResult { use std::ffi::OsStr; use std::os::unix::ffi::OsStrExt; FfiResult::catch_result_unwind(move || { @@ -33,7 +33,7 @@ pub extern "C" fn ytflow_db_new_unix(path: *const u8, len: usize) -> FfiResult { } #[no_mangle] -pub extern "C" fn ytflow_db_free(db: *mut Database) -> FfiResult { +pub unsafe extern "C" fn ytflow_db_free(db: *mut Database) -> FfiResult { FfiResult::catch_ptr_unwind(move || { unsafe { drop(Box::from_raw(db)) }; (null_mut(), 0) @@ -41,7 +41,7 @@ pub extern "C" fn ytflow_db_free(db: *mut Database) -> FfiResult { } #[no_mangle] -pub extern "C" fn ytflow_db_conn_new(db: *const Database) -> FfiResult { +pub unsafe extern "C" fn ytflow_db_conn_new(db: *const Database) -> FfiResult { FfiResult::catch_result_unwind(move || { let db = unsafe { &*db }; db.connect() @@ -50,7 +50,7 @@ pub extern "C" fn ytflow_db_conn_new(db: *const Database) -> FfiResult { } #[no_mangle] -pub extern "C" fn ytflow_db_conn_free(conn: *mut Connection) -> FfiResult { +pub unsafe extern "C" fn ytflow_db_conn_free(conn: *mut Connection) -> FfiResult { FfiResult::catch_ptr_unwind(AssertUnwindSafe(move || { unsafe { drop(Box::from_raw(conn)) }; (null_mut(), 0) @@ -58,7 +58,7 @@ pub extern "C" fn ytflow_db_conn_free(conn: *mut Connection) -> FfiResult { } #[no_mangle] -pub extern "C" fn ytflow_profiles_get_all(conn: *const Connection) -> FfiResult { +pub unsafe extern "C" fn ytflow_profiles_get_all(conn: *const Connection) -> FfiResult { FfiResult::catch_result_unwind(AssertUnwindSafe(move || { let conn = unsafe { &*conn }; Profile::query_all(conn).map(|p| serialize_buffer(&p)) @@ -66,7 +66,7 @@ pub extern "C" fn ytflow_profiles_get_all(conn: *const Connection) -> FfiResult } #[no_mangle] -pub extern "C" fn ytflow_plugins_get_by_profile( +pub unsafe extern "C" fn ytflow_plugins_get_by_profile( profile_id: u32, conn: *const Connection, ) -> FfiResult { @@ -77,7 +77,10 @@ pub extern "C" fn ytflow_plugins_get_by_profile( } #[no_mangle] -pub extern "C" fn ytflow_plugins_get_entry(profile_id: u32, conn: *const Connection) -> FfiResult { +pub unsafe extern "C" fn ytflow_plugins_get_entry( + profile_id: u32, + conn: *const Connection, +) -> FfiResult { FfiResult::catch_result_unwind(AssertUnwindSafe(move || { let conn = unsafe { &*conn }; Plugin::query_entry_by_profile(profile_id.into(), conn).map(|p| serialize_buffer(&p)) @@ -85,7 +88,7 @@ pub extern "C" fn ytflow_plugins_get_entry(profile_id: u32, conn: *const Connect } #[no_mangle] -pub extern "C" fn ytflow_profile_create( +pub unsafe extern "C" fn ytflow_profile_create( name: *const c_char, locale: *const c_char, conn: *const Connection, @@ -104,7 +107,7 @@ pub extern "C" fn ytflow_profile_create( } #[no_mangle] -pub extern "C" fn ytflow_profile_update( +pub unsafe extern "C" fn ytflow_profile_update( profile_id: u32, name: *const c_char, locale: *const c_char, @@ -125,7 +128,10 @@ pub extern "C" fn ytflow_profile_update( } #[no_mangle] -pub extern "C" fn ytflow_profile_delete(profile_id: u32, conn: *const Connection) -> FfiResult { +pub unsafe extern "C" fn ytflow_profile_delete( + profile_id: u32, + conn: *const Connection, +) -> FfiResult { FfiResult::catch_result_unwind(AssertUnwindSafe(move || { let conn = unsafe { &*conn }; Profile::delete(profile_id, conn).map(|()| (null_mut(), 0)) @@ -133,7 +139,7 @@ pub extern "C" fn ytflow_profile_delete(profile_id: u32, conn: *const Connection } #[no_mangle] -pub extern "C" fn ytflow_plugin_create( +pub unsafe extern "C" fn ytflow_plugin_create( profile_id: u32, name: *const c_char, desc: *const c_char, @@ -162,7 +168,7 @@ pub extern "C" fn ytflow_plugin_create( } #[no_mangle] -pub extern "C" fn ytflow_plugin_update( +pub unsafe extern "C" fn ytflow_plugin_update( plugin_id: u32, profile_id: u32, name: *const c_char, @@ -193,7 +199,10 @@ pub extern "C" fn ytflow_plugin_update( } #[no_mangle] -pub extern "C" fn ytflow_plugin_delete(plugin_id: u32, conn: *const Connection) -> FfiResult { +pub unsafe extern "C" fn ytflow_plugin_delete( + plugin_id: u32, + conn: *const Connection, +) -> FfiResult { FfiResult::catch_result_unwind(AssertUnwindSafe(move || { let conn = unsafe { &*conn }; Plugin::delete(plugin_id, conn).map(|()| (null_mut(), 0)) @@ -201,7 +210,7 @@ pub extern "C" fn ytflow_plugin_delete(plugin_id: u32, conn: *const Connection) } #[no_mangle] -pub extern "C" fn ytflow_plugin_set_as_entry( +pub unsafe extern "C" fn ytflow_plugin_set_as_entry( plugin_id: u32, profile_id: u32, conn: *const Connection, @@ -213,7 +222,7 @@ pub extern "C" fn ytflow_plugin_set_as_entry( } #[no_mangle] -pub extern "C" fn ytflow_plugin_unset_as_entry( +pub unsafe extern "C" fn ytflow_plugin_unset_as_entry( plugin_id: u32, profile_id: u32, conn: *const Connection, @@ -225,7 +234,7 @@ pub extern "C" fn ytflow_plugin_unset_as_entry( } #[no_mangle] -pub extern "C" fn ytflow_proxy_group_get_all(conn: *const Connection) -> FfiResult { +pub unsafe extern "C" fn ytflow_proxy_group_get_all(conn: *const Connection) -> FfiResult { FfiResult::catch_result_unwind(AssertUnwindSafe(move || { let conn = unsafe { &*conn }; ProxyGroup::query_all(conn).map(|p| serialize_buffer(&p)) @@ -233,7 +242,7 @@ pub extern "C" fn ytflow_proxy_group_get_all(conn: *const Connection) -> FfiResu } #[no_mangle] -pub extern "C" fn ytflow_proxy_group_get_by_id( +pub unsafe extern "C" fn ytflow_proxy_group_get_by_id( proxy_group_id: u32, conn: *const Connection, ) -> FfiResult { @@ -244,7 +253,7 @@ pub extern "C" fn ytflow_proxy_group_get_by_id( } #[no_mangle] -pub extern "C" fn ytflow_proxy_group_create( +pub unsafe extern "C" fn ytflow_proxy_group_create( name: *const c_char, r#type: *const c_char, conn: *const Connection, @@ -263,7 +272,7 @@ pub extern "C" fn ytflow_proxy_group_create( } #[no_mangle] -pub extern "C" fn ytflow_proxy_group_create_subscription( +pub unsafe extern "C" fn ytflow_proxy_group_create_subscription( name: *const c_char, format: *const c_char, url: *const c_char, @@ -285,7 +294,7 @@ pub extern "C" fn ytflow_proxy_group_create_subscription( } #[no_mangle] -pub extern "C" fn ytflow_proxy_group_rename( +pub unsafe extern "C" fn ytflow_proxy_group_rename( proxy_group_id: u32, name: *const c_char, conn: *const Connection, @@ -299,7 +308,7 @@ pub extern "C" fn ytflow_proxy_group_rename( } #[no_mangle] -pub extern "C" fn ytflow_proxy_group_delete( +pub unsafe extern "C" fn ytflow_proxy_group_delete( proxy_group_id: u32, conn: *const Connection, ) -> FfiResult { @@ -310,19 +319,19 @@ pub extern "C" fn ytflow_proxy_group_delete( } #[no_mangle] -pub extern "C" fn ytflow_proxy_subscription_query_by_proxy_group_id( +pub unsafe extern "C" fn ytflow_proxy_subscription_query_by_proxy_group_id( proxy_group_id: u32, conn: *const Connection, ) -> FfiResult { FfiResult::catch_result_unwind(AssertUnwindSafe(move || { let conn = unsafe { &*conn }; - ProxySubscription::query_by_proxy_group_id(proxy_group_id.into(), conn) + ProxySubscription::query_by_proxy_group_id(proxy_group_id, conn) .map(|p| serialize_buffer(&p)) })) } #[no_mangle] -pub extern "C" fn ytflow_proxy_subscription_update_retrieved_by_proxy_group_id( +pub unsafe extern "C" fn ytflow_proxy_subscription_update_retrieved_by_proxy_group_id( proxy_group_id: u32, upload_bytes_used: *const u64, download_bytes_used: *const u64, @@ -341,7 +350,7 @@ pub extern "C" fn ytflow_proxy_subscription_update_retrieved_by_proxy_group_id( }; let conn = unsafe { &*conn }; ProxySubscription::update_retrieved_by_proxy_group_id( - proxy_group_id.into(), + proxy_group_id, upload_bytes_used, download_bytes_used, bytes_total, @@ -353,7 +362,7 @@ pub extern "C" fn ytflow_proxy_subscription_update_retrieved_by_proxy_group_id( } #[no_mangle] -pub extern "C" fn ytflow_proxy_get_by_proxy_group( +pub unsafe extern "C" fn ytflow_proxy_get_by_proxy_group( proxy_group_id: u32, conn: *const Connection, ) -> FfiResult { @@ -364,7 +373,7 @@ pub extern "C" fn ytflow_proxy_get_by_proxy_group( } #[no_mangle] -pub extern "C" fn ytflow_proxy_create( +pub unsafe extern "C" fn ytflow_proxy_create( proxy_group_id: u32, name: *const c_char, proxy: *const u8, @@ -387,7 +396,7 @@ pub extern "C" fn ytflow_proxy_create( } #[no_mangle] -pub extern "C" fn ytflow_proxy_update( +pub unsafe extern "C" fn ytflow_proxy_update( proxy_id: u32, name: *const c_char, proxy: *const u8, @@ -410,7 +419,7 @@ pub extern "C" fn ytflow_proxy_update( } #[no_mangle] -pub extern "C" fn ytflow_proxy_delete(proxy_id: u32, conn: *const Connection) -> FfiResult { +pub unsafe extern "C" fn ytflow_proxy_delete(proxy_id: u32, conn: *const Connection) -> FfiResult { FfiResult::catch_result_unwind(AssertUnwindSafe(move || { let conn = unsafe { &*conn }; Proxy::delete(proxy_id, conn).map(|()| (null_mut(), 0)) @@ -418,7 +427,7 @@ pub extern "C" fn ytflow_proxy_delete(proxy_id: u32, conn: *const Connection) -> } #[no_mangle] -pub extern "C" fn ytflow_proxy_reorder( +pub unsafe extern "C" fn ytflow_proxy_reorder( proxy_group_id: u32, range_start_order: i32, range_end_order: i32, @@ -439,7 +448,7 @@ pub extern "C" fn ytflow_proxy_reorder( } #[no_mangle] -pub extern "C" fn ytflow_proxy_batch_update_by_group( +pub unsafe extern "C" fn ytflow_proxy_batch_update_by_group( proxy_group_id: u32, new_proxies_buf: *const u8, new_proxies_buf_len: usize, @@ -463,7 +472,7 @@ pub extern "C" fn ytflow_proxy_batch_update_by_group( } #[no_mangle] -pub extern "C" fn ytflow_resource_get_all(conn: *const Connection) -> FfiResult { +pub unsafe extern "C" fn ytflow_resource_get_all(conn: *const Connection) -> FfiResult { FfiResult::catch_result_unwind(AssertUnwindSafe(move || { let conn = unsafe { &*conn }; Resource::query_all(conn).map(|r| serialize_buffer(&r)) @@ -471,7 +480,10 @@ pub extern "C" fn ytflow_resource_get_all(conn: *const Connection) -> FfiResult } #[no_mangle] -pub extern "C" fn ytflow_resource_delete(resource_id: u32, conn: *const Connection) -> FfiResult { +pub unsafe extern "C" fn ytflow_resource_delete( + resource_id: u32, + conn: *const Connection, +) -> FfiResult { FfiResult::catch_result_unwind(AssertUnwindSafe(move || { let conn = unsafe { &*conn }; Resource::delete(resource_id, conn).map(|()| (null_mut(), 0)) @@ -479,7 +491,7 @@ pub extern "C" fn ytflow_resource_delete(resource_id: u32, conn: *const Connecti } #[no_mangle] -pub extern "C" fn ytflow_resource_create_with_url( +pub unsafe extern "C" fn ytflow_resource_create_with_url( key: *const c_char, r#type: *const c_char, local_file: *const c_char, @@ -504,7 +516,7 @@ pub extern "C" fn ytflow_resource_create_with_url( } #[no_mangle] -pub extern "C" fn ytflow_resource_create_with_github_release( +pub unsafe extern "C" fn ytflow_resource_create_with_github_release( key: *const c_char, r#type: *const c_char, local_file: *const c_char, @@ -535,7 +547,7 @@ pub extern "C" fn ytflow_resource_create_with_github_release( } #[no_mangle] -pub extern "C" fn ytflow_resource_url_query_by_resource_id( +pub unsafe extern "C" fn ytflow_resource_url_query_by_resource_id( resource_id: u32, conn: *const Connection, ) -> FfiResult { @@ -546,7 +558,7 @@ pub extern "C" fn ytflow_resource_url_query_by_resource_id( } #[no_mangle] -pub extern "C" fn ytflow_resource_url_update_retrieved_by_resource_id( +pub unsafe extern "C" fn ytflow_resource_url_update_retrieved_by_resource_id( resource_id: u32, etag: *const c_char, last_modified: *const c_char, @@ -578,7 +590,7 @@ pub extern "C" fn ytflow_resource_url_update_retrieved_by_resource_id( } #[no_mangle] -pub extern "C" fn ytflow_resource_github_release_query_by_resource_id( +pub unsafe extern "C" fn ytflow_resource_github_release_query_by_resource_id( resource_id: u32, conn: *const Connection, ) -> FfiResult { @@ -589,7 +601,7 @@ pub extern "C" fn ytflow_resource_github_release_query_by_resource_id( } #[no_mangle] -pub extern "C" fn ytflow_resource_github_release_update_retrieved_by_resource_id( +pub unsafe extern "C" fn ytflow_resource_github_release_update_retrieved_by_resource_id( resource_id: u32, git_tag: *const c_char, release_title: *const c_char, diff --git a/ytflow/src/ffi/interop.rs b/ytflow/src/ffi/interop.rs index 5a69dc9..f0fff01 100644 --- a/ytflow/src/ffi/interop.rs +++ b/ytflow/src/ffi/interop.rs @@ -6,7 +6,7 @@ use serde::Serialize; use super::error::FfiResult; #[no_mangle] -pub extern "C" fn ytflow_buffer_free(ptr: *mut c_void, metadata: usize) -> FfiResult { +pub unsafe extern "C" fn ytflow_buffer_free(ptr: *mut c_void, metadata: usize) -> FfiResult { FfiResult::catch_ptr_unwind(|| { unsafe { drop(Box::from_raw(std::ptr::from_raw_parts_mut::<[u8]>( diff --git a/ytflow/src/ffi/runtime.rs b/ytflow/src/ffi/runtime.rs index 270daec..8737582 100644 --- a/ytflow/src/ffi/runtime.rs +++ b/ytflow/src/ffi/runtime.rs @@ -23,7 +23,7 @@ pub extern "C" fn ytflow_runtime_new() -> FfiResult { } #[no_mangle] -pub extern "C" fn ytflow_runtime_free(runtime: *mut Runtime) -> FfiResult { +pub unsafe extern "C" fn ytflow_runtime_free(runtime: *mut Runtime) -> FfiResult { FfiResult::catch_ptr_unwind(AssertUnwindSafe(|| { unsafe { drop(Box::from_raw(runtime)) }; (null_mut(), 0) diff --git a/ytflow/src/plugin.rs b/ytflow/src/plugin.rs index a06a122..0023c76 100644 --- a/ytflow/src/plugin.rs +++ b/ytflow/src/plugin.rs @@ -45,4 +45,4 @@ pub mod vmess; pub mod ws; #[cfg(feature = "plugins")] -pub(self) mod h2; +mod h2; diff --git a/ytflow/src/plugin/dns_server/map_back.rs b/ytflow/src/plugin/dns_server/map_back.rs index 78bdf47..82c88eb 100644 --- a/ytflow/src/plugin/dns_server/map_back.rs +++ b/ytflow/src/plugin/dns_server/map_back.rs @@ -17,7 +17,7 @@ struct BackMapper { impl BackMapper { fn map_back_host(&self, host: &mut HostName) { match host { - HostName::DomainName(_) => return, + HostName::DomainName(_) => (), HostName::Ip(IpAddr::V4(ip)) => { *host = self .reverse_mapping_v4 @@ -136,7 +136,8 @@ impl DatagramSession for MapBackDatagramSession { fn send_to(&mut self, mut remote_peer: DestinationAddr, buf: Buffer) { if let HostName::DomainName(domain) = &remote_peer.host - && let Some(ip) = self.local_forward_mapping.get(domain) { + && let Some(ip) = self.local_forward_mapping.get(domain) + { remote_peer.host = HostName::Ip(*ip); } self.lower.send_to(remote_peer, buf) diff --git a/ytflow/src/plugin/dyn_outbound/select.rs b/ytflow/src/plugin/dyn_outbound/select.rs index dbf9816..8c814ab 100644 --- a/ytflow/src/plugin/dyn_outbound/select.rs +++ b/ytflow/src/plugin/dyn_outbound/select.rs @@ -83,11 +83,11 @@ impl super::DynOutbound { let mut preset_stream_outbounds = BTreeMap::new(); let mut preset_datagram_outbounds = BTreeMap::new(); preset_stream_outbounds.insert( - "$out.tcp".into(), + "$out.tcp", self.tcp_next.upgrade().ok_or(SelectError::NoOutbound)?, ); let udp_next = self.udp_next.upgrade().ok_or(SelectError::NoOutbound)?; - preset_datagram_outbounds.insert("$out.udp".into(), udp_next.clone()); + preset_datagram_outbounds.insert("$out.udp", udp_next.clone()); let (loader, errs) = crate::config::loader::proxy::ProxyLoader::parse_with_preset_outbounds( preset_stream_outbounds, preset_datagram_outbounds, @@ -116,7 +116,7 @@ impl super::DynOutbound { .ok_or_else(|| SelectError::EntrypointNotFound(udp_entry.into())) }) .transpose()? - .unwrap_or_else(|| udp_next); + .unwrap_or(udp_next); Ok(Selection { idx, diff --git a/ytflow/src/plugin/forward/stream.rs b/ytflow/src/plugin/forward/stream.rs index fe86cc8..1b91911 100644 --- a/ytflow/src/plugin/forward/stream.rs +++ b/ytflow/src/plugin/forward/stream.rs @@ -223,7 +223,7 @@ impl StreamForwardHandler { } // Drop earlier to prevent StreamForward outliving outbound - let _ = StreamForward { + StreamForward { stream_local: lower.as_mut(), stream_remote: outbound.as_mut(), downlink_state: initial_downlink_state, diff --git a/ytflow/src/plugin/host_resolver/mod.rs b/ytflow/src/plugin/host_resolver/mod.rs index 85d90ff..94e00ed 100644 --- a/ytflow/src/plugin/host_resolver/mod.rs +++ b/ytflow/src/plugin/host_resolver/mod.rs @@ -41,7 +41,7 @@ impl HostResolver { let datagram_hosts = datagram_hosts.into_iter(); let doh = doh.into_iter(); let size_hint = datagram_hosts.size_hint().1.unwrap_or(0) + doh.size_hint().1.unwrap_or(0); - let doh_factories = doh.map(|d| Arc::new(d)).collect::>(); + let doh_factories = doh.map(Arc::new).collect::>(); let mut dns_configs = Vec::with_capacity(size_hint); let mut factory_ids = Vec::with_capacity(size_hint); { diff --git a/ytflow/src/plugin/ip_stack/mod.rs b/ytflow/src/plugin/ip_stack/mod.rs index e21f86b..cda3585 100644 --- a/ytflow/src/plugin/ip_stack/mod.rs +++ b/ytflow/src/plugin/ip_stack/mod.rs @@ -369,7 +369,7 @@ fn process_udp( Box::new(MultiplexedDatagramSessionAdapter::new( datagram::IpStackDatagramSession { stack: stack_inner, - local_endpoint: src_addr.into(), + local_endpoint: src_addr, }, rx.into_stream(), 120, diff --git a/ytflow/src/plugin/netif/resolver.rs b/ytflow/src/plugin/netif/resolver.rs index f79c0ef..b14ae1d 100644 --- a/ytflow/src/plugin/netif/resolver.rs +++ b/ytflow/src/plugin/netif/resolver.rs @@ -95,7 +95,7 @@ fn create_host_resolver( } ( - HostResolver::new(weak_udp_factories.into_iter(), []), + HostResolver::new(weak_udp_factories, []), vec![], udp_factories, ) diff --git a/ytflow/src/plugin/netif/responder.rs b/ytflow/src/plugin/netif/responder.rs index 3fe287b..bc2afd7 100644 --- a/ytflow/src/plugin/netif/responder.rs +++ b/ytflow/src/plugin/netif/responder.rs @@ -44,7 +44,7 @@ impl PluginResponder for Responder { let info = Info { selection: &selection.0, preference: selection.1, - netif: &**netif, + netif: &netif, }; Some(to_vec(vec![], &info).unwrap()) } diff --git a/ytflow/src/plugin/netif/selector.rs b/ytflow/src/plugin/netif/selector.rs index 14a20f5..b8c2f75 100644 --- a/ytflow/src/plugin/netif/selector.rs +++ b/ytflow/src/plugin/netif/selector.rs @@ -73,7 +73,7 @@ impl StreamOutboundFactory for NetifSelector { let preference = self.selection.load().1; let netif = self.cached_netif.load(); crate::plugin::socket::dial_stream( - &context, + context, self.me.upgrade().unwrap(), // A workaround for E0308 "one type is more general than the other" // https://github.com/rust-lang/rust/issues/70263 diff --git a/ytflow/src/plugin/netif/sys/win.rs b/ytflow/src/plugin/netif/sys/win.rs index dbc6ff8..cc949f8 100644 --- a/ytflow/src/plugin/netif/sys/win.rs +++ b/ytflow/src/plugin/netif/sys/win.rs @@ -17,7 +17,7 @@ pub struct Netif { pub dns_servers: Vec, } -pub(crate) fn serialize_ipaddrs(ipaddrs: &Vec, serializer: S) -> Result +pub(crate) fn serialize_ipaddrs(ipaddrs: &[IpAddr], serializer: S) -> Result where S: Serializer, { diff --git a/ytflow/src/plugin/obfs/simple_http.rs b/ytflow/src/plugin/obfs/simple_http.rs index a57d423..625355c 100644 --- a/ytflow/src/plugin/obfs/simple_http.rs +++ b/ytflow/src/plugin/obfs/simple_http.rs @@ -139,7 +139,7 @@ impl StreamOutboundFactory for SimpleHttpOutbound { thread_rng().fill_bytes(&mut ws_key); let mut b64 = [0; 32]; let b64_len = BASE64_URL_SAFE - .encode_slice(&ws_key, &mut b64) + .encode_slice(ws_key, &mut b64) .expect("A base64 repr of 16 bytes should not exceed 32 chars"); req.extend_from_slice(&b64[..b64_len]); req.extend_from_slice(b"\r\nContent-Length: "); diff --git a/ytflow/src/plugin/obfs/simple_tls.rs b/ytflow/src/plugin/obfs/simple_tls.rs index 8011edb..84df546 100644 --- a/ytflow/src/plugin/obfs/simple_tls.rs +++ b/ytflow/src/plugin/obfs/simple_tls.rs @@ -142,7 +142,7 @@ impl Stream for SimpleTlsOutboundStream { fn commit_tx_buffer(&mut self, mut buffer: Buffer) -> FlowResult<()> { let mut payload_offset = self.tx_offset + self.tx_total_overhead; while payload_offset < buffer.len() { - let chunk_size = (buffer.len() - payload_offset).min(MAX_TLS_CHUNK_SIZE as usize); + let chunk_size = (buffer.len() - payload_offset).min(MAX_TLS_CHUNK_SIZE); *<&mut [u8; LEN_BUFFER_SIZE]>::try_from( &mut buffer[self.tx_offset..self.tx_offset + LEN_BUFFER_SIZE], ) diff --git a/ytflow/src/plugin/rule_dispatcher.rs b/ytflow/src/plugin/rule_dispatcher.rs index 7d6be0f..89d8b42 100644 --- a/ytflow/src/plugin/rule_dispatcher.rs +++ b/ytflow/src/plugin/rule_dispatcher.rs @@ -3,9 +3,9 @@ use std::sync::Weak; #[cfg(feature = "plugins")] mod builder; #[cfg(feature = "plugins")] -pub(self) mod dispatcher; +mod dispatcher; #[cfg(feature = "plugins")] -pub(self) mod rules; +mod rules; #[cfg(feature = "plugins")] mod set; diff --git a/ytflow/src/plugin/rule_dispatcher/builder/quanx_filter.rs b/ytflow/src/plugin/rule_dispatcher/builder/quanx_filter.rs index 4155e7d..6346704 100644 --- a/ytflow/src/plugin/rule_dispatcher/builder/quanx_filter.rs +++ b/ytflow/src/plugin/rule_dispatcher/builder/quanx_filter.rs @@ -84,7 +84,7 @@ fn build_ac_from_line_segs<'s, S: Iterator>( .filter_map(|(id, mut segs)| { let rule_type = segs.next()?; accepted_rule_types - .into_iter() + .iter() .any(|r| rule_type.eq_ignore_ascii_case(r)) .then_some((id, segs)) }) @@ -108,7 +108,7 @@ fn build_ip_rules_from_line_segs<'s, 'r, 'f: 'r, S: Iterator, I> .filter_map(|(id, mut segs)| { let rule_type = segs.next()?; accepted_rule_types - .into_iter() + .iter() .any(|r| rule_type.eq_ignore_ascii_case(r)) .then_some((id, segs)) }) @@ -145,7 +145,7 @@ impl RuleSet { ) -> Option { let lines = lines .map(|l| l.trim()) - .filter(|l| !l.starts_with(&['#', ';']) && !l.is_empty()) + .filter(|l| !l.starts_with(['#', ';']) && !l.is_empty()) .enumerate() .map(|(idx, l)| (idx as u32 + 1, l.split(',').map(|s| s.trim()))); let (mut full_rule_ranges, mut sub_rule_ranges, mut keyword_rule_ranges) = diff --git a/ytflow/src/plugin/shadowsocks/crypto/aead.rs b/ytflow/src/plugin/shadowsocks/crypto/aead.rs index 94f14cf..fb2826c 100644 --- a/ytflow/src/plugin/shadowsocks/crypto/aead.rs +++ b/ytflow/src/plugin/shadowsocks/crypto/aead.rs @@ -73,7 +73,7 @@ where return None; } increase_num_buf(&mut self.nonce); - let size = u16::from_be_bytes((&size_buf[..]).try_into().unwrap()) & 0x3fff; + let size = u16::from_be_bytes(size_buf.try_into().unwrap()) & 0x3fff; NonZeroUsize::new(size as usize) } @@ -84,7 +84,7 @@ where ) -> bool { let res = self .inner - .decrypt_in_place_detached(&self.nonce, &[], data, (&*post_overhead).into()) + .decrypt_in_place_detached(&self.nonce, &[], data, post_overhead.into()) .is_ok(); increase_num_buf(&mut self.nonce); res diff --git a/ytflow/src/plugin/shadowsocks/factory/stream.rs b/ytflow/src/plugin/shadowsocks/factory/stream.rs index 9a72a01..f890f4f 100644 --- a/ytflow/src/plugin/shadowsocks/factory/stream.rs +++ b/ytflow/src/plugin/shadowsocks/factory/stream.rs @@ -65,7 +65,7 @@ where ) -> FlowResult<(Box, Buffer)> { let outbound_factory = self.next.upgrade().ok_or(FlowError::NoOutbound)?; let ((next, initial_res), tx_crypto) = { - let (tx_buffer, tx_crypto) = self.get_req(&context, initial_data); + let (tx_buffer, tx_crypto) = self.get_req(context, initial_data); ( outbound_factory .create_outbound(context, &tx_buffer) diff --git a/ytflow/src/plugin/shadowsocks/mod.rs b/ytflow/src/plugin/shadowsocks/mod.rs index 4297f9c..877a265 100644 --- a/ytflow/src/plugin/shadowsocks/mod.rs +++ b/ytflow/src/plugin/shadowsocks/mod.rs @@ -1,5 +1,5 @@ #[cfg(feature = "plugins")] -pub(self) mod crypto; +mod crypto; #[cfg(feature = "plugins")] mod datagram; #[cfg(feature = "plugins")] diff --git a/ytflow/src/plugin/shadowsocks/stream.rs b/ytflow/src/plugin/shadowsocks/stream.rs index 496dc3e..b624491 100644 --- a/ytflow/src/plugin/shadowsocks/stream.rs +++ b/ytflow/src/plugin/shadowsocks/stream.rs @@ -52,8 +52,7 @@ where reader.poll_read_exact(cx, lower.as_mut(), C::IV_LEN, |buf| iv .copy_from_slice(buf)) )?; - *crypto = - RxCryptoState::Ready(C::create_crypto(key, (&iv).try_into().unwrap())); + *crypto = RxCryptoState::Ready(C::create_crypto(key, &iv)); } RxCryptoState::Ready(_) if C::PRE_CHUNK_OVERHEAD == 0 => { return Poll::Ready(Ok(SizeHint::Unknown { overhead: 0 })); @@ -109,7 +108,7 @@ where to_write })); if let Ok(written) = &res { - let _ = reader.advance(*written); + reader.advance(*written); } res.map(|_| ()) } else { diff --git a/ytflow/src/plugin/shadowsocks/util.rs b/ytflow/src/plugin/shadowsocks/util.rs index 2c3dd61..a3a4355 100644 --- a/ytflow/src/plugin/shadowsocks/util.rs +++ b/ytflow/src/plugin/shadowsocks/util.rs @@ -68,7 +68,7 @@ pub fn openssl_bytes_to_key(password: &[u8]) -> [u8; K] { while offset < K { let mut m = Md5::new(); if let Some(digest) = last_digest { - m.update(&digest); + m.update(digest); } m.update(password); diff --git a/ytflow/src/plugin/socket/mod.rs b/ytflow/src/plugin/socket/mod.rs index ec9e04b..398c6f5 100644 --- a/ytflow/src/plugin/socket/mod.rs +++ b/ytflow/src/plugin/socket/mod.rs @@ -22,8 +22,7 @@ pub use udp_listener::listen_udp; // See https://datatracker.ietf.org/doc/html/rfc8305 const CONN_ATTEMPT_DELAY: Duration = Duration::from_millis(250); const RESOLUTION_DELAY: Duration = Duration::from_millis(50); -const SOCKET_KEEPALIVE: &'static TcpKeepalive = - &TcpKeepalive::new().with_time(Duration::from_secs(600)); +const SOCKET_KEEPALIVE: &TcpKeepalive = &TcpKeepalive::new().with_time(Duration::from_secs(600)); pub struct SocketOutboundFactory { pub resolver: Weak, diff --git a/ytflow/src/plugin/socket/tcp.rs b/ytflow/src/plugin/socket/tcp.rs index deca304..6130dfb 100644 --- a/ytflow/src/plugin/socket/tcp.rs +++ b/ytflow/src/plugin/socket/tcp.rs @@ -111,10 +111,10 @@ pub async fn dial_stream( dial_socket_v6(ip, port, &bind_v6).await? } (HostName::DomainName(domain), Some(bind_v4), None) => { - let mut ip_iter = resolver.resolve_ipv4(domain).await?.into_iter(); + let ips = resolver.resolve_ipv4(domain).await?; let mut ret = Err(FlowError::NoOutbound); let mut futs = FuturesUnordered::new(); - while let Some(ip) = ip_iter.next() { + for ip in ips { futs.push(dial_socket_v4(ip, port, &bind_v4)); if timeout(super::CONN_ATTEMPT_DELAY, async { while let Some(r) = futs.next().await { @@ -145,10 +145,10 @@ pub async fn dial_stream( } } (HostName::DomainName(domain), None, Some(bind_v6)) => { - let mut ip_iter = resolver.resolve_ipv6(domain).await?.into_iter(); + let ips = resolver.resolve_ipv6(domain).await?; let mut ret = Err(FlowError::NoOutbound); let mut futs = FuturesUnordered::new(); - while let Some(ip) = ip_iter.next() { + for ip in ips { futs.push(dial_socket_v6(ip, port, &bind_v6)); if timeout(super::CONN_ATTEMPT_DELAY, async { while let Some(r) = futs.next().await { @@ -247,12 +247,12 @@ impl StreamOutboundFactory for super::SocketOutboundFactory { let resolver = self.resolver.upgrade().ok_or(FlowError::NoOutbound)?; dial_stream( - &context, + context, resolver, - bind_addr_v4.clone().map(|addr| { + bind_addr_v4.map(|addr| { move |s: &mut socket2::Socket| s.bind(&addr.into()).map_err(FlowError::from) }), - bind_addr_v6.clone().map(|addr| { + bind_addr_v6.map(|addr| { move |s: &mut socket2::Socket| s.bind(&addr.into()).map_err(FlowError::from) }), initial_data, diff --git a/ytflow/src/plugin/socket/udp.rs b/ytflow/src/plugin/socket/udp.rs index d130cc5..2ae05a4 100644 --- a/ytflow/src/plugin/socket/udp.rs +++ b/ytflow/src/plugin/socket/udp.rs @@ -259,11 +259,11 @@ impl< ( res_v4.map(|ips| ips[0]), res_v6 - .or_else(|_| { - Err(FlowError::Io(io::Error::new( + .map_err(|_| { + FlowError::Io(io::Error::new( io::ErrorKind::TimedOut, "IPv6 resolver timeout", - ))) + )) }) .flatten() .map(|ips| ips[0]), @@ -353,10 +353,10 @@ impl DatagramSessionFactory for super::SocketOutboundFactory { dial_datagram_session( &context, resolver, - bind_addr_v4.clone().map(|addr| { + bind_addr_v4.map(|addr| { move |s: &mut socket2::Socket| s.bind(&addr.into()).map_err(FlowError::from) }), - bind_addr_v6.clone().map(|addr| { + bind_addr_v6.map(|addr| { move |s: &mut socket2::Socket| s.bind(&addr.into()).map_err(FlowError::from) }), ) diff --git a/ytflow/src/plugin/system_resolver.rs b/ytflow/src/plugin/system_resolver.rs index adb4581..8e4d6b9 100644 --- a/ytflow/src/plugin/system_resolver.rs +++ b/ytflow/src/plugin/system_resolver.rs @@ -7,11 +7,12 @@ use tokio::net::lookup_host; use crate::flow::*; +#[derive(Default)] pub struct SystemResolver {} impl SystemResolver { pub fn new() -> Self { - Self {} + Default::default() } } diff --git a/ytflow/src/plugin/tls/stream.rs b/ytflow/src/plugin/tls/stream.rs index 3cff811..063f6d2 100644 --- a/ytflow/src/plugin/tls/stream.rs +++ b/ytflow/src/plugin/tls/stream.rs @@ -115,7 +115,6 @@ impl StreamOutboundFactory for SslStreamFactory { FlowError::UnexpectedData })?; { - let initial_data_container = initial_data_container; let initial_data = initial_data_container .lock() .unwrap() @@ -144,7 +143,7 @@ impl StreamOutboundFactory for SslStreamFactory { .retain(|a| a.as_bytes() == alpn); } - Pin::new(&mut ssl_stream).write(initial_data).await?; + Pin::new(&mut ssl_stream).write_all(initial_data).await?; Ok((Box::new(CompatFlow::new(ssl_stream, 4096)), Buffer::new())) } diff --git a/ytflow/src/plugin/vmess/client.rs b/ytflow/src/plugin/vmess/client.rs index 11355dc..d8a07e3 100644 --- a/ytflow/src/plugin/vmess/client.rs +++ b/ytflow/src/plugin/vmess/client.rs @@ -66,20 +66,21 @@ where let rx_size_crypto; let header_dec; let (stream, initial_res) = { - let mut req_buf = Vec::with_capacity(RE::REQUIRED_SIZE); - req_buf.resize(RE::REQUIRED_SIZE, 0); - let mut request = RequestHeader::default(); - request.ver = 1; + let mut req_buf = vec![0; RE::REQUIRED_SIZE]; + let mut request = RequestHeader { + ver: 1, + res_auth: rand::thread_rng().gen(), + opt: VMESS_HEADER_OPT_STD | VMESS_HEADER_OPT_SHAKE, + cmd: VMESS_HEADER_CMD_TCP, + port: context.remote_peer.port, + addr: (&context.remote_peer.host).into(), + ..Default::default() + }; getrandom(&mut request.data_iv).unwrap(); getrandom(&mut request.data_key).unwrap(); - request.res_auth = rand::thread_rng().gen(); - request.opt = VMESS_HEADER_OPT_STD | VMESS_HEADER_OPT_SHAKE; request.set_padding_len(rand::thread_rng().gen_range(0..=0b1111)); getrandom(request.padding_mut()).unwrap(); request.set_encryption(F::HEADER_SEC_TYPE); - request.cmd = VMESS_HEADER_CMD_TCP; - request.port = context.remote_peer.port; - request.addr = (&context.remote_peer.host).into(); let res_iv = req_enc.derive_res_iv(&request); let res_key = req_enc.derive_res_key(&request); let (req_len, dec) = req_enc.encrypt_req(&mut request, &mut req_buf).unwrap(); diff --git a/ytflow/src/plugin/vmess/protocol/body/aead.rs b/ytflow/src/plugin/vmess/protocol/body/aead.rs index 62507b7..c01ba39 100644 --- a/ytflow/src/plugin/vmess/protocol/body/aead.rs +++ b/ytflow/src/plugin/vmess/protocol/body/aead.rs @@ -57,7 +57,7 @@ impl AeadClientCryptoTx { ) -> Self { let key = { let hash1 = Md5::digest(data_key); - let hash2 = Md5::digest(&hash1); + let hash2 = Md5::digest(hash1); let mut key = [0; 32]; key[..16].copy_from_slice(&hash1[..]); key[16..].copy_from_slice(&hash2[..]); @@ -103,7 +103,7 @@ impl AeadClientCryptoRx { ) -> Self { let key = { let hash1 = Md5::digest(data_key); - let hash2 = Md5::digest(&hash1); + let hash2 = Md5::digest(hash1); let mut key = [0; 32]; key[..16].copy_from_slice(&hash1[..]); key[16..].copy_from_slice(&hash2[..]); diff --git a/ytflow/src/plugin/vmess/protocol/header/aead.rs b/ytflow/src/plugin/vmess/protocol/header/aead.rs index c5b2403..4d7f923 100644 --- a/ytflow/src/plugin/vmess/protocol/header/aead.rs +++ b/ytflow/src/plugin/vmess/protocol/header/aead.rs @@ -103,14 +103,14 @@ impl RequestHeaderEnc for AeadRequestEnc { fn derive_res_iv(&self, header: &RequestHeader) -> [u8; HEADER_IV_LEN] { let mut res_iv = [0; HEADER_IV_LEN]; - let res = Sha256::digest(&header.data_iv); + let res = Sha256::digest(header.data_iv); res_iv[..].copy_from_slice(&res[..HEADER_IV_LEN]); res_iv } fn derive_res_key(&self, header: &RequestHeader) -> [u8; HEADER_KEY_LEN] { let mut res_key = [0; HEADER_KEY_LEN]; - let res = Sha256::digest(&header.data_key); + let res = Sha256::digest(header.data_key); res_key[..].copy_from_slice(&res[..HEADER_KEY_LEN]); res_key } @@ -177,7 +177,7 @@ impl RequestHeaderEnc for AeadRequestEnc { } impl ResponseHeaderDec for AeadRequestDec { - fn decrypt_res<'a>(&mut self, data: &'a mut [u8]) -> HeaderDecryptResult { + fn decrypt_res(&mut self, data: &mut [u8]) -> HeaderDecryptResult { const RES_LEN: usize = 4; // TODO: const time? // TODO: cmd bytes @@ -191,12 +191,17 @@ impl ResponseHeaderDec for AeadRequestDec { }; let (chunk, chunk_tag) = size_chunk.split_at_mut(HEADER_SIZE_LEN); let mut chunk = <[u8; HEADER_SIZE_LEN]>::try_from(chunk).unwrap(); - if let Err(_) = self.header_size_dec.clone().decrypt_in_place_detached( - &self.header_size_nonce, - &[][..], - &mut chunk, - (&*chunk_tag).into(), - ) { + if self + .header_size_dec + .clone() + .decrypt_in_place_detached( + &self.header_size_nonce, + &[][..], + &mut chunk, + (&*chunk_tag).into(), + ) + .is_err() + { return HeaderDecryptResult::Invalid; } let size = u16::from_be_bytes([chunk[0], chunk[1]]) as usize; @@ -209,12 +214,12 @@ impl ResponseHeaderDec for AeadRequestDec { }; }; let (chunk, chunk_tag) = chunk.split_at_mut(size); - if let Err(_) = self.header_dec.clone().decrypt_in_place_detached( - &self.header_nonce, - &[][..], - chunk, - (&*chunk_tag).into(), - ) { + if self + .header_dec + .clone() + .decrypt_in_place_detached(&self.header_nonce, &[][..], chunk, (&*chunk_tag).into()) + .is_err() + { return HeaderDecryptResult::Invalid; } diff --git a/ytflow/src/plugin/vmess/protocol/header/aes_cfb.rs b/ytflow/src/plugin/vmess/protocol/header/aes_cfb.rs index 315fc3d..7f02b0b 100644 --- a/ytflow/src/plugin/vmess/protocol/header/aes_cfb.rs +++ b/ytflow/src/plugin/vmess/protocol/header/aes_cfb.rs @@ -59,14 +59,14 @@ impl RequestHeaderEnc for AesCfbRequestEnc { fn derive_res_iv(&self, header: &RequestHeader) -> [u8; HEADER_IV_LEN] { let mut res_iv = [0; HEADER_IV_LEN]; - let res = Md5::digest(&header.data_iv); + let res = Md5::digest(header.data_iv); res_iv[..].copy_from_slice(&res[..]); res_iv } fn derive_res_key(&self, header: &RequestHeader) -> [u8; HEADER_KEY_LEN] { let mut res_key = [0; HEADER_KEY_LEN]; - let res = Md5::digest(&header.data_key); + let res = Md5::digest(header.data_key); res_key[..].copy_from_slice(&res[..]); res_key } @@ -97,7 +97,7 @@ impl RequestHeaderEnc for AesCfbRequestEnc { } impl ResponseHeaderDec for AesCfbResponseDec { - fn decrypt_res<'a>(&mut self, data: &'a mut [u8]) -> HeaderDecryptResult { + fn decrypt_res(&mut self, data: &mut [u8]) -> HeaderDecryptResult { // Be careful not to mutate data inplace because subsequent dec may still need to continue // the dec state, e.g. aes-cfb body dec. // See VMessClientStream::poll_request_size. diff --git a/ytflow/src/plugin/vmess/protocol/header/crypto.rs b/ytflow/src/plugin/vmess/protocol/header/crypto.rs index ab06a01..8bb779c 100644 --- a/ytflow/src/plugin/vmess/protocol/header/crypto.rs +++ b/ytflow/src/plugin/vmess/protocol/header/crypto.rs @@ -25,13 +25,13 @@ pub trait RequestHeaderEnc { pub trait ResponseHeaderDec { #[must_use] - fn decrypt_res<'a>(&mut self, data: &'a mut [u8]) -> HeaderDecryptResult; + fn decrypt_res(&mut self, data: &mut [u8]) -> HeaderDecryptResult; } pub fn derive_cmd_key(user_id: &[u8; USER_ID_LEN]) -> [u8; CMD_KEY_LEN] { let mut cmd_key = *b"????????????????c48619fe-8f02-49e0-b9e9-edf763e17e21"; cmd_key[..USER_ID_LEN].copy_from_slice(user_id); let mut cmd_key_out = [0; CMD_KEY_LEN]; - cmd_key_out[..].copy_from_slice(&Md5::digest(&cmd_key)[..]); + cmd_key_out[..].copy_from_slice(&Md5::digest(cmd_key)[..]); cmd_key_out } diff --git a/ytflow/src/plugin/vmess/protocol/header/hmac_hash.rs b/ytflow/src/plugin/vmess/protocol/header/hmac_hash.rs index ad52743..3a8cfe8 100644 --- a/ytflow/src/plugin/vmess/protocol/header/hmac_hash.rs +++ b/ytflow/src/plugin/vmess/protocol/header/hmac_hash.rs @@ -49,7 +49,7 @@ impl HashMarker for HmacFixedKeyHash Update for HmacFixedKeyHash { fn update(&mut self, data: &[u8]) { - Mac::update(&mut self.hmac, data.as_ref()); + Mac::update(&mut self.hmac, data); } } @@ -73,7 +73,7 @@ struct GlobalPathSegmentGuard; impl GlobalPathSegmentGuard { fn get_tls() -> &'static LocalKey>> { thread_local! { - static PATH_SEGMENTS: RefCell> = RefCell::new(None); + static PATH_SEGMENTS: RefCell> = const { RefCell::new(None) }; } &PATH_SEGMENTS } diff --git a/ytflow/src/plugin/ws.rs b/ytflow/src/plugin/ws.rs index c1fc7d5..12e016c 100644 --- a/ytflow/src/plugin/ws.rs +++ b/ytflow/src/plugin/ws.rs @@ -56,7 +56,7 @@ impl WebSocketStreamOutboundFactory { path, headers, next, - h2_probe_state: Mutex::new(Default::default()), + h2_probe_state: Default::default(), } } @@ -165,7 +165,7 @@ impl WebSocketStreamOutboundFactory { impl StreamOutboundFactory for WebSocketStreamOutboundFactory { async fn create_outbound( &self, - mut context: &mut FlowContext, + context: &mut FlowContext, initial_data: &[u8], ) -> FlowResult<(Box, Buffer)> { let res = loop { @@ -175,7 +175,7 @@ impl StreamOutboundFactory for WebSocketStreamOutboundFactory { } { H2ProbeState::NotSupported => { return self - .websocket_handshake_h1(&mut context, initial_data.into()) + .websocket_handshake_h1(context, initial_data.into()) .await } H2ProbeState::Supported(client) => { diff --git a/ytflow/src/resource.rs b/ytflow/src/resource.rs index 34848d4..01d396a 100644 --- a/ytflow/src/resource.rs +++ b/ytflow/src/resource.rs @@ -86,8 +86,8 @@ impl DbFileResourceLoader { }) .collect(); let registered_handles_for_bytes = metadatas - .iter() - .map(|(_, m)| (m.handle.handle.clone(), None)) + .values() + .map(|m| (m.handle.handle.clone(), None)) .collect(); Ok(Self { metadatas, @@ -107,7 +107,7 @@ impl DbFileResourceLoader { .map(move |(handle, bytes)| { use tokio::io::AsyncReadExt; async move { - let mut file = tokio::fs::File::from_std(file_loader.load_file(&handle)?); + let mut file = tokio::fs::File::from_std(file_loader.load_file(handle)?); let mut buf = Vec::new(); file.read_to_end(&mut buf).await?; *bytes = Some(buf.into());