pub struct FlowController { /* private fields */ }Expand description
Main flow controller
Coordinates rate limiting, queue management, and resource tracking for all peers.
Implementations§
Source§impl FlowController
impl FlowController
Sourcepub fn new() -> FlowController
pub fn new() -> FlowController
Create a new flow controller with default config
Sourcepub fn with_config(config: FlowControlConfig) -> FlowController
pub fn with_config(config: FlowControlConfig) -> FlowController
Create a new flow controller with custom config
Sourcepub fn check_sync_allowed(
&self,
peer_id: &PublicKey,
doc_key: &str,
) -> Result<(), FlowControlError>
pub fn check_sync_allowed( &self, peer_id: &PublicKey, doc_key: &str, ) -> Result<(), FlowControlError>
Check if a sync operation is allowed
Performs all flow control checks:
- Rate limiting (token bucket)
- Sync cooldown (storm prevention)
- Resource limits (memory)
Returns Ok(()) if allowed, Err with specific reason if blocked.
Sourcepub fn record_sync(&self, peer_id: &PublicKey, doc_key: &str)
pub fn record_sync(&self, peer_id: &PublicKey, doc_key: &str)
Record a successful sync operation
Updates cooldown tracker to prevent sync storms.
Sourcepub fn get_resource_tracker(
&self,
peer_id: &PublicKey,
) -> Arc<PeerResourceTracker>
pub fn get_resource_tracker( &self, peer_id: &PublicKey, ) -> Arc<PeerResourceTracker>
Get or create resource tracker for peer
Sourcepub fn stats(&self) -> FlowControlStats
pub fn stats(&self) -> FlowControlStats
Get current statistics
Sourcepub fn config(&self) -> &FlowControlConfig
pub fn config(&self) -> &FlowControlConfig
Get current config
Sourcepub fn available_tokens(&self, peer_id: &PublicKey) -> u32
pub fn available_tokens(&self, peer_id: &PublicKey) -> u32
Get available tokens for a peer
Trait Implementations§
Source§impl Default for FlowController
impl Default for FlowController
Source§fn default() -> FlowController
fn default() -> FlowController
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !Freeze for FlowController
impl RefUnwindSafe for FlowController
impl Send for FlowController
impl Sync for FlowController
impl Unpin for FlowController
impl UnsafeUnpin for FlowController
impl UnwindSafe for FlowController
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more