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() -> AddressList
pub fn new() -> AddressList
Creates an empty AddressList with default base ban time.
Sourcepub fn with_settings(base_ban_period: Duration) -> AddressList
pub fn with_settings(base_ban_period: Duration) -> AddressList
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.
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>
Randomly select a not-banned address.
An address is considered live when it has never been banned or when its ban period has already expired.
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 · 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§fn default() -> AddressList
fn default() -> AddressList
Source§impl FromIterator<Address> for AddressList
impl FromIterator<Address> for AddressList
Source§fn from_iter<T>(iter: T) -> AddressListwhere
T: IntoIterator<Item = Address>,
fn from_iter<T>(iter: T) -> AddressListwhere
T: IntoIterator<Item = Address>,
Source§impl FromStr for AddressList
impl FromStr for AddressList
Source§type Err = AddressListError
type Err = AddressListError
Source§fn from_str(s: &str) -> Result<AddressList, <AddressList as FromStr>::Err>
fn from_str(s: &str) -> Result<AddressList, <AddressList as FromStr>::Err>
s to return a value of this type. Read moreSource§impl IntoIterator for AddressList
impl IntoIterator for AddressList
Source§type Item = (Address, AddressStatus)
type Item = (Address, AddressStatus)
Source§type IntoIter = IntoIter<Address, AddressStatus>
type IntoIter = IntoIter<Address, AddressStatus>
Source§fn into_iter(self) -> <AddressList as IntoIterator>::IntoIter
fn into_iter(self) -> <AddressList as IntoIterator>::IntoIter
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> CostsExt for T
impl<T> CostsExt for T
§fn wrap_with_cost(self, cost: OperationCost) -> CostContext<Self>where
Self: Sized,
fn wrap_with_cost(self, cost: OperationCost) -> CostContext<Self>where
Self: Sized,
CostContext object with provided costs.§fn wrap_fn_cost(
self,
f: impl FnOnce(&Self) -> OperationCost,
) -> CostContext<Self>where
Self: Sized,
fn wrap_fn_cost(
self,
f: impl FnOnce(&Self) -> OperationCost,
) -> CostContext<Self>where
Self: Sized,
CostContext object with costs computed using the
value getting wrapped.§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§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> 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>
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>
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§impl<T, U> IntoOnNetwork<U> for Twhere
U: FromOnNetwork<T>,
impl<T, U> IntoOnNetwork<U> for Twhere
U: FromOnNetwork<T>,
§fn into_on_network(self, network: Network) -> U
fn into_on_network(self, network: Network) -> U
Calls U::from_on_network(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].§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.