From 245eee3bbaaae7cdf062387fcdef17fd42e49e16 Mon Sep 17 00:00:00 2001 From: Zhang Jingqiang Date: Wed, 16 Aug 2023 19:37:21 +0800 Subject: [PATCH] simplify stats cast --- g3bench/src/target/h1/task.rs | 6 ++--- .../escape/direct_fixed/ftp_connect/stats.rs | 14 +++------- .../escape/direct_fixed/http_forward/mod.rs | 2 +- .../escape/direct_fixed/http_forward/stats.rs | 4 +-- g3proxy/src/escape/direct_fixed/mod.rs | 11 +++----- g3proxy/src/escape/direct_fixed/stats.rs | 14 +--------- .../escape/direct_fixed/tcp_connect/stats.rs | 7 ++--- .../escape/direct_fixed/tls_connect/mod.rs | 4 +-- .../escape/direct_fixed/udp_connect/stats.rs | 7 ++--- .../escape/direct_fixed/udp_relay/stats.rs | 6 ++--- .../escape/direct_float/ftp_connect/stats.rs | 7 ++--- .../escape/direct_float/http_forward/mod.rs | 2 +- g3proxy/src/escape/direct_float/stats.rs | 14 +--------- .../escape/direct_float/tcp_connect/stats.rs | 7 ++--- .../escape/direct_float/tls_connect/mod.rs | 4 +-- g3proxy/src/escape/dummy_deny/mod.rs | 9 +++---- g3proxy/src/escape/proxy_float/mod.rs | 9 +++---- .../proxy_float/peer/http/tcp_connect/mod.rs | 4 +-- .../proxy_float/peer/https/tcp_connect/mod.rs | 4 +-- .../peer/socks5/tcp_connect/mod.rs | 4 +-- .../src/escape/proxy_float/stats/escaper.rs | 14 +--------- .../escape/proxy_float/stats/wrapper/http.rs | 4 +-- .../escape/proxy_float/stats/wrapper/tcp.rs | 7 ++--- .../escape/proxy_http/http_connect/stats.rs | 7 ++--- .../escape/proxy_http/http_forward/stats.rs | 4 +-- g3proxy/src/escape/proxy_http/mod.rs | 12 +++------ g3proxy/src/escape/proxy_http/stats.rs | 14 +--------- .../src/escape/proxy_http/tcp_connect/mod.rs | 4 +-- g3proxy/src/escape/proxy_https/mod.rs | 12 +++------ g3proxy/src/escape/proxy_https/stats.rs | 14 +--------- .../src/escape/proxy_https/tcp_connect/mod.rs | 4 +-- g3proxy/src/escape/proxy_socks5/stats.rs | 14 +--------- .../escape/proxy_socks5/tcp_connect/mod.rs | 4 +-- g3proxy/src/serve/http_proxy/server.rs | 2 +- .../http_proxy/task/connect/stats/wrapper.rs | 7 ++--- .../src/serve/http_proxy/task/connect/task.rs | 2 +- .../http_proxy/task/forward/stats/task.rs | 11 +------- .../http_proxy/task/forward/stats/wrapper.rs | 12 +++------ .../src/serve/http_proxy/task/forward/task.rs | 6 ++--- .../serve/http_proxy/task/ftp/connection.rs | 16 +++--------- .../http_proxy/task/ftp/stats/wrapper.rs | 7 ++--- g3proxy/src/serve/http_rproxy/server.rs | 2 +- .../http_rproxy/task/forward/stats/task.rs | 11 +------- .../http_rproxy/task/forward/stats/wrapper.rs | 14 +++------- .../serve/http_rproxy/task/forward/task.rs | 6 ++--- g3proxy/src/serve/sni_proxy/server.rs | 2 +- .../src/serve/sni_proxy/task/relay/task.rs | 2 +- g3proxy/src/serve/socks_proxy/server.rs | 2 +- .../task/tcp_connect/stats/wrapper.rs | 7 ++--- .../socks_proxy/task/tcp_connect/task.rs | 2 +- .../task/udp_associate/stats/task.rs | 10 +------ .../task/udp_associate/stats/wrapper.rs | 7 ++--- .../socks_proxy/task/udp_associate/task.rs | 2 +- .../task/udp_connect/stats/task.rs | 11 +------- .../task/udp_connect/stats/wrapper.rs | 7 ++--- .../socks_proxy/task/udp_connect/task.rs | 2 +- g3proxy/src/serve/tcp_stream/server.rs | 2 +- g3proxy/src/serve/tcp_stream/task.rs | 6 ++--- g3proxy/src/serve/tls_stream/server.rs | 2 +- g3proxy/src/serve/tls_stream/task.rs | 6 ++--- g3tiles/src/serve/openssl_proxy/server.rs | 2 +- g3tiles/src/serve/rustls_proxy/server.rs | 2 +- lib/g3-daemon/src/stat/remote/tcp_connect.rs | 7 ++--- lib/g3-daemon/src/stat/task/tcp_stream.rs | 8 +----- lib/g3-io-ext/src/io/limited_stream.rs | 26 ++++++------------- 65 files changed, 127 insertions(+), 337 deletions(-) diff --git a/g3bench/src/target/h1/task.rs b/g3bench/src/target/h1/task.rs index 89640893b..fd297b751 100644 --- a/g3bench/src/target/h1/task.rs +++ b/g3bench/src/target/h1/task.rs @@ -25,7 +25,7 @@ use tokio::time::Instant; use g3_http::client::HttpForwardRemoteResponse; use g3_http::HttpBodyReader; -use g3_io_ext::{ArcLimitedReaderStats, ArcLimitedWriterStats, LimitedReader, LimitedWriter}; +use g3_io_ext::{LimitedReader, LimitedWriter}; use super::{ BenchHttpArgs, BenchTaskContext, HttpHistogramRecorder, HttpRuntimeStats, ProcArgs, @@ -103,13 +103,13 @@ impl HttpTaskContext { r, self.proc_args.tcp_sock_speed_limit.shift_millis, self.proc_args.tcp_sock_speed_limit.max_south, - self.runtime_stats.clone() as ArcLimitedReaderStats, + self.runtime_stats.clone() as _, ); let w = LimitedWriter::new( w, self.proc_args.tcp_sock_speed_limit.shift_millis, self.proc_args.tcp_sock_speed_limit.max_north, - self.runtime_stats.clone() as ArcLimitedWriterStats, + self.runtime_stats.clone() as _, ); Ok(SavedHttpForwardConnection::new(BufReader::new(r), w)) } diff --git a/g3proxy/src/escape/direct_fixed/ftp_connect/stats.rs b/g3proxy/src/escape/direct_fixed/ftp_connect/stats.rs index 5df21eb35..937c69972 100644 --- a/g3proxy/src/escape/direct_fixed/ftp_connect/stats.rs +++ b/g3proxy/src/escape/direct_fixed/ftp_connect/stats.rs @@ -45,16 +45,13 @@ impl FtpControlRemoteStats { pub(super) fn push_user_io_stats(&mut self, all: Vec>) { for s in all { - self.others.push(s as ArcFtpTaskRemoteControlStats); + self.others.push(s as _); } } pub(super) fn into_pair(self) -> (ArcLimitedReaderStats, ArcLimitedWriterStats) { let s = Arc::new(self); - ( - Arc::clone(&s) as ArcLimitedReaderStats, - s as ArcLimitedWriterStats, - ) + (Arc::clone(&s) as _, s as _) } } @@ -101,16 +98,13 @@ impl FtpTransferRemoteStats { pub(super) fn push_user_io_stats(&mut self, all: Vec>) { for s in all { - self.others.push(s as ArcFtpTaskRemoteTransferStats); + self.others.push(s as _); } } pub(super) fn into_pair(self) -> (ArcLimitedReaderStats, ArcLimitedWriterStats) { let s = Arc::new(self); - ( - Arc::clone(&s) as ArcLimitedReaderStats, - s as ArcLimitedWriterStats, - ) + (Arc::clone(&s) as _, s as _) } } diff --git a/g3proxy/src/escape/direct_fixed/http_forward/mod.rs b/g3proxy/src/escape/direct_fixed/http_forward/mod.rs index 6cb183963..22d74635e 100644 --- a/g3proxy/src/escape/direct_fixed/http_forward/mod.rs +++ b/g3proxy/src/escape/direct_fixed/http_forward/mod.rs @@ -58,7 +58,7 @@ impl DirectFixedEscaper { ups_r, limit_config.shift_millis, limit_config.max_south, - self.stats.for_limited_reader(), + self.stats.clone() as _, r_wrapper_stats.into_reader(), ); let ups_w = LimitedWriter::new( diff --git a/g3proxy/src/escape/direct_fixed/http_forward/stats.rs b/g3proxy/src/escape/direct_fixed/http_forward/stats.rs index f16c2ff6e..5bec8167a 100644 --- a/g3proxy/src/escape/direct_fixed/http_forward/stats.rs +++ b/g3proxy/src/escape/direct_fixed/http_forward/stats.rs @@ -43,13 +43,13 @@ impl DirectHttpMixedRemoteStats { pub(super) fn push_user_io_stats_by_ref(&mut self, all: &[Arc]) { for s in all { - self.others.push(s.clone() as ArcHttpForwardTaskRemoteStats); + self.others.push(s.clone() as _); } } pub(super) fn push_user_io_stats(&mut self, all: Vec>) { for s in all { - self.others.push(s as ArcHttpForwardTaskRemoteStats); + self.others.push(s as _); } } diff --git a/g3proxy/src/escape/direct_fixed/mod.rs b/g3proxy/src/escape/direct_fixed/mod.rs index bdb4bc4d5..56171f9c6 100644 --- a/g3proxy/src/escape/direct_fixed/mod.rs +++ b/g3proxy/src/escape/direct_fixed/mod.rs @@ -32,9 +32,7 @@ use g3_types::net::{Host, OpensslTlsClientConfig, UpstreamAddr}; use g3_types::resolve::{ResolveRedirection, ResolveStrategy}; use g3_types::route::EgressPathSelection; -use super::{ - ArcEscaper, ArcEscaperInternalStats, ArcEscaperStats, Escaper, EscaperInternal, EscaperStats, -}; +use super::{ArcEscaper, ArcEscaperStats, Escaper, EscaperInternal, EscaperStats}; use crate::auth::UserUpstreamTrafficStats; use crate::config::escaper::direct_fixed::DirectFixedEscaperConfig; use crate::config::escaper::{AnyEscaperConfig, EscaperConfig}; @@ -271,7 +269,7 @@ impl Escaper for DirectFixedEscaper { } fn get_escape_stats(&self) -> Option { - Some(Arc::clone(&self.stats) as ArcEscaperStats) + Some(Arc::clone(&self.stats) as _) } async fn publish(&self, _data: String) -> anyhow::Result<()> { @@ -328,10 +326,7 @@ impl Escaper for DirectFixedEscaper { } fn new_http_forward_context(&self, escaper: ArcEscaper) -> BoxHttpForwardContext { - let ctx = DirectHttpForwardContext::new( - Arc::clone(&self.stats) as ArcEscaperInternalStats, - escaper, - ); + let ctx = DirectHttpForwardContext::new(Arc::clone(&self.stats) as _, escaper); Box::new(ctx) } diff --git a/g3proxy/src/escape/direct_fixed/stats.rs b/g3proxy/src/escape/direct_fixed/stats.rs index 550d2d891..c6926600f 100644 --- a/g3proxy/src/escape/direct_fixed/stats.rs +++ b/g3proxy/src/escape/direct_fixed/stats.rs @@ -18,9 +18,7 @@ use std::sync::Arc; use arc_swap::ArcSwapOption; -use g3_io_ext::{ - ArcLimitedReaderStats, ArcLimitedWriterStats, LimitedReaderStats, LimitedWriterStats, -}; +use g3_io_ext::{LimitedReaderStats, LimitedWriterStats}; use g3_types::metrics::{MetricsName, StaticMetricsTags}; use g3_types::stats::{StatId, TcpIoSnapshot, UdpIoSnapshot}; @@ -52,16 +50,6 @@ impl DirectFixedEscaperStats { } } - #[inline] - pub(crate) fn for_limited_reader(self: &Arc) -> ArcLimitedReaderStats { - Arc::clone(self) as ArcLimitedReaderStats - } - - #[inline] - pub(crate) fn for_limited_writer(self: &Arc) -> ArcLimitedWriterStats { - Arc::clone(self) as ArcLimitedWriterStats - } - pub(super) fn set_extra_tags(&self, tags: Option>) { self.extra_metrics_tags.store(tags); } diff --git a/g3proxy/src/escape/direct_fixed/tcp_connect/stats.rs b/g3proxy/src/escape/direct_fixed/tcp_connect/stats.rs index f53e6c56d..0b642adf8 100644 --- a/g3proxy/src/escape/direct_fixed/tcp_connect/stats.rs +++ b/g3proxy/src/escape/direct_fixed/tcp_connect/stats.rs @@ -45,16 +45,13 @@ impl DirectTcpMixedRemoteStats { pub(super) fn push_user_io_stats(&mut self, all: Vec>) { for s in all { - self.others.push(s as ArcTcpConnectionTaskRemoteStats); + self.others.push(s as _); } } pub(super) fn into_pair(self) -> (ArcLimitedReaderStats, ArcLimitedWriterStats) { let s = Arc::new(self); - ( - Arc::clone(&s) as ArcLimitedReaderStats, - s as ArcLimitedWriterStats, - ) + (Arc::clone(&s) as _, s as _) } } diff --git a/g3proxy/src/escape/direct_fixed/tls_connect/mod.rs b/g3proxy/src/escape/direct_fixed/tls_connect/mod.rs index 52f1ed3c5..8028b82c1 100644 --- a/g3proxy/src/escape/direct_fixed/tls_connect/mod.rs +++ b/g3proxy/src/escape/direct_fixed/tls_connect/mod.rs @@ -54,13 +54,13 @@ impl DirectFixedEscaper { ups_r, limit_config.shift_millis, limit_config.max_south, - self.stats.for_limited_reader(), + self.stats.clone() as _, ); let ups_w = LimitedWriter::new( ups_w, limit_config.shift_millis, limit_config.max_north, - self.stats.for_limited_writer(), + self.stats.clone() as _, ); let ssl = tls_config diff --git a/g3proxy/src/escape/direct_fixed/udp_connect/stats.rs b/g3proxy/src/escape/direct_fixed/udp_connect/stats.rs index f8503d18a..bdb69c4b9 100644 --- a/g3proxy/src/escape/direct_fixed/udp_connect/stats.rs +++ b/g3proxy/src/escape/direct_fixed/udp_connect/stats.rs @@ -43,16 +43,13 @@ impl DirectUdpConnectRemoteStats { pub(super) fn push_user_io_stats(&mut self, all: Vec>) { for s in all { - self.others.push(s as ArcUdpConnectTaskRemoteStats); + self.others.push(s as _); } } pub(super) fn into_pair(self) -> (ArcLimitedRecvStats, ArcLimitedSendStats) { let s = Arc::new(self); - ( - Arc::clone(&s) as ArcLimitedRecvStats, - s as ArcLimitedSendStats, - ) + (Arc::clone(&s) as _, s as _) } } diff --git a/g3proxy/src/escape/direct_fixed/udp_relay/stats.rs b/g3proxy/src/escape/direct_fixed/udp_relay/stats.rs index f5145897b..36f621c37 100644 --- a/g3proxy/src/escape/direct_fixed/udp_relay/stats.rs +++ b/g3proxy/src/escape/direct_fixed/udp_relay/stats.rs @@ -43,16 +43,16 @@ impl DirectUdpRelayRemoteStats { pub(super) fn push_user_io_stats(&mut self, all: Vec>) { for s in all { - self.others.push(s as ArcUdpRelayTaskRemoteStats); + self.others.push(s as _); } } pub(super) fn for_recv(self: &Arc) -> ArcLimitedRecvStats { - Arc::clone(self) as ArcLimitedRecvStats + Arc::clone(self) as _ } pub(super) fn for_send(self: &Arc) -> ArcLimitedSendStats { - Arc::clone(self) as ArcLimitedSendStats + Arc::clone(self) as _ } } diff --git a/g3proxy/src/escape/direct_float/ftp_connect/stats.rs b/g3proxy/src/escape/direct_float/ftp_connect/stats.rs index 33d0b5ff8..12bbac203 100644 --- a/g3proxy/src/escape/direct_float/ftp_connect/stats.rs +++ b/g3proxy/src/escape/direct_float/ftp_connect/stats.rs @@ -45,16 +45,13 @@ impl FtpControlRemoteStats { pub(super) fn push_user_io_stats(&mut self, all: Vec>) { for s in all { - self.others.push(s as ArcFtpTaskRemoteControlStats); + self.others.push(s as _); } } pub(super) fn into_pair(self) -> (ArcLimitedReaderStats, ArcLimitedWriterStats) { let s = Arc::new(self); - ( - Arc::clone(&s) as ArcLimitedReaderStats, - s as ArcLimitedWriterStats, - ) + (Arc::clone(&s) as _, s as _) } } diff --git a/g3proxy/src/escape/direct_float/http_forward/mod.rs b/g3proxy/src/escape/direct_float/http_forward/mod.rs index f55da3cf9..bf3bcd79a 100644 --- a/g3proxy/src/escape/direct_float/http_forward/mod.rs +++ b/g3proxy/src/escape/direct_float/http_forward/mod.rs @@ -58,7 +58,7 @@ impl DirectFloatEscaper { ups_r, limit_config.shift_millis, limit_config.max_south, - self.stats.for_limited_reader(), + self.stats.clone() as _, r_wrapper_stats.into_reader(), ); let ups_w = LimitedWriter::new( diff --git a/g3proxy/src/escape/direct_float/stats.rs b/g3proxy/src/escape/direct_float/stats.rs index 6a7a2023e..c0318baf6 100644 --- a/g3proxy/src/escape/direct_float/stats.rs +++ b/g3proxy/src/escape/direct_float/stats.rs @@ -18,9 +18,7 @@ use std::sync::Arc; use arc_swap::ArcSwapOption; -use g3_io_ext::{ - ArcLimitedReaderStats, ArcLimitedWriterStats, LimitedReaderStats, LimitedWriterStats, -}; +use g3_io_ext::{LimitedReaderStats, LimitedWriterStats}; use g3_types::metrics::{MetricsName, StaticMetricsTags}; use g3_types::stats::{StatId, TcpIoSnapshot, UdpIoSnapshot}; @@ -52,16 +50,6 @@ impl DirectFloatEscaperStats { } } - #[inline] - pub(crate) fn for_limited_reader(self: &Arc) -> ArcLimitedReaderStats { - Arc::clone(self) as ArcLimitedReaderStats - } - - #[inline] - pub(crate) fn for_limited_writer(self: &Arc) -> ArcLimitedWriterStats { - Arc::clone(self) as ArcLimitedWriterStats - } - pub(super) fn set_extra_tags(&self, tags: Option>) { self.extra_metrics_tags.store(tags); } diff --git a/g3proxy/src/escape/direct_float/tcp_connect/stats.rs b/g3proxy/src/escape/direct_float/tcp_connect/stats.rs index f19504c94..5daa0b9a6 100644 --- a/g3proxy/src/escape/direct_float/tcp_connect/stats.rs +++ b/g3proxy/src/escape/direct_float/tcp_connect/stats.rs @@ -45,16 +45,13 @@ impl DirectTcpMixedRemoteStats { pub(super) fn push_user_io_stats(&mut self, all: Vec>) { for s in all { - self.others.push(s as ArcTcpConnectionTaskRemoteStats); + self.others.push(s as _); } } pub(super) fn into_pair(self) -> (ArcLimitedReaderStats, ArcLimitedWriterStats) { let s = Arc::new(self); - ( - Arc::clone(&s) as ArcLimitedReaderStats, - s as ArcLimitedWriterStats, - ) + (Arc::clone(&s) as _, s as _) } } diff --git a/g3proxy/src/escape/direct_float/tls_connect/mod.rs b/g3proxy/src/escape/direct_float/tls_connect/mod.rs index 7fcf3743c..faa2e399f 100644 --- a/g3proxy/src/escape/direct_float/tls_connect/mod.rs +++ b/g3proxy/src/escape/direct_float/tls_connect/mod.rs @@ -57,13 +57,13 @@ impl DirectFloatEscaper { ups_r, limit_config.shift_millis, limit_config.max_south, - self.stats.for_limited_reader(), + self.stats.clone() as _, ); let ups_w = LimitedWriter::new( ups_w, limit_config.shift_millis, limit_config.max_north, - self.stats.for_limited_writer(), + self.stats.clone() as _, ); let ssl = tls_config diff --git a/g3proxy/src/escape/dummy_deny/mod.rs b/g3proxy/src/escape/dummy_deny/mod.rs index c73b638de..eb79f3d0a 100644 --- a/g3proxy/src/escape/dummy_deny/mod.rs +++ b/g3proxy/src/escape/dummy_deny/mod.rs @@ -24,7 +24,7 @@ use g3_daemon::stat::remote::ArcTcpConnectionTaskRemoteStats; use g3_types::metrics::MetricsName; use g3_types::net::{OpensslTlsClientConfig, UpstreamAddr}; -use super::{ArcEscaper, ArcEscaperInternalStats, ArcEscaperStats, Escaper, EscaperInternal}; +use super::{ArcEscaper, ArcEscaperStats, Escaper, EscaperInternal}; use crate::config::escaper::dummy_deny::DummyDenyEscaperConfig; use crate::config::escaper::{AnyEscaperConfig, EscaperConfig}; use crate::module::ftp_over_http::{ @@ -99,7 +99,7 @@ impl Escaper for DummyDenyEscaper { } fn get_escape_stats(&self) -> Option { - Some(Arc::clone(&self.stats) as ArcEscaperStats) + Some(Arc::clone(&self.stats) as _) } async fn publish(&self, _data: String) -> anyhow::Result<()> { @@ -153,10 +153,7 @@ impl Escaper for DummyDenyEscaper { } fn new_http_forward_context(&self, escaper: ArcEscaper) -> BoxHttpForwardContext { - let ctx = DirectHttpForwardContext::new( - Arc::clone(&self.stats) as ArcEscaperInternalStats, - escaper, - ); + let ctx = DirectHttpForwardContext::new(Arc::clone(&self.stats) as _, escaper); Box::new(ctx) } diff --git a/g3proxy/src/escape/proxy_float/mod.rs b/g3proxy/src/escape/proxy_float/mod.rs index 67728ae81..0e422b802 100644 --- a/g3proxy/src/escape/proxy_float/mod.rs +++ b/g3proxy/src/escape/proxy_float/mod.rs @@ -30,7 +30,7 @@ use g3_daemon::stat::remote::ArcTcpConnectionTaskRemoteStats; use g3_types::metrics::MetricsName; use g3_types::net::{OpensslTlsClientConfig, UpstreamAddr}; -use super::{ArcEscaper, ArcEscaperInternalStats, ArcEscaperStats, Escaper, EscaperInternal}; +use super::{ArcEscaper, ArcEscaperStats, Escaper, EscaperInternal}; use crate::config::escaper::proxy_float::ProxyFloatEscaperConfig; use crate::config::escaper::{AnyEscaperConfig, EscaperConfig}; use crate::module::ftp_over_http::{ @@ -190,7 +190,7 @@ impl Escaper for ProxyFloatEscaper { } fn get_escape_stats(&self) -> Option { - Some(Arc::clone(&self.stats) as ArcEscaperStats) + Some(Arc::clone(&self.stats) as _) } async fn publish(&self, data: String) -> anyhow::Result<()> { @@ -272,10 +272,7 @@ impl Escaper for ProxyFloatEscaper { } fn new_http_forward_context(&self, escaper: ArcEscaper) -> BoxHttpForwardContext { - let ctx = DirectHttpForwardContext::new( - Arc::clone(&self.stats) as ArcEscaperInternalStats, - escaper, - ); + let ctx = DirectHttpForwardContext::new(Arc::clone(&self.stats) as _, escaper); Box::new(ctx) } diff --git a/g3proxy/src/escape/proxy_float/peer/http/tcp_connect/mod.rs b/g3proxy/src/escape/proxy_float/peer/http/tcp_connect/mod.rs index 0035b9f46..79f7ceeaa 100644 --- a/g3proxy/src/escape/proxy_float/peer/http/tcp_connect/mod.rs +++ b/g3proxy/src/escape/proxy_float/peer/http/tcp_connect/mod.rs @@ -120,13 +120,13 @@ impl ProxyFloatHttpPeer { r, limit_config.shift_millis, limit_config.max_south, - self.escaper_stats.for_limited_reader(), + self.escaper_stats.clone() as _, ); let w = LimitedWriter::new( w, limit_config.shift_millis, limit_config.max_north, - self.escaper_stats.for_limited_writer(), + self.escaper_stats.clone() as _, ); Ok((r, w)) diff --git a/g3proxy/src/escape/proxy_float/peer/https/tcp_connect/mod.rs b/g3proxy/src/escape/proxy_float/peer/https/tcp_connect/mod.rs index 256764b86..8f304a6b2 100644 --- a/g3proxy/src/escape/proxy_float/peer/https/tcp_connect/mod.rs +++ b/g3proxy/src/escape/proxy_float/peer/https/tcp_connect/mod.rs @@ -120,13 +120,13 @@ impl ProxyFloatHttpsPeer { r, limit_config.shift_millis, limit_config.max_south, - self.escaper_stats.for_limited_reader(), + self.escaper_stats.clone() as _, ); let w = LimitedWriter::new( w, limit_config.shift_millis, limit_config.max_north, - self.escaper_stats.for_limited_writer(), + self.escaper_stats.clone() as _, ); Ok((r, w)) diff --git a/g3proxy/src/escape/proxy_float/peer/socks5/tcp_connect/mod.rs b/g3proxy/src/escape/proxy_float/peer/socks5/tcp_connect/mod.rs index 0bd126b08..eb22d938a 100644 --- a/g3proxy/src/escape/proxy_float/peer/socks5/tcp_connect/mod.rs +++ b/g3proxy/src/escape/proxy_float/peer/socks5/tcp_connect/mod.rs @@ -120,13 +120,13 @@ impl ProxyFloatSocks5Peer { r, limit_config.shift_millis, limit_config.max_south, - self.escaper_stats.for_limited_reader(), + self.escaper_stats.clone() as _, ); let w = LimitedWriter::new( w, limit_config.shift_millis, limit_config.max_north, - self.escaper_stats.for_limited_writer(), + self.escaper_stats.clone() as _, ); Ok((r, w)) diff --git a/g3proxy/src/escape/proxy_float/stats/escaper.rs b/g3proxy/src/escape/proxy_float/stats/escaper.rs index 8213e2e0b..cf3e6b7e2 100644 --- a/g3proxy/src/escape/proxy_float/stats/escaper.rs +++ b/g3proxy/src/escape/proxy_float/stats/escaper.rs @@ -18,9 +18,7 @@ use std::sync::Arc; use arc_swap::ArcSwapOption; -use g3_io_ext::{ - ArcLimitedReaderStats, ArcLimitedWriterStats, LimitedReaderStats, LimitedWriterStats, -}; +use g3_io_ext::{LimitedReaderStats, LimitedWriterStats}; use g3_types::metrics::{MetricsName, StaticMetricsTags}; use g3_types::stats::{StatId, TcpIoSnapshot, UdpIoSnapshot}; @@ -51,16 +49,6 @@ impl ProxyFloatEscaperStats { } } - #[inline] - pub(crate) fn for_limited_reader(self: &Arc) -> ArcLimitedReaderStats { - Arc::clone(self) as ArcLimitedReaderStats - } - - #[inline] - pub(crate) fn for_limited_writer(self: &Arc) -> ArcLimitedWriterStats { - Arc::clone(self) as ArcLimitedWriterStats - } - pub(crate) fn set_extra_tags(&self, tags: Option>) { self.extra_metrics_tags.store(tags); } diff --git a/g3proxy/src/escape/proxy_float/stats/wrapper/http.rs b/g3proxy/src/escape/proxy_float/stats/wrapper/http.rs index 6aebbdd20..8851469f9 100644 --- a/g3proxy/src/escape/proxy_float/stats/wrapper/http.rs +++ b/g3proxy/src/escape/proxy_float/stats/wrapper/http.rs @@ -43,13 +43,13 @@ impl ProxyHttpMixedRemoteStats { pub(crate) fn push_user_io_stats_by_ref(&mut self, all: &[Arc]) { for s in all { - self.others.push(s.clone() as ArcHttpForwardTaskRemoteStats); + self.others.push(s.clone() as _); } } pub(crate) fn push_user_io_stats(&mut self, all: Vec>) { for s in all { - self.others.push(s.clone() as ArcHttpForwardTaskRemoteStats); + self.others.push(s.clone() as _); } } diff --git a/g3proxy/src/escape/proxy_float/stats/wrapper/tcp.rs b/g3proxy/src/escape/proxy_float/stats/wrapper/tcp.rs index 3e0f8d3eb..4c5b33f6e 100644 --- a/g3proxy/src/escape/proxy_float/stats/wrapper/tcp.rs +++ b/g3proxy/src/escape/proxy_float/stats/wrapper/tcp.rs @@ -45,16 +45,13 @@ impl ProxyTcpRemoteStats { pub(crate) fn push_user_io_stats(&mut self, all: Vec>) { for s in all { - self.others.push(s as ArcTcpConnectionTaskRemoteStats); + self.others.push(s as _); } } pub(crate) fn into_pair(self) -> (ArcLimitedReaderStats, ArcLimitedWriterStats) { let s = Arc::new(self); - ( - Arc::clone(&s) as ArcLimitedReaderStats, - s as ArcLimitedWriterStats, - ) + (Arc::clone(&s) as _, s as _) } } diff --git a/g3proxy/src/escape/proxy_http/http_connect/stats.rs b/g3proxy/src/escape/proxy_http/http_connect/stats.rs index 45246150b..7783152b4 100644 --- a/g3proxy/src/escape/proxy_http/http_connect/stats.rs +++ b/g3proxy/src/escape/proxy_http/http_connect/stats.rs @@ -45,16 +45,13 @@ impl ProxyTcpMixedRemoteStats { pub(super) fn push_user_io_stats(&mut self, all: Vec>) { for s in all { - self.others.push(s as ArcTcpConnectionTaskRemoteStats); + self.others.push(s as _); } } pub(super) fn into_pair(self) -> (ArcLimitedReaderStats, ArcLimitedWriterStats) { let s = Arc::new(self); - ( - Arc::clone(&s) as ArcLimitedReaderStats, - s as ArcLimitedWriterStats, - ) + (Arc::clone(&s) as _, s as _) } } diff --git a/g3proxy/src/escape/proxy_http/http_forward/stats.rs b/g3proxy/src/escape/proxy_http/http_forward/stats.rs index 35e826b4d..57767a25d 100644 --- a/g3proxy/src/escape/proxy_http/http_forward/stats.rs +++ b/g3proxy/src/escape/proxy_http/http_forward/stats.rs @@ -43,13 +43,13 @@ impl ProxyHttpMixedRemoteStats { pub(super) fn push_user_io_stats_by_ref(&mut self, all: &[Arc]) { for s in all { - self.others.push(s.clone() as ArcHttpForwardTaskRemoteStats); + self.others.push(s.clone() as _); } } pub(super) fn push_user_io_stats(&mut self, all: Vec>) { for s in all { - self.others.push(s as ArcHttpForwardTaskRemoteStats); + self.others.push(s as _); } } diff --git a/g3proxy/src/escape/proxy_http/mod.rs b/g3proxy/src/escape/proxy_http/mod.rs index 2fdb9e3ff..48ed2facc 100644 --- a/g3proxy/src/escape/proxy_http/mod.rs +++ b/g3proxy/src/escape/proxy_http/mod.rs @@ -29,10 +29,7 @@ use g3_types::net::{ Host, HttpForwardCapability, OpensslTlsClientConfig, UpstreamAddr, WeightedUpstreamAddr, }; -use super::{ - ArcEscaper, ArcEscaperInternalStats, ArcEscaperStats, Escaper, EscaperExt, EscaperInternal, - EscaperStats, -}; +use super::{ArcEscaper, ArcEscaperStats, Escaper, EscaperExt, EscaperInternal, EscaperStats}; use crate::auth::UserUpstreamTrafficStats; use crate::config::escaper::proxy_http::ProxyHttpEscaperConfig; use crate::config::escaper::{AnyEscaperConfig, EscaperConfig}; @@ -171,7 +168,7 @@ impl Escaper for ProxyHttpEscaper { } fn get_escape_stats(&self) -> Option { - Some(Arc::clone(&self.stats) as ArcEscaperStats) + Some(Arc::clone(&self.stats) as _) } async fn publish(&self, _data: String) -> anyhow::Result<()> { @@ -229,10 +226,7 @@ impl Escaper for ProxyHttpEscaper { } fn new_http_forward_context(&self, escaper: ArcEscaper) -> BoxHttpForwardContext { - let ctx = ProxyHttpForwardContext::new( - Arc::clone(&self.stats) as ArcEscaperInternalStats, - escaper, - ); + let ctx = ProxyHttpForwardContext::new(Arc::clone(&self.stats) as _, escaper); Box::new(ctx) } diff --git a/g3proxy/src/escape/proxy_http/stats.rs b/g3proxy/src/escape/proxy_http/stats.rs index 68adea6b7..146dd8810 100644 --- a/g3proxy/src/escape/proxy_http/stats.rs +++ b/g3proxy/src/escape/proxy_http/stats.rs @@ -18,9 +18,7 @@ use std::sync::Arc; use arc_swap::ArcSwapOption; -use g3_io_ext::{ - ArcLimitedReaderStats, ArcLimitedWriterStats, LimitedReaderStats, LimitedWriterStats, -}; +use g3_io_ext::{LimitedReaderStats, LimitedWriterStats}; use g3_types::metrics::{MetricsName, StaticMetricsTags}; use g3_types::stats::{StatId, TcpIoSnapshot}; @@ -45,16 +43,6 @@ impl ProxyHttpEscaperStats { } } - #[inline] - pub(crate) fn for_limited_reader(self: &Arc) -> ArcLimitedReaderStats { - Arc::clone(self) as ArcLimitedReaderStats - } - - #[inline] - pub(crate) fn for_limited_writer(self: &Arc) -> ArcLimitedWriterStats { - Arc::clone(self) as ArcLimitedWriterStats - } - pub(super) fn set_extra_tags(&self, tags: Option>) { self.extra_metrics_tags.store(tags); } diff --git a/g3proxy/src/escape/proxy_http/tcp_connect/mod.rs b/g3proxy/src/escape/proxy_http/tcp_connect/mod.rs index 44c601023..f84aef84f 100644 --- a/g3proxy/src/escape/proxy_http/tcp_connect/mod.rs +++ b/g3proxy/src/escape/proxy_http/tcp_connect/mod.rs @@ -307,13 +307,13 @@ impl ProxyHttpEscaper { r, limit_config.shift_millis, limit_config.max_south, - self.stats.for_limited_reader(), + self.stats.clone() as _, ); let mut w = LimitedWriter::new( w, limit_config.shift_millis, limit_config.max_north, - self.stats.for_limited_writer(), + self.stats.clone() as _, ); if let Some(version) = self.config.use_proxy_protocol { diff --git a/g3proxy/src/escape/proxy_https/mod.rs b/g3proxy/src/escape/proxy_https/mod.rs index ad27cc25f..0c03810be 100644 --- a/g3proxy/src/escape/proxy_https/mod.rs +++ b/g3proxy/src/escape/proxy_https/mod.rs @@ -29,10 +29,7 @@ use g3_types::net::{ Host, HttpForwardCapability, OpensslTlsClientConfig, UpstreamAddr, WeightedUpstreamAddr, }; -use super::{ - ArcEscaper, ArcEscaperInternalStats, ArcEscaperStats, Escaper, EscaperExt, EscaperInternal, - EscaperStats, -}; +use super::{ArcEscaper, ArcEscaperStats, Escaper, EscaperExt, EscaperInternal, EscaperStats}; use crate::auth::UserUpstreamTrafficStats; use crate::config::escaper::proxy_https::ProxyHttpsEscaperConfig; use crate::config::escaper::{AnyEscaperConfig, EscaperConfig}; @@ -178,7 +175,7 @@ impl Escaper for ProxyHttpsEscaper { } fn get_escape_stats(&self) -> Option { - Some(Arc::clone(&self.stats) as ArcEscaperStats) + Some(Arc::clone(&self.stats) as _) } async fn publish(&self, _data: String) -> anyhow::Result<()> { @@ -236,10 +233,7 @@ impl Escaper for ProxyHttpsEscaper { } fn new_http_forward_context(&self, escaper: ArcEscaper) -> BoxHttpForwardContext { - let ctx = ProxyHttpForwardContext::new( - Arc::clone(&self.stats) as ArcEscaperInternalStats, - escaper, - ); + let ctx = ProxyHttpForwardContext::new(Arc::clone(&self.stats) as _, escaper); Box::new(ctx) } diff --git a/g3proxy/src/escape/proxy_https/stats.rs b/g3proxy/src/escape/proxy_https/stats.rs index cca9e94c2..b5d12584b 100644 --- a/g3proxy/src/escape/proxy_https/stats.rs +++ b/g3proxy/src/escape/proxy_https/stats.rs @@ -18,9 +18,7 @@ use std::sync::Arc; use arc_swap::ArcSwapOption; -use g3_io_ext::{ - ArcLimitedReaderStats, ArcLimitedWriterStats, LimitedReaderStats, LimitedWriterStats, -}; +use g3_io_ext::{LimitedReaderStats, LimitedWriterStats}; use g3_types::metrics::{MetricsName, StaticMetricsTags}; use g3_types::stats::{StatId, TcpIoSnapshot}; @@ -45,16 +43,6 @@ impl ProxyHttpsEscaperStats { } } - #[inline] - pub(crate) fn for_limited_reader(self: &Arc) -> ArcLimitedReaderStats { - Arc::clone(self) as ArcLimitedReaderStats - } - - #[inline] - pub(crate) fn for_limited_writer(self: &Arc) -> ArcLimitedWriterStats { - Arc::clone(self) as ArcLimitedWriterStats - } - pub(super) fn set_extra_tags(&self, tags: Option>) { self.extra_metrics_tags.store(tags); } diff --git a/g3proxy/src/escape/proxy_https/tcp_connect/mod.rs b/g3proxy/src/escape/proxy_https/tcp_connect/mod.rs index 308d40d1d..c34d9d20c 100644 --- a/g3proxy/src/escape/proxy_https/tcp_connect/mod.rs +++ b/g3proxy/src/escape/proxy_https/tcp_connect/mod.rs @@ -312,13 +312,13 @@ impl ProxyHttpsEscaper { r, limit_config.shift_millis, limit_config.max_south, - self.stats.for_limited_reader(), + self.stats.clone() as _, ); let mut w = LimitedWriter::new( w, limit_config.shift_millis, limit_config.max_north, - self.stats.for_limited_writer(), + self.stats.clone() as _, ); if let Some(version) = self.config.use_proxy_protocol { diff --git a/g3proxy/src/escape/proxy_socks5/stats.rs b/g3proxy/src/escape/proxy_socks5/stats.rs index 37570732e..cdd4ad157 100644 --- a/g3proxy/src/escape/proxy_socks5/stats.rs +++ b/g3proxy/src/escape/proxy_socks5/stats.rs @@ -18,9 +18,7 @@ use std::sync::Arc; use arc_swap::ArcSwapOption; -use g3_io_ext::{ - ArcLimitedReaderStats, ArcLimitedWriterStats, LimitedReaderStats, LimitedWriterStats, -}; +use g3_io_ext::{LimitedReaderStats, LimitedWriterStats}; use g3_types::metrics::{MetricsName, StaticMetricsTags}; use g3_types::stats::{StatId, TcpIoSnapshot, UdpIoSnapshot}; @@ -51,16 +49,6 @@ impl ProxySocks5EscaperStats { } } - #[inline] - pub(crate) fn for_limited_reader(self: &Arc) -> ArcLimitedReaderStats { - Arc::clone(self) as ArcLimitedReaderStats - } - - #[inline] - pub(crate) fn for_limited_writer(self: &Arc) -> ArcLimitedWriterStats { - Arc::clone(self) as ArcLimitedWriterStats - } - pub(super) fn set_extra_tags(&self, tags: Option>) { self.extra_metrics_tags.store(tags); } diff --git a/g3proxy/src/escape/proxy_socks5/tcp_connect/mod.rs b/g3proxy/src/escape/proxy_socks5/tcp_connect/mod.rs index 3f5881c1d..d53299586 100644 --- a/g3proxy/src/escape/proxy_socks5/tcp_connect/mod.rs +++ b/g3proxy/src/escape/proxy_socks5/tcp_connect/mod.rs @@ -306,13 +306,13 @@ impl ProxySocks5Escaper { r, limit_config.shift_millis, limit_config.max_south, - self.stats.for_limited_reader(), + self.stats.clone() as _, ); let w = LimitedWriter::new( w, limit_config.shift_millis, limit_config.max_north, - self.stats.for_limited_writer(), + self.stats.clone() as _, ); Ok((r, w)) diff --git a/g3proxy/src/serve/http_proxy/server.rs b/g3proxy/src/serve/http_proxy/server.rs index 5e90b10bd..190e71c6c 100644 --- a/g3proxy/src/serve/http_proxy/server.rs +++ b/g3proxy/src/serve/http_proxy/server.rs @@ -339,7 +339,7 @@ impl Server for HttpProxyServer { } fn get_server_stats(&self) -> Option { - Some(Arc::clone(&self.server_stats) as ArcServerStats) + Some(Arc::clone(&self.server_stats) as _) } fn get_listen_stats(&self) -> Arc { diff --git a/g3proxy/src/serve/http_proxy/task/connect/stats/wrapper.rs b/g3proxy/src/serve/http_proxy/task/connect/stats/wrapper.rs index 4746080b6..9f3473400 100644 --- a/g3proxy/src/serve/http_proxy/task/connect/stats/wrapper.rs +++ b/g3proxy/src/serve/http_proxy/task/connect/stats/wrapper.rs @@ -59,16 +59,13 @@ impl TcpConnectTaskCltWrapperStats { pub(crate) fn push_user_io_stats(&mut self, all: Vec>) { for s in all { - self.others.push(s as ArcTcpConnectTaskCltStatsWrapper); + self.others.push(s as _); } } pub(crate) fn split(self) -> (ArcLimitedReaderStats, ArcLimitedWriterStats) { let s = Arc::new(self); - ( - Arc::clone(&s) as ArcLimitedReaderStats, - s as ArcLimitedWriterStats, - ) + (Arc::clone(&s) as _, s as _) } } diff --git a/g3proxy/src/serve/http_proxy/task/connect/task.rs b/g3proxy/src/serve/http_proxy/task/connect/task.rs index 48528ea04..9cda3292e 100644 --- a/g3proxy/src/serve/http_proxy/task/connect/task.rs +++ b/g3proxy/src/serve/http_proxy/task/connect/task.rs @@ -326,7 +326,7 @@ impl HttpProxyConnectTask { .tcp_setup_connection( &mut self.tcp_notes, &self.task_notes, - self.task_stats.for_escaper(), + self.task_stats.clone() as _, ) .await { diff --git a/g3proxy/src/serve/http_proxy/task/forward/stats/task.rs b/g3proxy/src/serve/http_proxy/task/forward/stats/task.rs index c1e420354..3f1f591af 100644 --- a/g3proxy/src/serve/http_proxy/task/forward/stats/task.rs +++ b/g3proxy/src/serve/http_proxy/task/forward/stats/task.rs @@ -14,11 +14,9 @@ * limitations under the License. */ -use std::sync::Arc; - use g3_daemon::stat::task::TcpStreamConnectionStats; -use crate::module::http_forward::{ArcHttpForwardTaskRemoteStats, HttpForwardTaskRemoteStats}; +use crate::module::http_forward::HttpForwardTaskRemoteStats; #[derive(Default)] pub(crate) struct HttpForwardTaskStats { @@ -26,13 +24,6 @@ pub(crate) struct HttpForwardTaskStats { pub(crate) ups: TcpStreamConnectionStats, } -impl HttpForwardTaskStats { - #[inline] - pub(crate) fn for_escaper(self: &Arc) -> ArcHttpForwardTaskRemoteStats { - Arc::clone(self) as ArcHttpForwardTaskRemoteStats - } -} - impl HttpForwardTaskRemoteStats for HttpForwardTaskStats { fn add_read_bytes(&self, size: u64) { self.ups.read.add_bytes(size); diff --git a/g3proxy/src/serve/http_proxy/task/forward/stats/wrapper.rs b/g3proxy/src/serve/http_proxy/task/forward/stats/wrapper.rs index 1ac2d6c5d..5a82c8544 100644 --- a/g3proxy/src/serve/http_proxy/task/forward/stats/wrapper.rs +++ b/g3proxy/src/serve/http_proxy/task/forward/stats/wrapper.rs @@ -71,16 +71,13 @@ impl HttpForwardTaskCltWrapperStats { pub(crate) fn push_user_io_stats(&mut self, all: Vec>) { for s in all { - self.others.push(s as ArcHttpForwardTaskCltStatsWrapper); + self.others.push(s as _); } } pub(crate) fn split(self) -> (ArcLimitedReaderStats, ArcLimitedWriterStats) { let s = Arc::new(self); - ( - Arc::clone(&s) as ArcLimitedReaderStats, - s as ArcLimitedWriterStats, - ) + (Arc::clone(&s) as _, s as _) } } @@ -131,10 +128,7 @@ impl HttpsForwardTaskCltWrapperStats { pub(crate) fn split(self) -> (ArcLimitedReaderStats, ArcLimitedWriterStats) { let s = Arc::new(self); - ( - Arc::clone(&s) as ArcLimitedReaderStats, - s as ArcLimitedWriterStats, - ) + (Arc::clone(&s) as _, s as _) } } diff --git a/g3proxy/src/serve/http_proxy/task/forward/task.rs b/g3proxy/src/serve/http_proxy/task/forward/task.rs index c33e32b7c..bfe4829ac 100644 --- a/g3proxy/src/serve/http_proxy/task/forward/task.rs +++ b/g3proxy/src/serve/http_proxy/task/forward/task.rs @@ -603,7 +603,7 @@ impl<'a> HttpProxyForwardTask<'a> { if let Some(connection) = fwd_ctx .get_alive_connection( &self.task_notes, - self.task_stats.for_escaper(), + self.task_stats.clone() as _, upstream_keepalive.idle_expire(), ) .await @@ -695,14 +695,14 @@ impl<'a> HttpProxyForwardTask<'a> { fwd_ctx .make_new_https_connection( &self.task_notes, - self.task_stats.for_escaper(), + self.task_stats.clone() as _, &self.ctx.tls_client_config, &tls_name, ) .await } else { fwd_ctx - .make_new_http_connection(&self.task_notes, self.task_stats.for_escaper()) + .make_new_http_connection(&self.task_notes, self.task_stats.clone() as _) .await } } diff --git a/g3proxy/src/serve/http_proxy/task/ftp/connection.rs b/g3proxy/src/serve/http_proxy/task/ftp/connection.rs index 0c2f8fbb4..19d5be7bd 100644 --- a/g3proxy/src/serve/http_proxy/task/ftp/connection.rs +++ b/g3proxy/src/serve/http_proxy/task/ftp/connection.rs @@ -22,10 +22,7 @@ use g3_ftp_client::FtpConnectionProvider; use g3_types::net::UpstreamAddr; use super::FtpOverHttpTaskStats; -use crate::module::ftp_over_http::{ - ArcFtpTaskRemoteControlStats, ArcFtpTaskRemoteTransferStats, BoxFtpConnectContext, - BoxFtpRemoteConnection, -}; +use crate::module::ftp_over_http::{BoxFtpConnectContext, BoxFtpRemoteConnection}; use crate::module::tcp_connect::TcpConnectError; use crate::serve::ServerTaskNotes; @@ -61,10 +58,7 @@ impl FtpConnectionProvider Result { self.connect_context - .new_control_connection( - task_notes, - Arc::clone(&self.task_stats) as ArcFtpTaskRemoteControlStats, - ) + .new_control_connection(task_notes, Arc::clone(&self.task_stats) as _) .await } @@ -74,11 +68,7 @@ impl FtpConnectionProvider Result { self.connect_context - .new_transfer_connection( - server_addr, - task_notes, - Arc::clone(&self.task_stats) as ArcFtpTaskRemoteTransferStats, - ) + .new_transfer_connection(server_addr, task_notes, Arc::clone(&self.task_stats) as _) .await } } diff --git a/g3proxy/src/serve/http_proxy/task/ftp/stats/wrapper.rs b/g3proxy/src/serve/http_proxy/task/ftp/stats/wrapper.rs index 2387e51d3..acd493137 100644 --- a/g3proxy/src/serve/http_proxy/task/ftp/stats/wrapper.rs +++ b/g3proxy/src/serve/http_proxy/task/ftp/stats/wrapper.rs @@ -61,16 +61,13 @@ impl FtpOverHttpTaskCltWrapperStats { pub(crate) fn push_user_io_stats(&mut self, all: Vec>) { for s in all { - self.others.push(s as ArcFtpOverHttpTaskCltStatsWrapper); + self.others.push(s as _); } } pub(crate) fn split(self) -> (ArcLimitedReaderStats, ArcLimitedWriterStats) { let s = Arc::new(self); - ( - Arc::clone(&s) as ArcLimitedReaderStats, - s as ArcLimitedWriterStats, - ) + (Arc::clone(&s) as _, s as _) } } diff --git a/g3proxy/src/serve/http_rproxy/server.rs b/g3proxy/src/serve/http_rproxy/server.rs index 731a4f851..74a142fe5 100644 --- a/g3proxy/src/serve/http_rproxy/server.rs +++ b/g3proxy/src/serve/http_rproxy/server.rs @@ -321,7 +321,7 @@ impl Server for HttpRProxyServer { } fn get_server_stats(&self) -> Option { - Some(Arc::clone(&self.server_stats) as ArcServerStats) + Some(Arc::clone(&self.server_stats) as _) } fn get_listen_stats(&self) -> Arc { diff --git a/g3proxy/src/serve/http_rproxy/task/forward/stats/task.rs b/g3proxy/src/serve/http_rproxy/task/forward/stats/task.rs index c1e420354..3f1f591af 100644 --- a/g3proxy/src/serve/http_rproxy/task/forward/stats/task.rs +++ b/g3proxy/src/serve/http_rproxy/task/forward/stats/task.rs @@ -14,11 +14,9 @@ * limitations under the License. */ -use std::sync::Arc; - use g3_daemon::stat::task::TcpStreamConnectionStats; -use crate::module::http_forward::{ArcHttpForwardTaskRemoteStats, HttpForwardTaskRemoteStats}; +use crate::module::http_forward::HttpForwardTaskRemoteStats; #[derive(Default)] pub(crate) struct HttpForwardTaskStats { @@ -26,13 +24,6 @@ pub(crate) struct HttpForwardTaskStats { pub(crate) ups: TcpStreamConnectionStats, } -impl HttpForwardTaskStats { - #[inline] - pub(crate) fn for_escaper(self: &Arc) -> ArcHttpForwardTaskRemoteStats { - Arc::clone(self) as ArcHttpForwardTaskRemoteStats - } -} - impl HttpForwardTaskRemoteStats for HttpForwardTaskStats { fn add_read_bytes(&self, size: u64) { self.ups.read.add_bytes(size); diff --git a/g3proxy/src/serve/http_rproxy/task/forward/stats/wrapper.rs b/g3proxy/src/serve/http_rproxy/task/forward/stats/wrapper.rs index eaaab12ef..a6580b15d 100644 --- a/g3proxy/src/serve/http_rproxy/task/forward/stats/wrapper.rs +++ b/g3proxy/src/serve/http_rproxy/task/forward/stats/wrapper.rs @@ -71,16 +71,13 @@ impl HttpForwardTaskCltWrapperStats { pub(crate) fn push_user_io_stats(&mut self, all: Vec>) { for s in all { - self.others.push(s as ArcHttpForwardTaskCltStatsWrapper); + self.others.push(s as _); } } pub(crate) fn split(self) -> (ArcLimitedReaderStats, ArcLimitedWriterStats) { let s = Arc::new(self); - ( - Arc::clone(&s) as ArcLimitedReaderStats, - s as ArcLimitedWriterStats, - ) + (Arc::clone(&s) as _, s as _) } } @@ -125,16 +122,13 @@ impl HttpsForwardTaskCltWrapperStats { pub(crate) fn push_user_io_stats(&mut self, all: Vec>) { for s in all { - self.others.push(s as ArcHttpForwardTaskCltStatsWrapper); + self.others.push(s as _); } } pub(crate) fn split(self) -> (ArcLimitedReaderStats, ArcLimitedWriterStats) { let s = Arc::new(self); - ( - Arc::clone(&s) as ArcLimitedReaderStats, - s as ArcLimitedWriterStats, - ) + (Arc::clone(&s) as _, s as _) } } diff --git a/g3proxy/src/serve/http_rproxy/task/forward/task.rs b/g3proxy/src/serve/http_rproxy/task/forward/task.rs index 7ff2b246f..0b68223fa 100644 --- a/g3proxy/src/serve/http_rproxy/task/forward/task.rs +++ b/g3proxy/src/serve/http_rproxy/task/forward/task.rs @@ -499,7 +499,7 @@ impl<'a> HttpRProxyForwardTask<'a> { if let Some(connection) = fwd_ctx .get_alive_connection( &self.task_notes, - self.task_stats.for_escaper(), + self.task_stats.clone() as _, upstream_keepalive.idle_expire(), ) .await @@ -584,14 +584,14 @@ impl<'a> HttpRProxyForwardTask<'a> { fwd_ctx .make_new_https_connection( &self.task_notes, - self.task_stats.for_escaper(), + self.task_stats.clone() as _, tls_client, &self.host.config.tls_name, ) .await } else { fwd_ctx - .make_new_http_connection(&self.task_notes, self.task_stats.for_escaper()) + .make_new_http_connection(&self.task_notes, self.task_stats.clone() as _) .await } } diff --git a/g3proxy/src/serve/sni_proxy/server.rs b/g3proxy/src/serve/sni_proxy/server.rs index 4441dfb50..4864d79ee 100644 --- a/g3proxy/src/serve/sni_proxy/server.rs +++ b/g3proxy/src/serve/sni_proxy/server.rs @@ -243,7 +243,7 @@ impl Server for SniProxyServer { } fn get_server_stats(&self) -> Option { - Some(Arc::clone(&self.server_stats) as ArcServerStats) + Some(Arc::clone(&self.server_stats) as _) } fn get_listen_stats(&self) -> Arc { diff --git a/g3proxy/src/serve/sni_proxy/task/relay/task.rs b/g3proxy/src/serve/sni_proxy/task/relay/task.rs index d8c31985b..36ad30176 100644 --- a/g3proxy/src/serve/sni_proxy/task/relay/task.rs +++ b/g3proxy/src/serve/sni_proxy/task/relay/task.rs @@ -141,7 +141,7 @@ impl TcpStreamTask { .tcp_setup_connection( &mut self.tcp_notes, &self.task_notes, - self.task_stats.for_escaper(), + self.task_stats.clone() as _, ) .await?; diff --git a/g3proxy/src/serve/socks_proxy/server.rs b/g3proxy/src/serve/socks_proxy/server.rs index 96fe2ce3b..0a6f83721 100644 --- a/g3proxy/src/serve/socks_proxy/server.rs +++ b/g3proxy/src/serve/socks_proxy/server.rs @@ -250,7 +250,7 @@ impl Server for SocksProxyServer { } fn get_server_stats(&self) -> Option { - Some(Arc::clone(&self.server_stats) as ArcServerStats) + Some(Arc::clone(&self.server_stats) as _) } fn get_listen_stats(&self) -> Arc { diff --git a/g3proxy/src/serve/socks_proxy/task/tcp_connect/stats/wrapper.rs b/g3proxy/src/serve/socks_proxy/task/tcp_connect/stats/wrapper.rs index 4aa2563d7..2d053f8e7 100644 --- a/g3proxy/src/serve/socks_proxy/task/tcp_connect/stats/wrapper.rs +++ b/g3proxy/src/serve/socks_proxy/task/tcp_connect/stats/wrapper.rs @@ -59,16 +59,13 @@ impl TcpConnectTaskCltWrapperStats { pub(crate) fn push_user_io_stats(&mut self, all: Vec>) { for s in all { - self.others.push(s as ArcTcpConnectTaskCltStatsWrapper); + self.others.push(s as _); } } pub(crate) fn split(self) -> (ArcLimitedReaderStats, ArcLimitedWriterStats) { let s = Arc::new(self); - ( - Arc::clone(&s) as ArcLimitedReaderStats, - s as ArcLimitedWriterStats, - ) + (Arc::clone(&s) as _, s as _) } } diff --git a/g3proxy/src/serve/socks_proxy/task/tcp_connect/task.rs b/g3proxy/src/serve/socks_proxy/task/tcp_connect/task.rs index ca32c5d2d..67cbcd85e 100644 --- a/g3proxy/src/serve/socks_proxy/task/tcp_connect/task.rs +++ b/g3proxy/src/serve/socks_proxy/task/tcp_connect/task.rs @@ -278,7 +278,7 @@ impl SocksProxyTcpConnectTask { .tcp_setup_connection( &mut self.tcp_notes, &self.task_notes, - self.task_stats.for_escaper(), + self.task_stats.clone() as _, ) .await { diff --git a/g3proxy/src/serve/socks_proxy/task/udp_associate/stats/task.rs b/g3proxy/src/serve/socks_proxy/task/udp_associate/stats/task.rs index c4f719a46..501abfa90 100644 --- a/g3proxy/src/serve/socks_proxy/task/udp_associate/stats/task.rs +++ b/g3proxy/src/serve/socks_proxy/task/udp_associate/stats/task.rs @@ -15,11 +15,10 @@ */ use std::sync::atomic::{AtomicU64, Ordering}; -use std::sync::Arc; use g3_daemon::stat::task::UdpConnectHalfConnectionStats; -use crate::module::udp_relay::{ArcUdpRelayTaskRemoteStats, UdpRelayTaskRemoteStats}; +use crate::module::udp_relay::UdpRelayTaskRemoteStats; #[derive(Default)] pub(crate) struct UdpAssociateClientSideStats { @@ -63,13 +62,6 @@ pub(crate) struct UdpAssociateTaskStats { pub(crate) ups: UdpAssociateRemoteSideStats, } -impl UdpAssociateTaskStats { - #[inline] - pub(crate) fn for_escaper(self: &Arc) -> ArcUdpRelayTaskRemoteStats { - Arc::clone(self) as ArcUdpRelayTaskRemoteStats - } -} - impl UdpRelayTaskRemoteStats for UdpAssociateTaskStats { fn add_recv_bytes(&self, size: u64) { self.ups.recv.add_bytes(size); diff --git a/g3proxy/src/serve/socks_proxy/task/udp_associate/stats/wrapper.rs b/g3proxy/src/serve/socks_proxy/task/udp_associate/stats/wrapper.rs index 93dadb7cc..f7c9c2c97 100644 --- a/g3proxy/src/serve/socks_proxy/task/udp_associate/stats/wrapper.rs +++ b/g3proxy/src/serve/socks_proxy/task/udp_associate/stats/wrapper.rs @@ -69,16 +69,13 @@ impl UdpAssociateTaskCltWrapperStats { pub(crate) fn push_user_io_stats(&mut self, all: Vec>) { for s in all { - self.others.push(s as ArcUdpAssociateTaskCltStatsWrapper); + self.others.push(s as _); } } pub(crate) fn split(self) -> (ArcLimitedRecvStats, ArcLimitedSendStats) { let s = Arc::new(self); - ( - Arc::clone(&s) as ArcLimitedRecvStats, - s as ArcLimitedSendStats, - ) + (Arc::clone(&s) as _, s as _) } } diff --git a/g3proxy/src/serve/socks_proxy/task/udp_associate/task.rs b/g3proxy/src/serve/socks_proxy/task/udp_associate/task.rs index a5107b2e7..8e8c15487 100644 --- a/g3proxy/src/serve/socks_proxy/task/udp_associate/task.rs +++ b/g3proxy/src/serve/socks_proxy/task/udp_associate/task.rs @@ -476,7 +476,7 @@ impl SocksProxyUdpAssociateTask { .udp_setup_relay( &mut self.udp_notes, &self.task_notes, - self.task_stats.for_escaper(), + self.task_stats.clone() as _, ) .await?; self.task_notes.stage = ServerTaskStage::Connected; diff --git a/g3proxy/src/serve/socks_proxy/task/udp_connect/stats/task.rs b/g3proxy/src/serve/socks_proxy/task/udp_connect/stats/task.rs index 418ea2ef1..e6749d42a 100644 --- a/g3proxy/src/serve/socks_proxy/task/udp_connect/stats/task.rs +++ b/g3proxy/src/serve/socks_proxy/task/udp_connect/stats/task.rs @@ -14,11 +14,9 @@ * limitations under the License. */ -use std::sync::Arc; - use g3_daemon::stat::task::UdpConnectConnectionStats; -use crate::module::udp_connect::{ArcUdpConnectTaskRemoteStats, UdpConnectTaskRemoteStats}; +use crate::module::udp_connect::UdpConnectTaskRemoteStats; #[derive(Default)] pub(crate) struct UdpConnectTaskStats { @@ -26,13 +24,6 @@ pub(crate) struct UdpConnectTaskStats { pub(crate) ups: UdpConnectConnectionStats, } -impl UdpConnectTaskStats { - #[inline] - pub(crate) fn for_escaper(self: &Arc) -> ArcUdpConnectTaskRemoteStats { - Arc::clone(self) as ArcUdpConnectTaskRemoteStats - } -} - impl UdpConnectTaskRemoteStats for UdpConnectTaskStats { fn add_recv_bytes(&self, size: u64) { self.ups.recv.add_bytes(size); diff --git a/g3proxy/src/serve/socks_proxy/task/udp_connect/stats/wrapper.rs b/g3proxy/src/serve/socks_proxy/task/udp_connect/stats/wrapper.rs index cb666b7c7..5b6570f74 100644 --- a/g3proxy/src/serve/socks_proxy/task/udp_connect/stats/wrapper.rs +++ b/g3proxy/src/serve/socks_proxy/task/udp_connect/stats/wrapper.rs @@ -69,16 +69,13 @@ impl UdpConnectTaskCltWrapperStats { pub(crate) fn push_user_io_stats(&mut self, all: Vec>) { for s in all { - self.others.push(s as ArcUdpConnectTaskCltStatsWrapper); + self.others.push(s as _); } } pub(crate) fn split(self) -> (ArcLimitedRecvStats, ArcLimitedSendStats) { let s = Arc::new(self); - ( - Arc::clone(&s) as ArcLimitedRecvStats, - s as ArcLimitedSendStats, - ) + (Arc::clone(&s) as _, s as _) } } diff --git a/g3proxy/src/serve/socks_proxy/task/udp_connect/task.rs b/g3proxy/src/serve/socks_proxy/task/udp_connect/task.rs index 14c19705d..7d7f93d35 100644 --- a/g3proxy/src/serve/socks_proxy/task/udp_connect/task.rs +++ b/g3proxy/src/serve/socks_proxy/task/udp_connect/task.rs @@ -525,7 +525,7 @@ impl SocksProxyUdpConnectTask { .udp_setup_connection( &mut self.udp_notes, &self.task_notes, - self.task_stats.for_escaper(), + self.task_stats.clone() as _, ) .await?; self.task_notes.stage = ServerTaskStage::Connected; diff --git a/g3proxy/src/serve/tcp_stream/server.rs b/g3proxy/src/serve/tcp_stream/server.rs index d97e087e2..4e68ee927 100644 --- a/g3proxy/src/serve/tcp_stream/server.rs +++ b/g3proxy/src/serve/tcp_stream/server.rs @@ -282,7 +282,7 @@ impl Server for TcpStreamServer { } fn get_server_stats(&self) -> Option { - Some(Arc::clone(&self.server_stats) as ArcServerStats) + Some(Arc::clone(&self.server_stats) as _) } fn get_listen_stats(&self) -> Arc { diff --git a/g3proxy/src/serve/tcp_stream/task.rs b/g3proxy/src/serve/tcp_stream/task.rs index 254be48fd..7e97110af 100644 --- a/g3proxy/src/serve/tcp_stream/task.rs +++ b/g3proxy/src/serve/tcp_stream/task.rs @@ -114,7 +114,7 @@ impl TcpStreamTask { .tls_setup_connection( &mut self.tcp_notes, &self.task_notes, - self.task_stats.for_escaper(), + self.task_stats.clone() as _, tls_client_config, tls_name, ) @@ -126,7 +126,7 @@ impl TcpStreamTask { .tls_setup_connection( &mut self.tcp_notes, &self.task_notes, - self.task_stats.for_escaper(), + self.task_stats.clone() as _, tls_client_config, &tls_name, ) @@ -138,7 +138,7 @@ impl TcpStreamTask { .tcp_setup_connection( &mut self.tcp_notes, &self.task_notes, - self.task_stats.for_escaper(), + self.task_stats.clone() as _, ) .await? }; diff --git a/g3proxy/src/serve/tls_stream/server.rs b/g3proxy/src/serve/tls_stream/server.rs index 5e0277180..b0cba32a9 100644 --- a/g3proxy/src/serve/tls_stream/server.rs +++ b/g3proxy/src/serve/tls_stream/server.rs @@ -294,7 +294,7 @@ impl Server for TlsStreamServer { } fn get_server_stats(&self) -> Option { - Some(Arc::clone(&self.server_stats) as ArcServerStats) + Some(Arc::clone(&self.server_stats) as _) } fn get_listen_stats(&self) -> Arc { diff --git a/g3proxy/src/serve/tls_stream/task.rs b/g3proxy/src/serve/tls_stream/task.rs index 8659df9f0..b0b96138c 100644 --- a/g3proxy/src/serve/tls_stream/task.rs +++ b/g3proxy/src/serve/tls_stream/task.rs @@ -115,7 +115,7 @@ impl TlsStreamTask { .tls_setup_connection( &mut self.tcp_notes, &self.task_notes, - self.task_stats.for_escaper(), + self.task_stats.clone() as _, tls_client_config, tls_name, ) @@ -127,7 +127,7 @@ impl TlsStreamTask { .tls_setup_connection( &mut self.tcp_notes, &self.task_notes, - self.task_stats.for_escaper(), + self.task_stats.clone() as _, tls_client_config, &tls_name, ) @@ -139,7 +139,7 @@ impl TlsStreamTask { .tcp_setup_connection( &mut self.tcp_notes, &self.task_notes, - self.task_stats.for_escaper(), + self.task_stats.clone() as _, ) .await? }; diff --git a/g3tiles/src/serve/openssl_proxy/server.rs b/g3tiles/src/serve/openssl_proxy/server.rs index b75d281ca..24269e0e6 100644 --- a/g3tiles/src/serve/openssl_proxy/server.rs +++ b/g3tiles/src/serve/openssl_proxy/server.rs @@ -266,7 +266,7 @@ impl Server for OpensslProxyServer { } fn get_server_stats(&self) -> Option { - Some(Arc::clone(&self.server_stats) as ArcServerStats) + Some(Arc::clone(&self.server_stats) as _) } fn get_listen_stats(&self) -> Arc { diff --git a/g3tiles/src/serve/rustls_proxy/server.rs b/g3tiles/src/serve/rustls_proxy/server.rs index 75688abbc..cdd68908e 100644 --- a/g3tiles/src/serve/rustls_proxy/server.rs +++ b/g3tiles/src/serve/rustls_proxy/server.rs @@ -234,7 +234,7 @@ impl Server for RustlsProxyServer { } fn get_server_stats(&self) -> Option { - Some(Arc::clone(&self.server_stats) as ArcServerStats) + Some(Arc::clone(&self.server_stats) as _) } fn get_listen_stats(&self) -> Arc { diff --git a/lib/g3-daemon/src/stat/remote/tcp_connect.rs b/lib/g3-daemon/src/stat/remote/tcp_connect.rs index 028acacff..b2e650988 100644 --- a/lib/g3-daemon/src/stat/remote/tcp_connect.rs +++ b/lib/g3-daemon/src/stat/remote/tcp_connect.rs @@ -47,16 +47,13 @@ impl TcpConnectionTaskRemoteStatsWrapper { T: TcpConnectionTaskRemoteStats + Send + Sync + 'static, { for s in all { - self.others.push(s as ArcTcpConnectionTaskRemoteStats); + self.others.push(s as _); } } pub fn into_pair(self) -> (ArcLimitedReaderStats, ArcLimitedWriterStats) { let s = Arc::new(self); - ( - Arc::clone(&s) as ArcLimitedReaderStats, - s as ArcLimitedWriterStats, - ) + (Arc::clone(&s) as _, s as _) } } diff --git a/lib/g3-daemon/src/stat/task/tcp_stream.rs b/lib/g3-daemon/src/stat/task/tcp_stream.rs index 3f298489a..1a2d5dd22 100644 --- a/lib/g3-daemon/src/stat/task/tcp_stream.rs +++ b/lib/g3-daemon/src/stat/task/tcp_stream.rs @@ -15,9 +15,8 @@ */ use std::cell::UnsafeCell; -use std::sync::Arc; -use crate::stat::remote::{ArcTcpConnectionTaskRemoteStats, TcpConnectionTaskRemoteStats}; +use crate::stat::remote::TcpConnectionTaskRemoteStats; #[derive(Default)] pub struct TcpStreamHalfConnectionStats { @@ -65,11 +64,6 @@ impl TcpStreamTaskStats { ups: TcpStreamConnectionStats::default(), } } - - #[inline] - pub fn for_escaper(self: &Arc) -> ArcTcpConnectionTaskRemoteStats { - Arc::clone(self) as ArcTcpConnectionTaskRemoteStats - } } impl TcpConnectionTaskRemoteStats for TcpStreamTaskStats { diff --git a/lib/g3-io-ext/src/io/limited_stream.rs b/lib/g3-io-ext/src/io/limited_stream.rs index 19351dbdb..0f0f4f435 100644 --- a/lib/g3-io-ext/src/io/limited_stream.rs +++ b/lib/g3-io-ext/src/io/limited_stream.rs @@ -23,8 +23,8 @@ use std::task::{Context, Poll}; use pin_project::pin_project; use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; -use super::limited_read::{ArcLimitedReaderStats, LimitedReaderState, LimitedReaderStats}; -use super::limited_write::{ArcLimitedWriterStats, LimitedWriterState, LimitedWriterStats}; +use super::limited_read::{LimitedReaderState, LimitedReaderStats}; +use super::limited_write::{LimitedWriterState, LimitedWriterStats}; #[pin_project] pub struct LimitedStream { @@ -47,16 +47,8 @@ impl LimitedStream { { LimitedStream { inner, - reader_state: LimitedReaderState::new( - shift_millis, - read_max_bytes, - stats.clone() as ArcLimitedReaderStats, - ), - writer_state: LimitedWriterState::new( - shift_millis, - write_max_bytes, - stats as ArcLimitedWriterStats, - ), + reader_state: LimitedReaderState::new(shift_millis, read_max_bytes, stats.clone() as _), + writer_state: LimitedWriterState::new(shift_millis, write_max_bytes, stats as _), } } @@ -66,8 +58,8 @@ impl LimitedStream { { LimitedStream { inner, - reader_state: LimitedReaderState::new_unlimited(stats.clone() as ArcLimitedReaderStats), - writer_state: LimitedWriterState::new_unlimited(stats as ArcLimitedWriterStats), + reader_state: LimitedReaderState::new_unlimited(stats.clone() as _), + writer_state: LimitedWriterState::new_unlimited(stats as _), } } @@ -75,10 +67,8 @@ impl LimitedStream { where ST: LimitedReaderStats + LimitedWriterStats + Send + Sync + 'static, { - self.reader_state - .reset_stats(stats.clone() as ArcLimitedReaderStats); - self.writer_state - .reset_stats(stats as ArcLimitedWriterStats); + self.reader_state.reset_stats(stats.clone() as _); + self.writer_state.reset_stats(stats as _); } pub fn reset_limit(&mut self, shift_millis: u8, read_max_bytes: usize, write_max_bytes: usize) {