Shorten debug for messages

This commit is contained in:
Igor Katson 2023-11-30 17:28:32 +00:00
parent 558aa3f246
commit 32a220f17c
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
2 changed files with 31 additions and 5 deletions

View file

@ -163,17 +163,27 @@ struct RawMessage<BufT, Args = IgnoredAny, Resp = IgnoredAny> {
ip: Option<CompactPeerInfo>, ip: Option<CompactPeerInfo>,
} }
#[derive(Debug)]
pub struct Node { pub struct Node {
pub id: Id20, pub id: Id20,
pub addr: SocketAddrV4, pub addr: SocketAddrV4,
} }
#[derive(Debug)] impl core::fmt::Debug for Node {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "<{:?}; {}>", self.id, self.addr)
}
}
pub struct CompactNodeInfo { pub struct CompactNodeInfo {
pub nodes: Vec<Node>, pub nodes: Vec<Node>,
} }
impl core::fmt::Debug for CompactNodeInfo {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self.nodes)
}
}
impl Serialize for CompactNodeInfo { impl Serialize for CompactNodeInfo {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where where
@ -230,11 +240,16 @@ impl<'de> Deserialize<'de> for CompactNodeInfo {
} }
} }
#[derive(Debug)]
pub struct CompactPeerInfo { pub struct CompactPeerInfo {
pub addr: SocketAddrV4, pub addr: SocketAddrV4,
} }
impl core::fmt::Debug for CompactPeerInfo {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self.addr)
}
}
impl Serialize for CompactPeerInfo { impl Serialize for CompactPeerInfo {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where where
@ -343,7 +358,6 @@ impl Message<ByteString> {
} }
} }
#[derive(Debug)]
pub enum MessageKind<BufT> { pub enum MessageKind<BufT> {
Error(ErrorDescription<BufT>), Error(ErrorDescription<BufT>),
GetPeersRequest(GetPeersRequest), GetPeersRequest(GetPeersRequest),
@ -352,6 +366,18 @@ pub enum MessageKind<BufT> {
PingRequest(PingRequest), PingRequest(PingRequest),
} }
impl<BufT: core::fmt::Debug> core::fmt::Debug for MessageKind<BufT> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Error(e) => write!(f, "{e:?}"),
Self::GetPeersRequest(r) => write!(f, "{r:?}"),
Self::FindNodeRequest(r) => write!(f, "{r:?}"),
Self::Response(r) => write!(f, "{r:?}"),
Self::PingRequest(r) => write!(f, "{r:?}"),
}
}
}
pub fn serialize_message<'a, W: Write, BufT: Serialize + From<&'a [u8]>>( pub fn serialize_message<'a, W: Write, BufT: Serialize + From<&'a [u8]>>(
writer: &mut W, writer: &mut W,
transaction_id: BufT, transaction_id: BufT,

View file

@ -638,7 +638,7 @@ impl DhtState {
_ => {} _ => {}
}; };
trace!("received query: {:?}", msg); trace!("received query from {addr}: {msg:?}");
match &msg.kind { match &msg.kind {
// Otherwise, respond to a query. // Otherwise, respond to a query.