Skip to content

Commit

Permalink
add: clone
Browse files Browse the repository at this point in the history
  • Loading branch information
justRkive committed Aug 15, 2024
1 parent 9c88861 commit 7e92baa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
9 changes: 5 additions & 4 deletions src/async_resolver/server_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::async_resolver::server_entry::ServerEntry;
/// A structure which describes the name servers which the resolver is
/// currently trying to query. This structure keeps track of the state of a
/// request if it must wait for answers from other name servers.
#[derive(Clone)]
pub struct ServerState {
servers: Vec<ServerEntry>,
current_server_index: usize,
Expand Down Expand Up @@ -36,10 +37,10 @@ impl ServerState {
self.current_server_index = (self.current_server_index + 1)%(self.servers.len());
}

/// Returns a refererece to the current `ServerInfo` of the request.
pub fn get_current_server(&self) -> &ServerInfo {
return &self.servers[self.current_server_index].get_info();
}
// /// Returns a refererece to the current `ServerInfo` of the request.
// pub fn get_current_server(&self) -> &ServerInfo {
// return &self.servers[self.current_server_index].get_info();
// }

pub fn get_current_server_entry(&mut self) -> &mut ServerEntry {
&mut self.servers[self.current_server_index]
Expand Down
11 changes: 6 additions & 5 deletions src/async_resolver/state_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use super::server_info::ServerInfo;
///
/// The key algorithm uses the state information of the request to select the
/// next name server address to query.
#[derive(Clone)]
pub struct StateBlock {
/// A timestamp indicating the time the request began.
///
Expand All @@ -28,7 +29,7 @@ pub struct StateBlock {
/// be decremented each time the resolver performs work on behalf of
/// the request. If the counter reaches zero, the resolver must
/// return a response to the client.
work_counter: u32,
work_counter: u16,

server_state: ServerState,
}
Expand All @@ -43,7 +44,7 @@ impl StateBlock {
/// ```
/// let state_block = StateBlock::new(Instant::now());
/// ```
pub fn new(request_global_limit: u32, servers: Vec<ServerInfo>) -> StateBlock {
pub fn new(request_global_limit: u16, servers: Vec<ServerInfo>) -> StateBlock {
StateBlock {
timestamp: Instant::now(),
work_counter: request_global_limit,
Expand Down Expand Up @@ -74,11 +75,11 @@ impl StateBlock {
}

/// Returns a the `work_counter` of the request.
pub fn get_work_counter(&self) -> u32 {
pub fn get_work_counter(&self) -> u16 {
return self.work_counter;
}

pub fn get_server_state(&self) -> &ServerState {
&self.server_state
pub fn get_server_state(&mut self) -> &mut ServerState {
&mut self.server_state
}
}

0 comments on commit 7e92baa

Please sign in to comment.