pub struct AddressManager { /* private fields */ }Expand description
Simple single ISD-AS address registry.
Implementations§
Source§impl AddressManager
impl AddressManager
Sourcepub fn new(
isd_as: IsdAsn,
prefixes: Vec<IpNet>,
rng: ChaCha8Rng,
) -> Result<Self, AllocatorCreationError>
pub fn new( isd_as: IsdAsn, prefixes: Vec<IpNet>, rng: ChaCha8Rng, ) -> Result<Self, AllocatorCreationError>
Create a new address registry for the given ISD-AS and prefixes.
Sourcepub fn with_hold_duration(self, hold_duration: Duration) -> Self
pub fn with_hold_duration(self, hold_duration: Duration) -> Self
Set the hold duration for address grants.
Sourcepub fn with_max_attempts(self, max_attempts: usize) -> Self
pub fn with_max_attempts(self, max_attempts: usize) -> Self
Set the maximum number of attempts to allocate an address.
Sourcepub fn match_isd_as(&self, isd_as: IsdAsn) -> bool
pub fn match_isd_as(&self, isd_as: IsdAsn) -> bool
Checks if the given ISD-AS matches the registry’s ISD-AS.
Sourcepub fn register(
&mut self,
id: String,
isd_asn: IsdAsn,
addr: IpAddr,
) -> Result<AddressGrant, AddressRegistrationError>
pub fn register( &mut self, id: String, isd_asn: IsdAsn, addr: IpAddr, ) -> Result<AddressGrant, AddressRegistrationError>
Registers a new Address, will remove current grant if id is reused
§Parameters
id: Unique identifier of the allocation. Oneidcan only have one Grant.isd_asn: The IsdAsn associated with this address allocation.addr: The requested IP address. Use std::net::Ipv4Addr::UNSPECIFIED or std::net::Ipv6Addr::UNSPECIFIED to request any available address.
Sourcepub fn put_on_hold(
&mut self,
id: String,
duration_since_start: Duration,
) -> bool
pub fn put_on_hold( &mut self, id: String, duration_since_start: Duration, ) -> bool
Puts a grant on hold for the default hold period
After this period has passed, the address can be freed by the cleanup job.
Sourcepub fn free(&mut self, id: &String) -> bool
pub fn free(&mut self, id: &String) -> bool
Immediately frees an address
Returns true if address existed and was freed, otherwise false
Sourcepub fn min_free_addresses(&self) -> u128
pub fn min_free_addresses(&self) -> u128
Get the minimal count of free addresses of this registry
Call Self::clean_expired before this to get the actual count
Sourcepub fn clean_expired(
&mut self,
duration_since_start: Duration,
) -> (usize, usize)
pub fn clean_expired( &mut self, duration_since_start: Duration, ) -> (usize, usize)
Checks all grants and removes expired grants
Should be called periodically
Returns (grant_count_before, grant_count_after)
Trait Implementations§
Source§impl Clone for AddressManager
impl Clone for AddressManager
Source§fn clone(&self) -> AddressManager
fn clone(&self) -> AddressManager
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AddressManager
impl Debug for AddressManager
Source§impl From<&AddressManager> for AddressManagerDto
impl From<&AddressManager> for AddressManagerDto
Source§fn from(state: &AddressManager) -> Self
fn from(state: &AddressManager) -> Self
Source§impl PartialEq for AddressManager
impl PartialEq for AddressManager
Source§impl TryFrom<AddressManagerDto> for AddressManager
impl TryFrom<AddressManagerDto> for AddressManager
impl Eq for AddressManager
impl StructuralPartialEq for AddressManager
Auto Trait Implementations§
impl Freeze for AddressManager
impl RefUnwindSafe for AddressManager
impl Send for AddressManager
impl Sync for AddressManager
impl Unpin for AddressManager
impl UnwindSafe for AddressManager
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,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request