BootstrapCache

Struct BootstrapCache 

Source
pub struct BootstrapCache { /* private fields */ }
Expand description

Greedy bootstrap cache with quality-based peer selection.

This cache stores peer information with quality metrics and provides epsilon-greedy selection to balance exploitation (using known-good peers) with exploration (trying new peers to discover potentially better ones).

Implementations§

Source§

impl BootstrapCache

Source

pub async fn open(config: BootstrapCacheConfig) -> Result<Self>

Open or create a bootstrap cache.

Loads existing cache data from disk if available, otherwise starts fresh.

Source

pub fn subscribe(&self) -> Receiver<CacheEvent>

Subscribe to cache events

Source

pub async fn peer_count(&self) -> usize

Get the number of cached peers

Source

pub async fn select_peers(&self, count: usize) -> Vec<CachedPeer>

Select peers for bootstrap using epsilon-greedy strategy.

Returns up to count peers, balancing exploitation of known-good peers with exploration of untested peers based on the configured epsilon.

Source

pub async fn select_relay_peers(&self, count: usize) -> Vec<CachedPeer>

Select peers that support relay functionality.

Returns peers sorted by quality score that have relay capability.

Source

pub async fn select_coordinators(&self, count: usize) -> Vec<CachedPeer>

Select peers that support NAT coordination.

Returns peers sorted by quality score that have coordination capability.

Source

pub async fn upsert(&self, peer: CachedPeer)

Add or update a peer in the cache.

If the cache is at capacity, evicts the lowest quality peers.

Source

pub async fn add_seed(&self, peer_id: PeerId, addresses: Vec<SocketAddr>)

Add a seed peer (user-provided bootstrap node).

Source

pub async fn add_from_connection( &self, peer_id: PeerId, addresses: Vec<SocketAddr>, caps: Option<PeerCapabilities>, )

Add a peer discovered from an active connection.

Source

pub async fn record_outcome(&self, peer_id: &PeerId, outcome: ConnectionOutcome)

Record a connection attempt result.

Source

pub async fn record_success(&self, peer_id: &PeerId, rtt_ms: u32)

Record successful connection.

Source

pub async fn record_failure(&self, peer_id: &PeerId)

Record failed connection.

Source

pub async fn update_capabilities( &self, peer_id: &PeerId, caps: PeerCapabilities, )

Update peer capabilities.

Source

pub async fn get(&self, peer_id: &PeerId) -> Option<CachedPeer>

Get a specific peer.

Source

pub async fn contains(&self, peer_id: &PeerId) -> bool

Check if peer exists in cache.

Source

pub async fn remove(&self, peer_id: &PeerId) -> Option<CachedPeer>

Remove a peer from cache.

Source

pub async fn save(&self) -> Result<()>

Save cache to disk.

Source

pub async fn cleanup_stale(&self) -> usize

Cleanup stale peers.

Removes peers that haven’t been seen within the stale threshold. Returns the number of peers removed.

Source

pub async fn recalculate_quality(&self)

Recalculate quality scores for all peers.

Source

pub async fn stats(&self) -> CacheStats

Get cache statistics.

Source

pub fn start_maintenance(self: Arc<Self>) -> JoinHandle<()>

Start background maintenance tasks.

Spawns a task that periodically:

  • Saves the cache to disk
  • Cleans up stale peers
  • Recalculates quality scores

Returns a handle that can be used to cancel the task.

Source

pub async fn all_peers(&self) -> Vec<CachedPeer>

Get all cached peers (for export/debug).

Source

pub fn config(&self) -> &BootstrapCacheConfig

Get the configuration.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more