Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add warning for sending on non-registered protocol
  • Loading branch information
tomaka committed Aug 31, 2020
commit b1fade9cb996d5485130fa79bc5f0940a59b5c0d
28 changes: 25 additions & 3 deletions client/network/src/protocol/generic_proto/handler/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,12 +576,34 @@ impl ProtocolsHandler for NotifsHandler {
protocol_name,
message
} => {
let mut found_any_with_name = false;

for (handler, _) in &mut self.out_handlers {
if *handler.protocol_name() == protocol_name && handler.is_open() {
handler.send_or_discard(message);
continue 'poll_notifs_sink;
if *handler.protocol_name() == protocol_name {
found_any_with_name = true;
if handler.is_open() {
handler.send_or_discard(message);
continue 'poll_notifs_sink;
}
}
}

// If this code is reached, there exists two possibilities:
//
// - User tried to send a notification on a non-existing protocol. This
// most likely relates to https://github.com/paritytech/substrate/issues/6827
// - User tried to send a notification to a peer we're not or no longer
// connected to. This happens in a normal scenario due to the racy nature
// of connections and disconnections, and is benign.
//
// We print a warning in the former condition.
if !found_any_with_name {
log::warn!(
target: "sub-libp2p",
"Tried to send a notification on non-registered protocol: {:?}",
protocol_name
);
}
}
NotificationsSinkMessage::ForceClose => {
return Poll::Ready(ProtocolsHandlerEvent::Close(NotifsHandlerError::SyncNotificationsClogged));
Expand Down