Shorten debug for messages
This commit is contained in:
parent
558aa3f246
commit
32a220f17c
2 changed files with 31 additions and 5 deletions
|
|
@ -163,17 +163,27 @@ struct RawMessage<BufT, Args = IgnoredAny, Resp = IgnoredAny> {
|
|||
ip: Option<CompactPeerInfo>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Node {
|
||||
pub id: Id20,
|
||||
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 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 {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
|
|
@ -230,11 +240,16 @@ impl<'de> Deserialize<'de> for CompactNodeInfo {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct CompactPeerInfo {
|
||||
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 {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
|
|
@ -343,7 +358,6 @@ impl Message<ByteString> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum MessageKind<BufT> {
|
||||
Error(ErrorDescription<BufT>),
|
||||
GetPeersRequest(GetPeersRequest),
|
||||
|
|
@ -352,6 +366,18 @@ pub enum MessageKind<BufT> {
|
|||
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]>>(
|
||||
writer: &mut W,
|
||||
transaction_id: BufT,
|
||||
|
|
|
|||
|
|
@ -638,7 +638,7 @@ impl DhtState {
|
|||
_ => {}
|
||||
};
|
||||
|
||||
trace!("received query: {:?}", msg);
|
||||
trace!("received query from {addr}: {msg:?}");
|
||||
|
||||
match &msg.kind {
|
||||
// Otherwise, respond to a query.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue