mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 08:41:07 +00:00
Improve warning about notifications queue and remove spurious triggers (#5512)
* Better logging for notifications and buffer size increase * Address review * Improve warning about notifications queue and remove spurious triggers
This commit is contained in:
@@ -43,8 +43,7 @@ use unsigned_varint::codec::UviBytes;
|
||||
|
||||
/// Maximum allowed size of the two handshake messages, in bytes.
|
||||
const MAX_HANDSHAKE_SIZE: usize = 1024;
|
||||
/// Maximum number of buffered messages before we consider the remote unresponsive and kill the
|
||||
/// substream.
|
||||
/// Maximum number of buffered messages before we refuse to accept more.
|
||||
const MAX_PENDING_MESSAGES: usize = 256;
|
||||
|
||||
/// Upgrade that accepts a substream, sends back a status message, then becomes a unidirectional
|
||||
@@ -285,6 +284,18 @@ impl<TSubstream> NotificationsOutSubstream<TSubstream> {
|
||||
pub fn queue_len(&self) -> u32 {
|
||||
u32::try_from(self.messages_queue.len()).unwrap_or(u32::max_value())
|
||||
}
|
||||
|
||||
/// Push a message to the queue of messages.
|
||||
///
|
||||
/// This has the same effect as the `Sink::start_send` implementation.
|
||||
pub fn push_message(&mut self, item: Vec<u8>) -> Result<(), NotificationsOutError> {
|
||||
if self.messages_queue.len() >= MAX_PENDING_MESSAGES {
|
||||
return Err(NotificationsOutError::Clogged);
|
||||
}
|
||||
|
||||
self.messages_queue.push_back(item);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<TSubstream> Sink<Vec<u8>> for NotificationsOutSubstream<TSubstream>
|
||||
@@ -297,12 +308,7 @@ impl<TSubstream> Sink<Vec<u8>> for NotificationsOutSubstream<TSubstream>
|
||||
}
|
||||
|
||||
fn start_send(mut self: Pin<&mut Self>, item: Vec<u8>) -> Result<(), Self::Error> {
|
||||
if self.messages_queue.len() >= MAX_PENDING_MESSAGES {
|
||||
return Err(NotificationsOutError::Clogged);
|
||||
}
|
||||
|
||||
self.messages_queue.push_back(item);
|
||||
Ok(())
|
||||
self.push_message(item)
|
||||
}
|
||||
|
||||
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<(), Self::Error>> {
|
||||
|
||||
Reference in New Issue
Block a user