struct ProgressMessageBuffer {
buffer_capacity: BufferSize,
buffer: BTreeMap<ViewNumber, VecDeque<(VerifyingKey, ProgressMessage)>>,
buffer_size: BufferSize,
}Expand description
Message buffer intended for storing received ProgressMessages for future views.
Its size is bounded by its capacity, and when the capacity is reached messages for highest views may be removed.
Fields§
§buffer_capacity: BufferSize§buffer: BTreeMap<ViewNumber, VecDeque<(VerifyingKey, ProgressMessage)>>§buffer_size: BufferSizeImplementations§
source§impl ProgressMessageBuffer
impl ProgressMessageBuffer
sourcefn new(buffer_capacity: BufferSize) -> Self
fn new(buffer_capacity: BufferSize) -> Self
Create an empty message buffer.
sourcefn insert<M: Into<ProgressMessage> + Cacheable>(
&mut self,
msg: M,
sender: VerifyingKey,
) -> bool
fn insert<M: Into<ProgressMessage> + Cacheable>( &mut self, msg: M, sender: VerifyingKey, ) -> bool
Try inserting the message into the buffer. In case caching the message makes the buffer grow beyond its capacity, this function either:
- If the message has the highest view among the views of messages currently in the buffer, then the message is dropped, or
- Otherwise, just enough highest-viewed messages are removed from the buffer to make space for the new message.
Returns whether the message was successfully inserted into the buffer.
sourcefn get_msg(
&mut self,
view: &ViewNumber,
) -> Option<(VerifyingKey, ProgressMessage)>
fn get_msg( &mut self, view: &ViewNumber, ) -> Option<(VerifyingKey, ProgressMessage)>
If there are messages for this view in the buffer, remove and return the message at the front of the queue.
sourcefn remove_highest_viewed_msgs(&mut self, bytes_to_remove: u64)
fn remove_highest_viewed_msgs(&mut self, bytes_to_remove: u64)
Given the number of bytes that need to be removed, removes just enough highest-viewed messages to free up (at least) the required number of bytes in the buffer.
sourcefn remove_expired_msgs(&mut self, cur_view: ViewNumber)
fn remove_expired_msgs(&mut self, cur_view: ViewNumber)
Remove all messages for views less than the current view.