pub struct AddressList { /* private fields */ }Expand description
A structure to manage DAPI addresses to select from for DapiRequest execution.
Address selection is sticky: requests rotate over a small active set of addresses (5 by default, see AddressList::with_active_set_size) and the rest of the list serves as failover standby (see AddressList::get_live_address).
Implementations§
Source§impl AddressList
impl AddressList
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty AddressList with default base ban time.
Sourcepub fn with_settings(base_ban_period: Duration) -> Self
pub fn with_settings(base_ban_period: Duration) -> Self
Creates an empty AddressList with adjustable base ban time.
Sourcepub fn with_active_set_size(self, size: usize) -> Self
pub fn with_active_set_size(self, size: usize) -> Self
Set how many addresses receive traffic at a time.
Defaults to 5. 0 is clamped to 1. Smaller values maximize connection
reuse, larger values spread load over more nodes. The effective size is
additionally capped by the number of live addresses, so a very large
value (e.g. usize::MAX) disables stickiness and round-robins over the
whole list.
The size lives in the rotation state shared by every clone of this list, so it applies to all clones and takes effect on the next selection (shrinking drops the excess members).
Sourcepub fn ban(&self, address: &Address) -> bool
pub fn ban(&self, address: &Address) -> bool
Bans address Returns false if the address is not in the list.
Back-compat shim for AddressList::ban_with_reason with no reason.
Sourcepub fn ban_with_reason(&self, address: &Address, reason: Option<String>) -> bool
pub fn ban_with_reason(&self, address: &Address, reason: Option<String>) -> bool
Bans address, recording the reason for the ban.
Returns false if the address is not in the list.
Sourcepub fn ban_for(
&self,
address: &Address,
period: Duration,
reason: Option<String>,
) -> bool
pub fn ban_for( &self, address: &Address, period: Duration, reason: Option<String>, ) -> bool
Ban the address for an exact period (server-advertised); delegates to
AddressStatus::ban_for — see that method for the full contract
including the ban_count floor and ladder side-effect.
Returns false if the address is not in the list.
Sourcepub fn unban(&self, address: &Address) -> bool
pub fn unban(&self, address: &Address) -> bool
Clears address’ ban record Returns false if the address is not in the list.
Sourcepub fn add(&mut self, address: Address) -> bool
pub fn add(&mut self, address: Address) -> bool
Adds a node Address to AddressList Returns false if the address is already in the list.
Sourcepub fn remove(&mut self, address: &Address) -> Option<AddressStatus>
pub fn remove(&mut self, address: &Address) -> Option<AddressStatus>
Remove address from the list Returns AddressStatus if the address was in the list.
Sourcepub fn add_uri(&mut self, uri: Uri) -> bool
👎Deprecated
pub fn add_uri(&mut self, uri: Uri) -> bool
Add a node Address to AddressList by Uri. Returns false if the address is already in the list.
Sourcepub fn get_live_address(&self) -> Option<Address>
pub fn get_live_address(&self) -> Option<Address>
Select a not-banned address to send the next request to.
Not a pure getter: every call advances the shared rotation cursor and may promote or retire active-set members, steering traffic for all clones of this list.
Selection is sticky: requests rotate round-robin over a small active set of addresses (see AddressList::with_active_set_size) instead of sampling the whole list, so connections to those hosts stay warm. An active address that got banned, removed or evicted on failover (see AddressList::evict_from_rotation) is dropped from the set here and a random live standby address is promoted in its place. Each slot also expires after a jittered lifetime (5–7.5 minutes). Evicted and expired members are used to refill slots only after all live standbys have been selected, preserving availability when alternatives are scarce.
An address is considered live when it has never been banned or when its ban period has already expired.
Sourcepub fn evict_from_rotation(&self, address: &Address)
pub fn evict_from_rotation(&self, address: &Address)
Drop address from the sticky active set, leaving its ban state
untouched; the next selection prefers a random live standby in its
place, falling back to evicted members if there are too few standbys.
This is the failover path for callers that disable banning (RequestSettings::ban_failed_address): a failing node yields its slot’s traffic to an available standby even when it is never banned.
Sourcepub fn get_live_addresses(&self) -> Vec<Address>
pub fn get_live_addresses(&self) -> Vec<Address>
Get all not banned addresses.
Returns a vector of addresses that are not currently banned or whose ban period has expired.
The returned addresses use the same filtering logic as Self::get_live_address, checking if the
ban period has expired based on the current time.
§Examples
use rs_dapi_client::{AddressList, Address};
let mut list = AddressList::new();
list.add("http://127.0.0.1:3000".parse().unwrap());
list.add("http://127.0.0.1:3001".parse().unwrap());
// Get all non-banned addresses
let live_addresses = list.get_live_addresses();
assert_eq!(live_addresses.len(), 2);Sourcepub fn ban_info(&self) -> Vec<AddressBanInfo>
pub fn ban_info(&self) -> Vec<AddressBanInfo>
Get an owned snapshot of every address’ ban state.
Clones the current state into an owned Vec<AddressBanInfo> so
it can be inspected without holding the internal lock. The
banned flag reflects the currently effectively banned
semantics used by AddressList::get_live_address: the address
has been banned at least once (ban_count > 0) and its ban
period has not yet expired (banned_until is in the future).
Trait Implementations§
Source§impl Clone for AddressList
impl Clone for AddressList
Source§fn clone(&self) -> AddressList
fn clone(&self) -> AddressList
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AddressList
impl Debug for AddressList
Source§impl Default for AddressList
impl Default for AddressList
Source§impl FromIterator<Address> for AddressList
impl FromIterator<Address> for AddressList
Source§impl FromStr for AddressList
impl FromStr for AddressList
Source§impl IntoIterator for AddressList
impl IntoIterator for AddressList
Auto Trait Implementations§
impl Freeze for AddressList
impl RefUnwindSafe for AddressList
impl Send for AddressList
impl Sync for AddressList
impl Unpin for AddressList
impl UnsafeUnpin for AddressList
impl UnwindSafe for AddressList
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T, U> IntoPlatformVersioned<U> for Twhere
U: FromPlatformVersioned<T>,
impl<T, U> IntoPlatformVersioned<U> for Twhere
U: FromPlatformVersioned<T>,
§fn into_platform_versioned(self, platform_version: &PlatformVersion) -> U
fn into_platform_versioned(self, platform_version: &PlatformVersion) -> U
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].