sc-network: Log outgoing notifications too (#7624)

* Log outgoing notifications too

* Update client/network/src/protocol/generic_proto/handler.rs

Co-authored-by: Max Inden <mail@max-inden.de>

Co-authored-by: Addie Wagenknecht <addie@nortd.com>
Co-authored-by: Max Inden <mail@max-inden.de>
This commit is contained in:
Pierre Krieger
2020-11-30 11:52:08 +01:00
committed by GitHub
parent f6dc35284f
commit a2b14d10fb
3 changed files with 52 additions and 6 deletions
+22 -1
View File
@@ -664,7 +664,7 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkService<B, H> {
// `peers_notifications_sinks` mutex as soon as possible.
let sink = {
let peers_notifications_sinks = self.peers_notifications_sinks.lock();
if let Some(sink) = peers_notifications_sinks.get(&(target, protocol.clone())) {
if let Some(sink) = peers_notifications_sinks.get(&(target.clone(), protocol.clone())) {
sink.clone()
} else {
// Notification silently discarded, as documented.
@@ -684,6 +684,14 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkService<B, H> {
}
// Sending is communicated to the `NotificationsSink`.
trace!(
target: "sub-libp2p",
"External API => Notification({:?}, {:?}, {} bytes)",
target,
protocol,
message.len()
);
trace!(target: "sub-libp2p", "Handler({:?}) <= Sync notification", target);
sink.send_sync_notification(protocol, message);
}
@@ -1139,6 +1147,7 @@ impl NotificationSender {
Ok(r) => r,
Err(()) => return Err(NotificationSenderError::Closed),
},
peer_id: self.sink.peer_id(),
notification_size_metric: self.notification_size_metric.clone(),
})
}
@@ -1149,6 +1158,9 @@ impl NotificationSender {
pub struct NotificationSenderReady<'a> {
ready: Ready<'a>,
/// Target of the notification.
peer_id: &'a PeerId,
/// Field extracted from the [`Metrics`] struct and necessary to report the
/// notifications-related metrics.
notification_size_metric: Option<Histogram>,
@@ -1163,6 +1175,15 @@ impl<'a> NotificationSenderReady<'a> {
notification_size_metric.observe(notification.len() as f64);
}
trace!(
target: "sub-libp2p",
"External API => Notification({:?}, {:?}, {} bytes)",
self.peer_id,
self.ready.protocol_name(),
notification.len()
);
trace!(target: "sub-libp2p", "Handler({:?}) <= Async notification", self.peer_id);
self.ready
.send(notification)
.map_err(|()| NotificationSenderError::Closed)