mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-05-13 17:35:37 +00:00
chore: update Rust to 2024 edition (#2066)
This commit is contained in:
@@ -110,11 +110,7 @@ pub mod instance {
|
||||
ret += stats.rx_bytes;
|
||||
}
|
||||
|
||||
if ret == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(ret)
|
||||
}
|
||||
if ret == 0 { None } else { Some(ret) }
|
||||
}
|
||||
|
||||
pub fn get_tx_bytes(&self) -> Option<u64> {
|
||||
@@ -127,11 +123,7 @@ pub mod instance {
|
||||
ret += stats.tx_bytes;
|
||||
}
|
||||
|
||||
if ret == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(ret)
|
||||
}
|
||||
if ret == 0 { None } else { Some(ret) }
|
||||
}
|
||||
|
||||
pub fn get_loss_rate(&self) -> Option<f64> {
|
||||
@@ -167,11 +159,7 @@ pub mod instance {
|
||||
}
|
||||
}
|
||||
|
||||
if ret.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(ret)
|
||||
}
|
||||
if ret.is_empty() { None } else { Some(ret) }
|
||||
}
|
||||
|
||||
pub fn get_udp_nat_type(&self) -> String {
|
||||
@@ -366,9 +354,10 @@ mod tests {
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
assert!(pair
|
||||
.get_loss_rate()
|
||||
.is_some_and(|loss_rate| (loss_rate - 0.4).abs() < 1e-6));
|
||||
assert!(
|
||||
pair.get_loss_rate()
|
||||
.is_some_and(|loss_rate| (loss_rate - 0.4).abs() < 1e-6)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -4,10 +4,10 @@ use std::{
|
||||
};
|
||||
|
||||
use anyhow::Context;
|
||||
use base64::{prelude::BASE64_STANDARD, Engine as _};
|
||||
use base64::{Engine as _, prelude::BASE64_STANDARD};
|
||||
use strum::VariantArray;
|
||||
|
||||
use crate::tunnel::{packet_def::CompressorAlgo, IpScheme};
|
||||
use crate::tunnel::{IpScheme, packet_def::CompressorAlgo};
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/common.rs"));
|
||||
|
||||
@@ -288,18 +288,17 @@ impl fmt::Display for Url {
|
||||
fn split_tunnel_scheme(raw_scheme: &str) -> Option<(&str, &'static str, bool)> {
|
||||
for scheme in IpScheme::VARIANTS {
|
||||
let scheme: &'static str = scheme.into();
|
||||
if let Some(base) = raw_scheme.strip_suffix('6') {
|
||||
if let Some(prefix) = base.strip_suffix(scheme) {
|
||||
if prefix.is_empty() || prefix.ends_with('-') {
|
||||
return Some((prefix, scheme, true));
|
||||
}
|
||||
}
|
||||
if let Some(base) = raw_scheme.strip_suffix('6')
|
||||
&& let Some(prefix) = base.strip_suffix(scheme)
|
||||
&& (prefix.is_empty() || prefix.ends_with('-'))
|
||||
{
|
||||
return Some((prefix, scheme, true));
|
||||
}
|
||||
|
||||
if let Some(prefix) = raw_scheme.strip_suffix(scheme) {
|
||||
if prefix.is_empty() || prefix.ends_with('-') {
|
||||
return Some((prefix, scheme, false));
|
||||
}
|
||||
if let Some(prefix) = raw_scheme.strip_suffix(scheme)
|
||||
&& (prefix.is_empty() || prefix.ends_with('-'))
|
||||
{
|
||||
return Some((prefix, scheme, false));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -532,7 +531,7 @@ impl SecureModeConfig {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{normalize_tunnel_url, TunnelInfo, Url};
|
||||
use super::{TunnelInfo, Url, normalize_tunnel_url};
|
||||
|
||||
fn assert_ipv6_tunnel_normalization(scheme: &str, port: u16) {
|
||||
let expected = format!("{scheme}6://[2001:db8::1]:{port}");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::sync::{atomic::AtomicBool, Arc, Mutex};
|
||||
use std::sync::{Arc, Mutex, atomic::AtomicBool};
|
||||
|
||||
use futures::{SinkExt as _, StreamExt};
|
||||
use tokio::{task::JoinSet, time::timeout};
|
||||
@@ -6,7 +6,7 @@ use tokio::{task::JoinSet, time::timeout};
|
||||
use crate::{
|
||||
defer,
|
||||
proto::rpc_types::error::Error,
|
||||
tunnel::{packet_def::PacketType, ring::create_ring_tunnel_pair, Tunnel},
|
||||
tunnel::{Tunnel, packet_def::PacketType, ring::create_ring_tunnel_pair},
|
||||
};
|
||||
|
||||
use super::{client::Client, server::Server, service_registry::ServiceRegistry};
|
||||
|
||||
@@ -12,15 +12,15 @@ use tokio_stream::StreamExt;
|
||||
|
||||
use crate::common::shrink_dashmap;
|
||||
use crate::common::{
|
||||
stats_manager::{LabelSet, LabelType, MetricName, StatsManager},
|
||||
PeerId,
|
||||
stats_manager::{LabelSet, LabelType, MetricName, StatsManager},
|
||||
};
|
||||
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, BuildRpcPacketArgs,
|
||||
BuildRpcPacketArgs, build_rpc_packet, compress_packet, decompress_packet,
|
||||
};
|
||||
use crate::proto::rpc_types::controller::Controller;
|
||||
use crate::proto::rpc_types::descriptor::MethodDescriptor;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::tunnel::{mpsc::MpscTunnel, Tunnel};
|
||||
use crate::tunnel::{Tunnel, mpsc::MpscTunnel};
|
||||
|
||||
pub type RpcController = super::rpc_types::controller::BaseController;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use prost::Message as _;
|
||||
|
||||
use crate::{
|
||||
common::{compressor::DefaultCompressor, PeerId},
|
||||
common::{PeerId, compressor::DefaultCompressor},
|
||||
proto::{
|
||||
common::{CompressionAlgoPb, RpcCompressionInfo, RpcDescriptor, RpcPacket},
|
||||
rpc_types::error::Error,
|
||||
|
||||
@@ -11,9 +11,8 @@ use tokio_stream::StreamExt;
|
||||
|
||||
use crate::{
|
||||
common::{
|
||||
join_joinset_background,
|
||||
PeerId, join_joinset_background,
|
||||
stats_manager::{LabelSet, LabelType, MetricName, StatsManager},
|
||||
PeerId,
|
||||
},
|
||||
proto::{
|
||||
common::{
|
||||
@@ -24,16 +23,16 @@ use crate::{
|
||||
rpc_types::{controller::Controller, error::Result},
|
||||
},
|
||||
tunnel::{
|
||||
Tunnel, ZCPacketStream,
|
||||
mpsc::{MpscTunnel, MpscTunnelSender},
|
||||
ring::create_ring_tunnel_pair,
|
||||
Tunnel, ZCPacketStream,
|
||||
},
|
||||
};
|
||||
|
||||
use super::{
|
||||
packet::{build_rpc_packet, compress_packet, decompress_packet, PacketMerger},
|
||||
service_registry::ServiceRegistry,
|
||||
RpcController, Transport,
|
||||
packet::{PacketMerger, build_rpc_packet, compress_packet, decompress_packet},
|
||||
service_registry::ServiceRegistry,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use std::{
|
||||
sync::{atomic::AtomicU32, Arc, Mutex},
|
||||
sync::{Arc, Mutex, atomic::AtomicU32},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
@@ -204,8 +204,8 @@ mod tests {
|
||||
use crate::{
|
||||
proto::rpc_impl::standalone::StandAloneServer,
|
||||
tunnel::{
|
||||
tcp::{TcpTunnelConnector, TcpTunnelListener},
|
||||
TunnelConnector as _,
|
||||
tcp::{TcpTunnelConnector, TcpTunnelListener},
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -191,8 +191,8 @@ impl TestContext {
|
||||
}
|
||||
|
||||
fn random_string(len: usize) -> String {
|
||||
use rand::distributions::Alphanumeric;
|
||||
use rand::Rng;
|
||||
use rand::distributions::Alphanumeric;
|
||||
let mut rng = rand::thread_rng();
|
||||
let s: Vec<u8> = std::iter::repeat(())
|
||||
.map(|()| rng.sample(Alphanumeric))
|
||||
|
||||
Reference in New Issue
Block a user