pub struct AckOptimizer { /* private fields */ }Expand description
ACK optimizer for reducing network load from acknowledgments.
Implementations§
Source§impl AckOptimizer
impl AckOptimizer
Sourcepub fn new(local_device_id: impl Into<String>) -> Self
pub fn new(local_device_id: impl Into<String>) -> Self
Creates a new ACK optimizer with default configuration.
Sourcepub fn with_config(
local_device_id: impl Into<String>,
config: AckOptimizationConfig,
) -> Self
pub fn with_config( local_device_id: impl Into<String>, config: AckOptimizationConfig, ) -> Self
Creates a new ACK optimizer with custom configuration.
Sourcepub fn should_relay_ack(
&self,
ack_message_id: &str,
visible_peer_count: usize,
) -> bool
pub fn should_relay_ack( &self, ack_message_id: &str, visible_peer_count: usize, ) -> bool
Determines if this node should relay a received ACK.
Uses deterministic pseudo-random selection based on ACK ID and local device ID to ensure consistent relay decisions across the network.
§Arguments
ack_message_id- ID of the ACK message being relayedvisible_peer_count- Number of visible peers in the network
§Returns
true if this node should relay the ACK, false otherwise.
Sourcepub fn add_ack_for_aggregation(
&mut self,
destination: &str,
original_message_id: MessageId,
hop_count: u8,
) -> Option<Vec<AggregatedAck>>
pub fn add_ack_for_aggregation( &mut self, destination: &str, original_message_id: MessageId, hop_count: u8, ) -> Option<Vec<AggregatedAck>>
Adds an ACK to the pending aggregation buffer.
§Arguments
destination- User ID of the original message sender (ACK destination)original_message_id- ID of the message being acknowledgedhop_count- Number of hops the original message traveled
§Returns
Some(Vec<AggregatedAck>) if batch is ready for transmission, None otherwise.
Sourcepub fn flush_pending_acks(
&mut self,
destination: &str,
) -> Option<Vec<AggregatedAck>>
pub fn flush_pending_acks( &mut self, destination: &str, ) -> Option<Vec<AggregatedAck>>
Flushes pending ACKs for a destination.
Sourcepub fn get_timed_out_destinations(&self) -> Vec<String>
pub fn get_timed_out_destinations(&self) -> Vec<String>
Gets destinations with ACKs that have timed out and should be flushed.
§Returns
A vector of destination user IDs whose ACK buffers should be flushed.
Sourcepub fn drain_timed_out(&mut self) -> Vec<(String, Vec<AggregatedAck>)>
pub fn drain_timed_out(&mut self) -> Vec<(String, Vec<AggregatedAck>)>
Drains all timed-out ACK batches.
§Returns
A vector of (destination, acks) tuples for destinations that timed out.
Sourcepub fn get_piggyback_acks(
&mut self,
message_destination: &str,
) -> Option<PiggybackAckData>
pub fn get_piggyback_acks( &mut self, message_destination: &str, ) -> Option<PiggybackAckData>
Sourcepub fn pending_destination_count(&self) -> usize
pub fn pending_destination_count(&self) -> usize
Returns the number of pending ACK destinations.
Sourcepub fn pending_ack_count(&self) -> usize
pub fn pending_ack_count(&self) -> usize
Returns the total number of pending ACKs.
Sourcepub fn config(&self) -> &AckOptimizationConfig
pub fn config(&self) -> &AckOptimizationConfig
Gets the configuration.