Remove legacy Clogged event (#6652)

This commit is contained in:
Pierre Krieger
2020-07-14 17:43:08 +02:00
committed by GitHub
parent ef4dfc612c
commit 4613dc2af4
5 changed files with 15 additions and 83 deletions
@@ -310,15 +310,6 @@ pub enum GenericProtoOut {
/// Message that has been received.
message: BytesMut,
},
/// The substream used by the protocol is pretty large. We should print avoid sending more
/// messages on it if possible.
Clogged {
/// Id of the peer which is clogged.
peer_id: PeerId,
/// Copy of the messages that are within the buffer, for further diagnostic.
messages: Vec<Vec<u8>>,
},
}
impl GenericProto {
@@ -1312,18 +1303,6 @@ impl NetworkBehaviour for GenericProto {
self.events.push_back(NetworkBehaviourAction::GenerateEvent(event));
}
NotifsHandlerOut::Clogged { messages } => {
debug_assert!(self.is_open(&source));
trace!(target: "sub-libp2p", "Handler({:?}) => Clogged", source);
trace!(target: "sub-libp2p", "External API <= Clogged({:?})", source);
warn!(target: "sub-libp2p", "Queue of packets to send to {:?} is \
pretty large", source);
self.events.push_back(NetworkBehaviourAction::GenerateEvent(GenericProtoOut::Clogged {
peer_id: source,
messages,
}));
}
// Don't do anything for non-severe errors except report them.
NotifsHandlerOut::ProtocolError { is_severe, ref error } if !is_severe => {
debug!(target: "sub-libp2p", "Handler({:?}) => Benign protocol error: {:?}",
@@ -215,13 +215,6 @@ pub enum NotifsHandlerOut {
message: BytesMut,
},
/// A substream to the remote is clogged. The send buffer is very large, and we should print
/// a diagnostic message and/or avoid sending more data.
Clogged {
/// Copy of the messages that are within the buffer, for further diagnostic.
messages: Vec<Vec<u8>>,
},
/// An error has happened on the protocol level with this node.
ProtocolError {
/// If true the error is severe, such as a protocol violation.
@@ -484,10 +477,6 @@ impl ProtocolsHandler for NotifsHandler {
Poll::Ready(ProtocolsHandlerEvent::Custom(
NotifsHandlerOut::CustomMessage { message }
)),
ProtocolsHandlerEvent::Custom(LegacyProtoHandlerOut::Clogged { messages }) =>
Poll::Ready(ProtocolsHandlerEvent::Custom(
NotifsHandlerOut::Clogged { messages }
)),
ProtocolsHandlerEvent::Custom(LegacyProtoHandlerOut::ProtocolError { is_severe, error }) =>
Poll::Ready(ProtocolsHandlerEvent::Custom(
NotifsHandlerOut::ProtocolError { is_severe, error }
@@ -236,13 +236,6 @@ pub enum LegacyProtoHandlerOut {
message: BytesMut,
},
/// A substream to the remote is clogged. The send buffer is very large, and we should print
/// a diagnostic message and/or avoid sending more data.
Clogged {
/// Copy of the messages that are within the buffer, for further diagnostic.
messages: Vec<Vec<u8>>,
},
/// An error has happened on the protocol level with this node.
ProtocolError {
/// If true the error is severe, such as a protocol violation.
@@ -395,13 +388,19 @@ impl LegacyProtoHandler {
self.state = ProtocolState::Normal { substreams, shutdown };
return Some(ProtocolsHandlerEvent::Custom(event));
},
Poll::Ready(Some(Ok(RegisteredProtocolEvent::Clogged { messages }))) => {
let event = LegacyProtoHandlerOut::Clogged {
messages,
};
substreams.push(substream);
self.state = ProtocolState::Normal { substreams, shutdown };
return Some(ProtocolsHandlerEvent::Custom(event));
Poll::Ready(Some(Ok(RegisteredProtocolEvent::Clogged))) => {
shutdown.push(substream);
if substreams.is_empty() {
let event = LegacyProtoHandlerOut::CustomProtocolClosed {
reason: "Legacy substream clogged".into(),
endpoint: self.endpoint.clone()
};
self.state = ProtocolState::Disabled {
shutdown: shutdown.into_iter().collect(),
reenable: true
};
return Some(ProtocolsHandlerEvent::Custom(event));
}
}
Poll::Ready(None) => {
shutdown.push(substream);
@@ -142,10 +142,7 @@ pub enum RegisteredProtocolEvent {
/// Diagnostic event indicating that the connection is clogged and we should avoid sending too
/// many messages to it.
Clogged {
/// Copy of the messages that are within the buffer, for further diagnostic.
messages: Vec<Vec<u8>>,
},
Clogged,
}
impl<TSubstream> Stream for RegisteredProtocolSubstream<TSubstream>
@@ -183,11 +180,7 @@ where TSubstream: AsyncRead + AsyncWrite + Unpin {
// if you remove the fuse, then we will always return early from this function and
// thus never read any message from the network.
self.clogged_fuse = true;
return Poll::Ready(Some(Ok(RegisteredProtocolEvent::Clogged {
messages: self.send_queue.iter()
.map(|m| m.clone().to_vec())
.collect(),
})))
return Poll::Ready(Some(Ok(RegisteredProtocolEvent::Clogged)))
}
} else {
self.clogged_fuse = false;