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
impl Leases
Sourcepub const FILE_NAME: &'static str = "toe-beans.leases"
pub const FILE_NAME: &'static str = "toe-beans.leases"
The file name that the Leases is read from and written to.
Sourcepub fn get_config(&self) -> &LeaseConfig
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.
Sourcepub fn new(config: LeaseConfig) -> Self
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.
Sourcepub fn offer(
&mut self,
owner: MacAddress,
requested_ip: Option<Ipv4Addr>,
) -> Result<Ipv4Addr>
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).
Sourcepub fn ack(&mut self, owner: MacAddress) -> Result<Ipv4Addr>
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.
Sourcepub fn extend(&mut self, owner: MacAddress) -> Result<()>
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.
Sourcepub fn release(&mut self, owner: MacAddress) -> Result<()>
pub fn release(&mut self, owner: MacAddress) -> Result<()>
Makes an ip address that was offered or acked available again.
Sourcepub fn is_available(&self, ip: &Ipv4Addr) -> bool
pub fn is_available(&self, ip: &Ipv4Addr) -> bool
Checks whether the passed IP address is available in the pool.
Sourcepub fn verify_lease(&self, owner: MacAddress, ip: &Ipv4Addr) -> Result<()>
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.