pub struct AddressList { /* private fields */ }Expand description
A structure to manage DAPI addresses to select from for DapiRequest execution.
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 ban(&self, address: &Address) -> bool
pub fn ban(&self, address: &Address) -> bool
Bans address 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>
Randomly select a not banned address.
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 [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);Trait Implementations§
Source§impl Clone for AddressList
impl Clone for AddressList
Source§fn clone(&self) -> AddressList
fn clone(&self) -> AddressList
1.0.0 · 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 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
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>
Source§impl<T, U> IntoPlatformVersioned<U> for Twhere
U: FromPlatformVersioned<T>,
impl<T, U> IntoPlatformVersioned<U> for Twhere
U: FromPlatformVersioned<T>,
Source§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].