Skip to content

Commit 646fd16

Browse files
authored
feat(gossipsub): log when sending and receiving gossipsub messages
To help with the upcoming [partial messages](sigp#577) Pull-Request: #6234.
1 parent 1c9fd89 commit 646fd16

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

protocols/gossipsub/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
## 0.50.0
2+
- Log when sending and receiving messages.
3+
See [PR 6234](https://github.com/libp2p/rust-libp2p/pull/6234)
4+
25
- Prevent mesh exceeding mesh_n_high.
36
See [PR 6184](https://github.com/libp2p/rust-libp2p/pull/6184)
47

protocols/gossipsub/src/behaviour.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3140,6 +3140,7 @@ where
31403140
// This clones a reference to the Queue so any new handlers reference the same underlying
31413141
// queue. No data is actually cloned here.
31423142
Ok(Handler::new(
3143+
peer_id,
31433144
self.config.protocol_config(),
31443145
connected_peer.messages.clone(),
31453146
))
@@ -3169,6 +3170,7 @@ where
31693170
// This clones a reference to the Queue so any new handlers reference the same underlying
31703171
// queue. No data is actually cloned here.
31713172
Ok(Handler::new(
3173+
peer_id,
31723174
self.config.protocol_config(),
31733175
connected_peer.messages.clone(),
31743176
))
@@ -3228,6 +3230,7 @@ where
32283230
rpc,
32293231
invalid_messages,
32303232
} => {
3233+
tracing::debug!(peer=%propagation_source, message=?rpc, "Received gossipsub message");
32313234
// Handle the gossipsub RPC
32323235

32333236
// Handle subscriptions

protocols/gossipsub/src/handler.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use std::{
2525

2626
use asynchronous_codec::Framed;
2727
use futures::{future::Either, prelude::*, StreamExt};
28-
use libp2p_core::upgrade::DeniedUpgrade;
28+
use libp2p_core::{upgrade::DeniedUpgrade, PeerId};
2929
use libp2p_swarm::{
3030
handler::{
3131
ConnectionEvent, ConnectionHandler, ConnectionHandlerEvent, DialUpgradeError,
@@ -89,6 +89,9 @@ pub enum Handler {
8989

9090
/// Protocol Handler that manages a single long-lived substream with a peer.
9191
pub struct EnabledHandler {
92+
/// Remote `PeerId` for this `ConnectionHandler`.
93+
peer_id: PeerId,
94+
9295
/// Upgrade configuration for the gossipsub protocol.
9396
listen_protocol: ProtocolConfig,
9497

@@ -162,8 +165,13 @@ enum OutboundSubstreamState {
162165

163166
impl Handler {
164167
/// Builds a new [`Handler`].
165-
pub(crate) fn new(protocol_config: ProtocolConfig, message_queue: Queue) -> Self {
168+
pub(crate) fn new(
169+
peer_id: PeerId,
170+
protocol_config: ProtocolConfig,
171+
message_queue: Queue,
172+
) -> Self {
166173
Handler::Enabled(EnabledHandler {
174+
peer_id,
167175
listen_protocol: protocol_config,
168176
inbound_substream: None,
169177
outbound_substream: None,
@@ -254,6 +262,7 @@ impl EnabledHandler {
254262
Some(OutboundSubstreamState::WaitingOutput(substream)) => {
255263
if let Poll::Ready(mut message) = Pin::new(&mut self.message_queue).poll_pop(cx)
256264
{
265+
tracing::debug!(peer=%self.peer_id, ?message, "Sending gossipsub message");
257266
match message {
258267
RpcOut::Publish {
259268
message: _,

0 commit comments

Comments
 (0)