Skip to content

Commit a04e92c

Browse files
authored
feat(shadowsocks): add more Debug implementations (#1656)
Most implementations are derived. I would like to add `missing_debug_implementations` lint, but before deriving more Debug implementations we need to add Debug implementations to types exported from `shadowsocks-crypto`.
1 parent 4b510d5 commit a04e92c

File tree

18 files changed

+40
-1
lines changed

18 files changed

+40
-1
lines changed

crates/shadowsocks/src/context.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::{
1313
};
1414

1515
/// Service context
16+
#[derive(Debug)]
1617
pub struct Context {
1718
// Protector against replay attack
1819
// The actual replay detection behavior is implemented in ReplayProtector

crates/shadowsocks/src/dns_resolver/resolver.rs

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub trait DnsResolve {
3838
}
3939

4040
#[cfg(feature = "hickory-dns")]
41+
#[derive(Debug)]
4142
pub struct HickoryDnsSystemResolver {
4243
resolver: ArcSwap<HickoryDnsResolver>,
4344
#[cfg_attr(any(windows, target_os = "android"), allow(dead_code))]

crates/shadowsocks/src/manager/datagram.rs

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ impl fmt::Display for ManagerSocketAddr {
4646
/// Datagram socket for manager
4747
///
4848
/// For *nix system, this is a wrapper for both UDP socket and Unix socket
49+
#[derive(Debug)]
4950
pub enum ManagerDatagram {
5051
UdpDatagram(UdpSocket),
5152
#[cfg(unix)]

crates/shadowsocks/src/manager/listener.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use super::{
1313
};
1414

1515
/// Manager server Listener
16+
#[derive(Debug)]
1617
pub struct ManagerListener {
1718
socket: ManagerDatagram,
1819
}

crates/shadowsocks/src/net/tcp.rs

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ impl AsyncWrite for TcpStream {
121121
}
122122

123123
/// `TcpListener` for accepting inbound connections
124+
#[derive(Debug)]
124125
pub struct TcpListener {
125126
inner: TokioTcpListener,
126127
accept_opts: AcceptOpts,

crates/shadowsocks/src/net/udp.rs

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ fn make_mtu_error(packet_size: usize, mtu: usize) -> io::Error {
8585
}
8686

8787
/// Wrappers for outbound `UdpSocket`
88+
#[derive(Debug)]
8889
#[pin_project]
8990
pub struct UdpSocket {
9091
#[pin]

crates/shadowsocks/src/plugin/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ pub enum PluginMode {
5858
}
5959

6060
/// A shadowsocks SIP004 Plugin
61+
#[derive(Debug)]
6162
pub struct Plugin {
6263
process: Child,
6364
local_addr: SocketAddr,

crates/shadowsocks/src/relay/tcprelay/aead.rs

+2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ impl From<ProtocolError> for io::Error {
8080
}
8181
}
8282

83+
#[derive(Debug)]
8384
enum DecryptReadState {
8485
WaitSalt { key: Bytes },
8586
ReadLength,
@@ -320,6 +321,7 @@ impl DecryptedReader {
320321
}
321322
}
322323

324+
#[derive(Debug)]
323325
enum EncryptWriteState {
324326
AssemblePacket,
325327
Writing { pos: usize },

crates/shadowsocks/src/relay/tcprelay/crypto_io.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! IO facilities for TCP relay
22
33
use std::{
4-
io,
4+
fmt, io,
55
marker::Unpin,
66
pin::Pin,
77
sync::Arc,
@@ -313,6 +313,15 @@ pub struct CryptoStream<S> {
313313
has_handshaked: bool,
314314
}
315315

316+
impl<S> fmt::Debug for CryptoStream<S> {
317+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
318+
f.debug_struct("CryptoStream")
319+
.field("method", &self.method)
320+
.field("has_handshaked", &self.has_handshaked)
321+
.finish()
322+
}
323+
}
324+
316325
impl<S> CryptoStream<S> {
317326
/// Create a new CryptoStream with the underlying stream connection
318327
pub fn from_stream(

crates/shadowsocks/src/relay/tcprelay/proxy_listener.rs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use crate::{
1717
};
1818

1919
/// A TCP listener for accepting shadowsocks' client connection
20+
#[derive(Debug)]
2021
pub struct ProxyListener {
2122
listener: TcpListener,
2223
method: CipherKind,

crates/shadowsocks/src/relay/tcprelay/proxy_stream/client.rs

+3
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,22 @@ use crate::{
3030
},
3131
};
3232

33+
#[derive(Debug)]
3334
enum ProxyClientStreamWriteState {
3435
Connect(Address),
3536
Connecting(BytesMut),
3637
Connected,
3738
}
3839

40+
#[derive(Debug)]
3941
enum ProxyClientStreamReadState {
4042
#[cfg(feature = "aead-cipher-2022")]
4143
CheckRequestNonce,
4244
Established,
4345
}
4446

4547
/// A stream for sending / receiving data stream from remote server via shadowsocks' proxy server
48+
#[derive(Debug)]
4649
#[pin_project]
4750
pub struct ProxyClientStream<S> {
4851
#[pin]

crates/shadowsocks/src/relay/tcprelay/proxy_stream/protocol/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub mod v1;
1818
#[cfg(feature = "aead-cipher-2022")]
1919
pub mod v2;
2020

21+
#[derive(Debug)]
2122
pub enum TcpRequestHeader {
2223
Stream(StreamTcpRequestHeader),
2324
#[cfg(feature = "aead-cipher-2022")]
@@ -74,6 +75,7 @@ impl TcpRequestHeader {
7475
}
7576
}
7677

78+
#[derive(Debug)]
7779
pub enum TcpRequestHeaderRef<'a> {
7880
Stream(StreamTcpRequestHeaderRef<'a>),
7981
#[cfg(feature = "aead-cipher-2022")]

crates/shadowsocks/src/relay/tcprelay/proxy_stream/protocol/v1.rs

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use tokio::io::AsyncRead;
77

88
use crate::relay::socks5::Address;
99

10+
#[derive(Debug)]
1011
pub struct StreamTcpRequestHeader {
1112
pub addr: Address,
1213
}
@@ -27,6 +28,7 @@ impl StreamTcpRequestHeader {
2728
}
2829
}
2930

31+
#[derive(Debug)]
3032
pub struct StreamTcpRequestHeaderRef<'a> {
3133
pub addr: &'a Address,
3234
}

crates/shadowsocks/src/relay/tcprelay/proxy_stream/protocol/v2.rs

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ impl Aead2022TcpRequestHeader {
6666
}
6767
}
6868

69+
#[derive(Debug)]
6970
pub struct Aead2022TcpRequestHeaderRef<'a> {
7071
pub addr: &'a Address,
7172
pub padding_size: u16,

crates/shadowsocks/src/relay/tcprelay/proxy_stream/server.rs

+2
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ use crate::{
2525
},
2626
};
2727

28+
#[derive(Debug)]
2829
enum ProxyServerStreamWriteState {
2930
#[cfg(feature = "aead-cipher-2022")]
3031
PrepareHeader(Option<std::task::Waker>),
3132
Established,
3233
}
3334

3435
/// A stream for communicating with shadowsocks' proxy client
36+
#[derive(Debug)]
3537
#[pin_project]
3638
pub struct ProxyServerStream<S> {
3739
#[pin]

crates/shadowsocks/src/relay/udprelay/proxy_socket.rs

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ impl From<ProxySocketError> for io::Error {
6969
pub type ProxySocketResult<T> = Result<T, ProxySocketError>;
7070

7171
/// UDP client for communicating with ShadowSocks' server
72+
#[derive(Debug)]
7273
pub struct ProxySocket {
7374
socket_type: UdpSocketType,
7475
socket: ShadowUdpSocket,

crates/shadowsocks/src/security/replay/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::fmt;
2+
13
#[cfg(feature = "aead-cipher-2022")]
24
use std::time::Duration;
35

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

34+
impl fmt::Debug for ReplayProtector {
35+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
36+
f.debug_struct("ReplayProtector").finish()
37+
}
38+
}
39+
3240
impl ReplayProtector {
3341
/// Create a new ReplayProtector
3442
#[allow(unused_variables)]

crates/shadowsocks/src/security/replay/ppbloom.rs

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const BF_ERROR_RATE_FOR_CLIENT: f64 = 1e-15;
2727
//
2828
// It contains 2 bloom filters and each one holds 1/2 entries.
2929
// Use them as a ring buffer.
30+
#[derive(Debug)]
3031
pub struct PingPongBloom {
3132
blooms: [Bloom<[u8]>; 2],
3233
bloom_count: [usize; 2],

0 commit comments

Comments
 (0)