From b002c2b38f6fe1c03a2d270c2bf61fe451ba39db Mon Sep 17 00:00:00 2001 From: Katia Fredes Date: Tue, 6 Aug 2024 15:38:24 -0400 Subject: [PATCH] add: server state struct --- src/async_resolver.rs | 1 + src/async_resolver/server_state.rs | 35 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/async_resolver/server_state.rs diff --git a/src/async_resolver.rs b/src/async_resolver.rs index a94eb24a..25991b74 100644 --- a/src/async_resolver.rs +++ b/src/async_resolver.rs @@ -5,6 +5,7 @@ pub mod resolver_error; pub mod server_info; pub mod slist; pub mod state_block; +pub mod server_state; use self::lookup_response::LookupResponse; use crate::async_resolver::resolver_error::ResolverError; diff --git a/src/async_resolver/server_state.rs b/src/async_resolver/server_state.rs new file mode 100644 index 00000000..1f3d3318 --- /dev/null +++ b/src/async_resolver/server_state.rs @@ -0,0 +1,35 @@ +use crate::async_resolver::server_info::ServerInfo; + +/// Struct that holds the state of the queried server for a single request. +/// +/// 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. +pub struct ServerState { + name_servers: Vec, + current_server_index: usize, +} + +impl ServerState { + /// Creates a new ServerState for a request. + /// + /// # Arguments + /// * `name_servers` - A vector of ServerInfo structs that represent the name servers to query. + /// + /// # Example + /// ``` + /// let server_state = ServerState::new(vec![ServerInfo::new(" + /// + /// ``` + pub fn new(name_servers: Vec) -> ServerState { + ServerState { + name_servers: name_servers, + current_server_index: 0, + } + } + + /// Returns a reference to the `name_servers` of the request. + pub fn get_name_servers(&self) -> &Vec { + return &self.name_servers; + } +} \ No newline at end of file