Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(shadowsocks): add more Debug implementations #1656

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/shadowsocks/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::{
};

/// Service context
#[derive(Debug)]
pub struct Context {
// Protector against replay attack
// The actual replay detection behavior is implemented in ReplayProtector
Expand Down
1 change: 1 addition & 0 deletions crates/shadowsocks/src/dns_resolver/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub trait DnsResolve {
}

#[cfg(feature = "hickory-dns")]
#[derive(Debug)]
pub struct HickoryDnsSystemResolver {
resolver: ArcSwap<HickoryDnsResolver>,
#[cfg_attr(any(windows, target_os = "android"), allow(dead_code))]
Expand Down
1 change: 1 addition & 0 deletions crates/shadowsocks/src/manager/datagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl fmt::Display for ManagerSocketAddr {
/// Datagram socket for manager
///
/// For *nix system, this is a wrapper for both UDP socket and Unix socket
#[derive(Debug)]
pub enum ManagerDatagram {
UdpDatagram(UdpSocket),
#[cfg(unix)]
Expand Down
1 change: 1 addition & 0 deletions crates/shadowsocks/src/manager/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use super::{
};

/// Manager server Listener
#[derive(Debug)]
pub struct ManagerListener {
socket: ManagerDatagram,
}
Expand Down
1 change: 1 addition & 0 deletions crates/shadowsocks/src/net/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ impl AsyncWrite for TcpStream {
}

/// `TcpListener` for accepting inbound connections
#[derive(Debug)]
pub struct TcpListener {
inner: TokioTcpListener,
accept_opts: AcceptOpts,
Expand Down
1 change: 1 addition & 0 deletions crates/shadowsocks/src/net/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ fn make_mtu_error(packet_size: usize, mtu: usize) -> io::Error {
}

/// Wrappers for outbound `UdpSocket`
#[derive(Debug)]
#[pin_project]
pub struct UdpSocket {
#[pin]
Expand Down
1 change: 1 addition & 0 deletions crates/shadowsocks/src/plugin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub enum PluginMode {
}

/// A shadowsocks SIP004 Plugin
#[derive(Debug)]
pub struct Plugin {
process: Child,
local_addr: SocketAddr,
Expand Down
2 changes: 2 additions & 0 deletions crates/shadowsocks/src/relay/tcprelay/aead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ impl From<ProtocolError> for io::Error {
}
}

#[derive(Debug)]
enum DecryptReadState {
WaitSalt { key: Bytes },
ReadLength,
Expand Down Expand Up @@ -320,6 +321,7 @@ impl DecryptedReader {
}
}

#[derive(Debug)]
enum EncryptWriteState {
AssemblePacket,
Writing { pos: usize },
Expand Down
11 changes: 10 additions & 1 deletion crates/shadowsocks/src/relay/tcprelay/crypto_io.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! IO facilities for TCP relay

use std::{
io,
fmt, io,
marker::Unpin,
pin::Pin,
sync::Arc,
Expand Down Expand Up @@ -313,6 +313,15 @@ pub struct CryptoStream<S> {
has_handshaked: bool,
}

impl<S> fmt::Debug for CryptoStream<S> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("CryptoStream")
.field("method", &self.method)
.field("has_handshaked", &self.has_handshaked)
.finish()
}
}

impl<S> CryptoStream<S> {
/// Create a new CryptoStream with the underlying stream connection
pub fn from_stream(
Expand Down
1 change: 1 addition & 0 deletions crates/shadowsocks/src/relay/tcprelay/proxy_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::{
};

/// A TCP listener for accepting shadowsocks' client connection
#[derive(Debug)]
pub struct ProxyListener {
listener: TcpListener,
method: CipherKind,
Expand Down
3 changes: 3 additions & 0 deletions crates/shadowsocks/src/relay/tcprelay/proxy_stream/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,22 @@ use crate::{
},
};

#[derive(Debug)]
enum ProxyClientStreamWriteState {
Connect(Address),
Connecting(BytesMut),
Connected,
}

#[derive(Debug)]
enum ProxyClientStreamReadState {
#[cfg(feature = "aead-cipher-2022")]
CheckRequestNonce,
Established,
}

/// A stream for sending / receiving data stream from remote server via shadowsocks' proxy server
#[derive(Debug)]
#[pin_project]
pub struct ProxyClientStream<S> {
#[pin]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub mod v1;
#[cfg(feature = "aead-cipher-2022")]
pub mod v2;

#[derive(Debug)]
pub enum TcpRequestHeader {
Stream(StreamTcpRequestHeader),
#[cfg(feature = "aead-cipher-2022")]
Expand Down Expand Up @@ -74,6 +75,7 @@ impl TcpRequestHeader {
}
}

#[derive(Debug)]
pub enum TcpRequestHeaderRef<'a> {
Stream(StreamTcpRequestHeaderRef<'a>),
#[cfg(feature = "aead-cipher-2022")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use tokio::io::AsyncRead;

use crate::relay::socks5::Address;

#[derive(Debug)]
pub struct StreamTcpRequestHeader {
pub addr: Address,
}
Expand All @@ -27,6 +28,7 @@ impl StreamTcpRequestHeader {
}
}

#[derive(Debug)]
pub struct StreamTcpRequestHeaderRef<'a> {
pub addr: &'a Address,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl Aead2022TcpRequestHeader {
}
}

#[derive(Debug)]
pub struct Aead2022TcpRequestHeaderRef<'a> {
pub addr: &'a Address,
pub padding_size: u16,
Expand Down
2 changes: 2 additions & 0 deletions crates/shadowsocks/src/relay/tcprelay/proxy_stream/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ use crate::{
},
};

#[derive(Debug)]
enum ProxyServerStreamWriteState {
#[cfg(feature = "aead-cipher-2022")]
PrepareHeader(Option<std::task::Waker>),
Established,
}

/// A stream for communicating with shadowsocks' proxy client
#[derive(Debug)]
#[pin_project]
pub struct ProxyServerStream<S> {
#[pin]
Expand Down
1 change: 1 addition & 0 deletions crates/shadowsocks/src/relay/udprelay/proxy_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ impl From<ProxySocketError> for io::Error {
pub type ProxySocketResult<T> = Result<T, ProxySocketError>;

/// UDP client for communicating with ShadowSocks' server
#[derive(Debug)]
pub struct ProxySocket {
socket_type: UdpSocketType,
socket: ShadowUdpSocket,
Expand Down
8 changes: 8 additions & 0 deletions crates/shadowsocks/src/security/replay/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt;

#[cfg(feature = "aead-cipher-2022")]
use std::time::Duration;

Expand Down Expand Up @@ -29,6 +31,12 @@ pub struct ReplayProtector {
nonce_set: spin::Mutex<LruCache<Vec<u8>, ()>>,
}

impl fmt::Debug for ReplayProtector {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("ReplayProtector").finish()
}
}

impl ReplayProtector {
/// Create a new ReplayProtector
#[allow(unused_variables)]
Expand Down
1 change: 1 addition & 0 deletions crates/shadowsocks/src/security/replay/ppbloom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const BF_ERROR_RATE_FOR_CLIENT: f64 = 1e-15;
//
// It contains 2 bloom filters and each one holds 1/2 entries.
// Use them as a ring buffer.
#[derive(Debug)]
pub struct PingPongBloom {
blooms: [Bloom<[u8]>; 2],
bloom_count: [usize; 2],
Expand Down
Loading