Skip to content

Commit a04e92c

Browse files
authored
feat(shadowsocks): add more Debug implementations (shadowsocks#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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 10 additions & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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,

0 commit comments

Comments
 (0)