mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-12 17:41:22 +00:00
Debug instance for the gossipsub behaviour (#1673)
* Add debug instances for MessageCache and GossipSub behaviour * Manual impl of Debug for GossipsubMessage * Add pretty printing of protocol_id in debug * Use hex_fmt instead of hex * Inline StringOrBytes helper struct Since it is used only once here * Limit data of gossipsub msg to 20 bytes Otherwise they might become very large and useless for debugging
This commit is contained in:
@ -29,7 +29,7 @@ use futures::prelude::*;
|
||||
use futures_codec::{Decoder, Encoder, Framed};
|
||||
use libp2p_core::{InboundUpgrade, OutboundUpgrade, PeerId, UpgradeInfo};
|
||||
use prost::Message as ProtobufMessage;
|
||||
use std::{borrow::Cow, io, iter, pin::Pin};
|
||||
use std::{borrow::Cow, fmt, io, iter, pin::Pin};
|
||||
use unsigned_varint::codec;
|
||||
|
||||
/// Implementation of the `ConnectionUpgrade` for the Gossipsub protocol.
|
||||
@ -336,7 +336,7 @@ impl Into<String> for MessageId {
|
||||
}
|
||||
|
||||
/// A message received by the gossipsub system.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
pub struct GossipsubMessage {
|
||||
/// Id of the peer that published this message.
|
||||
pub source: PeerId,
|
||||
@ -353,6 +353,17 @@ pub struct GossipsubMessage {
|
||||
pub topics: Vec<TopicHash>,
|
||||
}
|
||||
|
||||
impl fmt::Debug for GossipsubMessage {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("GossipsubMessage")
|
||||
.field("data",&format_args!("{:<20}", &hex_fmt::HexFmt(&self.data)))
|
||||
.field("source", &self.source)
|
||||
.field("sequence_number", &self.sequence_number)
|
||||
.field("topics", &self.topics)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
/// A subscription received by the gossipsub system.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct GossipsubSubscription {
|
||||
|
Reference in New Issue
Block a user