Skip to main content

Leases

Struct Leases 

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

Stores the leases and other information used across leasing functions in memory.

The leases are also written to a file on disk to preserve state in the event that something, such as a power outage, causes the server to stop. This file is attempted to be read, parsed, and validated during Leases creation during Server start. After which it is only written to in order to sync it with its in-memory state. Therefore, changing the file when the server is running will have no effect and may impact syncing to the file correctly.

Implementations§

Source§

impl Leases

Source

pub const FILE_NAME: &'static str = "toe-beans.leases"

The file name that the Leases is read from and written to.

Source

pub fn get_config(&self) -> &LeaseConfig

Once you pass a LeaseConfig to Leases, Leases privately owns it, but you can use this fn to borrow an immutable reference.

Source

pub fn new(config: LeaseConfig) -> Self

Depending on whether the passed config enables use_leases_file: Restore and validate the leases file or create a new, empty Leases.

Source

pub fn offer( &mut self, owner: MacAddress, requested_ip: Option<Ipv4Addr>, ) -> Result<Ipv4Addr>

Takes an available IP address, marks it as offered, and returns it.

Returns one of:

  • The previously offered address, if one has been offered.
  • The requested address:
    • If one was requested,
    • and it is available,
    • and there is not a static lease
  • Otherwise any available address (unless none are available).
Source

pub fn ack(&mut self, owner: MacAddress) -> Result<Ipv4Addr>

Takes a chaddr’s offered ip address and marks it as reserved then commits it to persistent storage and returns the address.

Source

pub fn extend(&mut self, owner: MacAddress) -> Result<()>

Resets the time of an offered or acked lease. Used by the server in the lease renew/rebind process.

Source

pub fn release(&mut self, owner: MacAddress) -> Result<()>

Makes an ip address that was offered or acked available again.

Source

pub fn is_available(&self, ip: &Ipv4Addr) -> bool

Checks whether the passed IP address is available in the pool.

Source

pub fn verify_lease(&self, owner: MacAddress, ip: &Ipv4Addr) -> Result<()>

Checks if the passed IP address matches the committed, leased IP address, and that the lease is not expired.

Trait Implementations§

Source§

impl Debug for Leases

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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, 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, 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