Skip to content

Commit

Permalink
style: cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Itsusinn committed Sep 23, 2024
1 parent 27b2794 commit 98cb3cf
Show file tree
Hide file tree
Showing 19 changed files with 38 additions and 40 deletions.
10 changes: 4 additions & 6 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
unstable_features = true


version = "Two"

style_edition = "2024"
tab_spaces = 4

# imports
group_imports = "StdExternalCrate"
imports_granularity = "Crate"
reorder_imports = true

# comments
wrap_comments = true
normalize_comments = true
format_code_in_doc_comments = true

reorder_impl_items = true
condense_wildcard_suffixes = true
enum_discrim_align_threshold = 20
use_field_init_shorthand = true

format_strings = true
format_code_in_doc_comments = true
format_macro_matchers = true
2 changes: 1 addition & 1 deletion tuic-client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::{
use humantime::Duration as HumanDuration;
use lexopt::{Arg, Error as ArgumentError, Parser};
use log::LevelFilter;
use serde::{de::Error as DeError, Deserialize, Deserializer};
use serde::{Deserialize, Deserializer, de::Error as DeError};
use serde_json::Error as SerdeError;
use thiserror::Error;
use uuid::Uuid;
Expand Down
10 changes: 5 additions & 5 deletions tuic-client/src/connection/mod.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
use std::{
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, UdpSocket},
sync::{atomic::AtomicU32, Arc},
sync::{Arc, atomic::AtomicU32},
time::Duration,
};

use anyhow::Context;
use crossbeam_utils::atomic::AtomicCell;
use once_cell::sync::OnceCell;
use quinn::{
congestion::{BbrConfig, CubicConfig, NewRenoConfig},
crypto::rustls::QuicClientConfig,
ClientConfig, Connection as QuinnConnection, Endpoint as QuinnEndpoint, EndpointConfig,
TokioRuntime, TransportConfig, VarInt, ZeroRttAccepted,
congestion::{BbrConfig, CubicConfig, NewRenoConfig},
crypto::rustls::QuicClientConfig,
};
use register_count::Counter;
use rustls::{
pki_types::{CertificateDer, ServerName, UnixTime},
ClientConfig as RustlsClientConfig,
pki_types::{CertificateDer, ServerName, UnixTime},
};
use tokio::{
sync::{OnceCell as AsyncOnceCell, RwLock as AsyncRwLock},
time,
};
use tuic_quinn::{side, Connection as Model};
use tuic_quinn::{Connection as Model, side};
use uuid::Uuid;

use crate::{
Expand Down
4 changes: 2 additions & 2 deletions tuic-client/src/socks5/handle_task.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use socks5_proto::{Address, Reply};
use socks5_server::{
connection::{associate, bind, connect},
Associate, Bind, Connect,
connection::{associate, bind, connect},
};
use tokio::io::{self, AsyncWriteExt};
use tokio_util::compat::FuturesAsyncReadCompatExt;
use tuic::Address as TuicAddress;

use super::{udp_session::UdpSession, Server, UDP_SESSIONS};
use super::{Server, UDP_SESSIONS, udp_session::UdpSession};
use crate::connection::{Connection as TuicConnection, ERROR_CODE};

impl Server {
Expand Down
4 changes: 2 additions & 2 deletions tuic-client/src/socks5/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ use std::{
collections::HashMap,
net::{SocketAddr, TcpListener as StdTcpListener},
sync::{
atomic::{AtomicU16, Ordering},
Arc,
atomic::{AtomicU16, Ordering},
},
};

use once_cell::sync::OnceCell;
use socket2::{Domain, Protocol, SockAddr, Socket, Type};
use socks5_server::{
auth::{NoAuth, Password},
Auth, Connection, Server as Socks5Server,
auth::{NoAuth, Password},
};
use tokio::{net::TcpListener, sync::RwLock as AsyncRwLock};

Expand Down
2 changes: 1 addition & 1 deletion tuic-client/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
};

use anyhow::Context;
use rustls::{pki_types::CertificateDer, RootCertStore};
use rustls::{RootCertStore, pki_types::CertificateDer};
use tokio::net;

use crate::error::Error;
Expand Down
4 changes: 2 additions & 2 deletions tuic-quinn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ use quinn::{
};
use thiserror::Error;
use tuic::{
Address, Header, UnmarshalError,
model::{
side::{Rx, Tx},
AssembleError, Authenticate as AuthenticateModel, Connect as ConnectModel,
Connection as ConnectionModel, KeyingMaterialExporter as KeyingMaterialExporterImpl,
Packet as PacketModel,
side::{Rx, Tx},
},
Address, Header, UnmarshalError,
};
use uuid::Uuid;

Expand Down
2 changes: 1 addition & 1 deletion tuic-server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::{collections::HashMap, env::ArgsOs, net::SocketAddr, path::PathBuf, tim

use educe::Educe;
use figment::{
providers::{Format, Serialized, Toml},
Figment,
providers::{Format, Serialized, Toml},
};
use lexopt::{Arg, Parser};
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion tuic-server/src/connection/authenticated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
};

use arc_swap::ArcSwap;
use tokio::sync::{broadcast::Sender, RwLock as AsyncRwLock};
use tokio::sync::{RwLock as AsyncRwLock, broadcast::Sender};
use uuid::Uuid;

#[derive(Clone)]
Expand Down
2 changes: 1 addition & 1 deletion tuic-server/src/connection/handle_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use tracing::{debug, warn};
use tuic_quinn::Task;

use super::Connection;
use crate::{error::Error, utils::UdpRelayMode, CONFIG};
use crate::{CONFIG, error::Error, utils::UdpRelayMode};

impl Connection {
pub async fn handle_uni_stream(self, recv: RecvStream, _reg: Register) {
Expand Down
2 changes: 1 addition & 1 deletion tuic-server/src/connection/handle_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use tracing::{info, warn};
use tuic::Address;
use tuic_quinn::{Authenticate, Connect, Packet};

use super::{Connection, UdpSession, ERROR_CODE};
use super::{Connection, ERROR_CODE, UdpSession};
use crate::{error::Error, utils::UdpRelayMode};

impl Connection {
Expand Down
6 changes: 3 additions & 3 deletions tuic-server/src/connection/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{
collections::HashMap,
sync::{atomic::AtomicU32, Arc},
sync::{Arc, atomic::AtomicU32},
time::Duration,
};

Expand All @@ -9,10 +9,10 @@ use quinn::{Connecting, Connection as QuinnConnection, VarInt};
use register_count::Counter;
use tokio::{sync::RwLock as AsyncRwLock, time};
use tracing::{debug, info, warn};
use tuic_quinn::{side, Authenticate, Connection as Model};
use tuic_quinn::{Authenticate, Connection as Model, side};

use self::{authenticated::Authenticated, udp_session::UdpSession};
use crate::{error::Error, restful, utils::UdpRelayMode, CONFIG};
use crate::{CONFIG, error::Error, restful, utils::UdpRelayMode};

mod authenticated;
mod handle_stream;
Expand Down
4 changes: 2 additions & 2 deletions tuic-server/src/connection/udp_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ use socket2::{Domain, Protocol, SockAddr, Socket, Type};
use tokio::{
net::UdpSocket,
sync::{
oneshot::{self, Sender},
RwLock as AsyncRwLock,
oneshot::{self, Sender},
},
};
use tracing::warn;
use tuic::Address;

use super::Connection;
use crate::{error::Error, CONFIG};
use crate::{CONFIG, error::Error};

#[derive(Clone)]
pub struct UdpSession(Arc<UdpSessionInner>);
Expand Down
2 changes: 1 addition & 1 deletion tuic-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use std::{env, process};

use chrono::{Local, Offset, TimeZone};
use config::{parse_config, Config};
use config::{Config, parse_config};
use lateinit::LateInit;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};

Expand Down
2 changes: 1 addition & 1 deletion tuic-server/src/old_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{

use humantime::Duration as HumanDuration;
use lexopt::Error as ArgumentError;
use serde::{de::Error as DeError, Deserialize, Deserializer};
use serde::{Deserialize, Deserializer, de::Error as DeError};
use serde_json::Error as SerdeError;
use thiserror::Error;
use uuid::Uuid;
Expand Down
6 changes: 3 additions & 3 deletions tuic-server/src/restful.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ use std::{
net::SocketAddr,
ops::Deref,
sync::{
atomic::{AtomicU64, Ordering},
LazyLock,
atomic::{AtomicU64, Ordering},
},
};

use axum::{
Json, Router,
http::StatusCode,
routing::{get, post},
Json, Router,
};
use axum_extra::{
headers::{authorization::Bearer, Authorization},
TypedHeader,
headers::{Authorization, authorization::Bearer},
};
use chashmap::CHashMap;
use lateinit::LateInit;
Expand Down
10 changes: 5 additions & 5 deletions tuic-server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ use std::{

use anyhow::Context;
use quinn::{
Endpoint, EndpointConfig, IdleTimeout, ServerConfig, TokioRuntime, TransportConfig, VarInt,
congestion::{BbrConfig, CubicConfig, NewRenoConfig},
crypto::rustls::QuicServerConfig,
Endpoint, EndpointConfig, IdleTimeout, ServerConfig, TokioRuntime, TransportConfig, VarInt,
};
use rustls::{
pki_types::{CertificateDer, PrivateKeyDer, PrivatePkcs8KeyDer},
ServerConfig as RustlsServerConfig,
pki_types::{CertificateDer, PrivateKeyDer, PrivatePkcs8KeyDer},
};
use socket2::{Domain, Protocol, SockAddr, Socket, Type};
use tracing::{debug, warn};

use crate::{
CONFIG,
connection::{Connection, INIT_CONCURRENT_STREAMS},
error::Error,
utils::{self, CongestionController},
CONFIG,
};

pub struct Server {
Expand Down Expand Up @@ -106,7 +106,7 @@ impl Server {
};

let socket = Socket::new(domain, Type::DGRAM, Some(Protocol::UDP))
.map_err(|err| Error::Socket("failed to create endpoint UDP socket", err))?;
.context("failed to create endpoint UDP socket")?;

if CONFIG.dual_stack {
socket.set_only_v6(!CONFIG.dual_stack).map_err(|err| {
Expand All @@ -116,7 +116,7 @@ impl Server {

socket
.bind(&SockAddr::from(CONFIG.server))
.map_err(|err| Error::Socket("failed to bind endpoint UDP socket", err))?;
.context("failed to bind endpoint UDP socket")?;

StdUdpSocket::from(socket)
};
Expand Down
2 changes: 1 addition & 1 deletion tuic/src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::{
fmt::{Debug, Formatter, Result as FmtResult},
mem,
sync::{
atomic::{AtomicU16, Ordering},
Arc,
atomic::{AtomicU16, Ordering},
},
time::{Duration, Instant},
};
Expand Down
2 changes: 1 addition & 1 deletion tuic/src/model/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use std::{
use parking_lot::Mutex;

use super::{
side::{self, Side},
Assemblable, AssembleError, UdpSessions,
side::{self, Side},
};
use crate::{Address, Header, Packet as PacketHeader};

Expand Down

0 comments on commit 98cb3cf

Please sign in to comment.