-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: timestamp getter and constructor
- Loading branch information
Showing
1 changed file
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,43 @@ | ||
use tokio::time::Instant; | ||
|
||
/// This struct represent the state of information of a pending request. | ||
/// | ||
/// [RFC 1035](https://datatracker.ietf.org/doc/html/rfc1035#section-7.1) | ||
/// | ||
/// Since a resolver must be able to multiplex multiple requests if it is to | ||
/// perform its function efficiently, each pending request is usually | ||
/// represented in some block of state information. | ||
/// | ||
/// The key algorithm uses the state information of the request to select the next name server address to | ||
/// query | ||
pub struct StateBlock { | ||
timestamp: u64, | ||
/// A timestamp indicating the time the request began. | ||
/// | ||
/// The timestamp is used to decide whether RRs in the database | ||
/// can be used or are out of date. This timestamp uses the | ||
/// absolute time format. | ||
timestamp: Instant, | ||
} | ||
|
||
impl StateBlock { | ||
/// Creates a new StateBlock for a request. | ||
/// | ||
/// # Arguments | ||
/// * `timestamp` - A Instant that represents the time the request began. | ||
/// | ||
/// # Example | ||
/// ``` | ||
/// let state_block = StateBlock::new(Instant::now()); | ||
/// ``` | ||
pub fn new() -> StateBlock { | ||
StateBlock { | ||
timestamp: Instant::now(), | ||
} | ||
} | ||
|
||
/// Returns a reference to the `timestamp` of the request. | ||
pub fn get_timestamp(&self) -> &Instant { | ||
return &self.timestamp; | ||
} | ||
|
||
} |