mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-05-15 18:35:47 +00:00
clippy all codes (#1214)
1. clippy code 2. add fmt and clippy check in ci
This commit is contained in:
@@ -18,7 +18,9 @@ use crate::defer;
|
||||
use crate::proto::common::{
|
||||
CompressionAlgoPb, RpcCompressionInfo, RpcDescriptor, RpcPacket, RpcRequest, RpcResponse,
|
||||
};
|
||||
use crate::proto::rpc_impl::packet::{build_rpc_packet, compress_packet, decompress_packet};
|
||||
use crate::proto::rpc_impl::packet::{
|
||||
build_rpc_packet, compress_packet, decompress_packet, BuildRpcPacketArgs,
|
||||
};
|
||||
use crate::proto::rpc_types::controller::Controller;
|
||||
use crate::proto::rpc_types::descriptor::MethodDescriptor;
|
||||
use crate::proto::rpc_types::{
|
||||
@@ -53,6 +55,15 @@ struct InflightRequest {
|
||||
start_time: std::time::Instant,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for InflightRequest {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("InflightRequest")
|
||||
.field("sender", &self.sender)
|
||||
.field("start_time", &self.start_time)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct PeerInfo {
|
||||
pub peer_id: PeerId,
|
||||
@@ -72,6 +83,12 @@ pub struct Client {
|
||||
stats_manager: Option<Arc<StatsManager>>,
|
||||
}
|
||||
|
||||
impl Default for Client {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Client {
|
||||
pub fn new() -> Self {
|
||||
let (ring_a, ring_b) = create_ring_tunnel_pair();
|
||||
@@ -86,15 +103,9 @@ impl Client {
|
||||
}
|
||||
|
||||
pub fn new_with_stats_manager(stats_manager: Arc<StatsManager>) -> Self {
|
||||
let (ring_a, ring_b) = create_ring_tunnel_pair();
|
||||
Self {
|
||||
mpsc: Mutex::new(MpscTunnel::new(ring_a, None)),
|
||||
transport: Mutex::new(MpscTunnel::new(ring_b, None)),
|
||||
inflight_requests: Arc::new(DashMap::new()),
|
||||
peer_info: Arc::new(DashMap::new()),
|
||||
tasks: Mutex::new(JoinSet::new()),
|
||||
stats_manager: Some(stats_manager),
|
||||
}
|
||||
let mut ret = Self::new();
|
||||
ret.stats_manager = Some(stats_manager);
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn get_transport_sink(&self) -> MpscTunnelSender {
|
||||
@@ -151,7 +162,11 @@ impl Client {
|
||||
};
|
||||
|
||||
let Some(mut inflight_request) = inflight_requests.get_mut(&key) else {
|
||||
tracing::warn!(?key, "No inflight request found for key");
|
||||
tracing::warn!(
|
||||
?key,
|
||||
?inflight_requests,
|
||||
"No inflight request found for key"
|
||||
);
|
||||
continue;
|
||||
};
|
||||
|
||||
@@ -276,19 +291,19 @@ impl Client {
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let packets = build_rpc_packet(
|
||||
self.from_peer_id,
|
||||
self.to_peer_id,
|
||||
let packets = build_rpc_packet(BuildRpcPacketArgs {
|
||||
from_peer: self.from_peer_id,
|
||||
to_peer: self.to_peer_id,
|
||||
rpc_desc,
|
||||
transaction_id,
|
||||
true,
|
||||
&buf,
|
||||
ctrl.trace_id(),
|
||||
RpcCompressionInfo {
|
||||
is_req: true,
|
||||
content: &buf,
|
||||
trace_id: ctrl.trace_id(),
|
||||
compression_info: RpcCompressionInfo {
|
||||
algo: c_algo.into(),
|
||||
accepted_algo: CompressionAlgoPb::Zstd.into(),
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
let timeout_dur = std::time::Duration::from_millis(ctrl.timeout_ms() as u64);
|
||||
let mut rpc_packet = timeout(timeout_dur, self.do_rpc(packets, &mut rx)).await??;
|
||||
@@ -298,7 +313,7 @@ impl Client {
|
||||
self.to_peer_id,
|
||||
PeerInfo {
|
||||
peer_id: self.to_peer_id,
|
||||
compression_info: compression_info.clone(),
|
||||
compression_info,
|
||||
last_active: Some(std::time::Instant::now()),
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user