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

Remove dumping packet content in Debug... #988

Closed
wants to merge 1 commit into from
Closed
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
19 changes: 18 additions & 1 deletion src/hp/derp/client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! based on tailscale/derp/derp_client.go
use std::fmt;
use std::net::SocketAddr;
use std::sync::Arc;
use std::time::Duration;
Expand Down Expand Up @@ -546,7 +547,7 @@ fn get_key_from_slice(payload: &[u8]) -> Result<PublicKey> {
Ok(<[u8; PUBLIC_KEY_LENGTH]>::try_from(payload)?.into())
}

#[derive(Debug, Clone)]
#[derive(Clone)]
pub enum ReceivedMessage {
/// Represents an incoming packet.
ReceivedPacket {
Expand Down Expand Up @@ -605,6 +606,22 @@ pub enum ReceivedMessage {
},
}

impl fmt::Debug for ReceivedMessage {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::ReceivedPacket { source, data } => f.debug_struct("ReceivedPacket").field("source", source).field("data", &data.len()).finish(),
Self::PeerGone(arg0) => f.debug_tuple("PeerGone").field(arg0).finish(),
Self::PeerPresent(arg0) => f.debug_tuple("PeerPresent").field(arg0).finish(),
Self::ServerInfo { token_bucket_bytes_per_second, token_bucket_bytes_burst } => f.debug_struct("ServerInfo").field("token_bucket_bytes_per_second", token_bucket_bytes_per_second).field("token_bucket_bytes_burst", token_bucket_bytes_burst).finish(),
Self::Ping(arg0) => f.debug_tuple("Ping").field(arg0).finish(),
Self::Pong(arg0) => f.debug_tuple("Pong").field(arg0).finish(),
Self::KeepAlive => write!(f, "KeepAlive"),
Self::Health { problem } => f.debug_struct("Health").field("problem", problem).finish(),
Self::ServerRestarting { reconnect_in, try_for } => f.debug_struct("ServerRestarting").field("reconnect_in", reconnect_in).field("try_for", try_for).finish(),
}
}
}

pub(crate) async fn send_packet<W: AsyncWrite + Unpin>(
mut writer: W,
rate_limiter: &Option<RateLimiter>,
Expand Down
13 changes: 11 additions & 2 deletions src/hp/magicsock/conn.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{
collections::{HashMap, HashSet, VecDeque},
fmt::Debug,
fmt::{Debug, self},
io::{self, IoSliceMut},
mem::MaybeUninit,
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr},
Expand Down Expand Up @@ -676,14 +676,23 @@ enum NetworkSource {
Derp,
}

#[derive(Debug)]
struct DerpReadResult {
region_id: u16,
src: key::node::PublicKey,
/// packet data
buf: BytesMut,
}

impl fmt::Debug for DerpReadResult {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("DerpReadResult")
.field("region_id", &self.region_id)
.field("src", &self.src)
.field("buf", &self.buf.len())
.finish()
}
}

/// Contains fields for an active DERP connection.
#[derive(Debug)]
struct ActiveDerp {
Expand Down
Loading