Skip to content

Commit

Permalink
add: work counter for server receives maximum limit
Browse files Browse the repository at this point in the history
  • Loading branch information
justRkive committed Sep 21, 2024
1 parent e95b4c8 commit 6e73839
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
21 changes: 8 additions & 13 deletions src/async_resolver/server_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,26 @@ use crate::async_resolver::server_info::ServerInfo;
#[derive(Clone)]
pub struct ServerEntry {
info: ServerInfo,
retransmissions: u32,
work_counter: u16,
}

impl ServerEntry {
pub fn new(info: ServerInfo) -> ServerEntry {
pub fn new(info: ServerInfo, work_counter: u16) -> ServerEntry {
ServerEntry {
info,
retransmissions: 0,
// is_active: true,
work_counter: work_counter,
}
}

pub fn get_info(&self) -> &ServerInfo {
&self.info// TODO: see if this is necessary to use clone or not, in order to reuse TCP connections
&self.info // TODO: see if this is necessary to use clone or not, in order to reuse TCP connections
}

pub fn get_retransmissions(&self) -> u32 {
self.retransmissions
pub fn get_work_counter(&self) -> u16 {
self.work_counter
}

pub fn increment_retransmissions(&mut self) {
self.retransmissions += 1;
}

pub fn reset_retransmissions(&mut self) {
self.retransmissions = 0;
pub fn decrement_work_counter(&mut self) {
self.work_counter -= 1;
}
}
4 changes: 2 additions & 2 deletions src/async_resolver/state_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ impl StateBlock {
/// ```
/// let state_block = StateBlock::new(Instant::now());
/// ```
pub fn new(request_global_limit: u16, servers: Vec<ServerInfo>) -> StateBlock {
pub fn new(request_global_limit: u16, server_transmission_limit: u16, servers: Vec<ServerInfo>) -> StateBlock {
StateBlock {
timestamp: Instant::now(),
work_counter: request_global_limit,
servers: servers.into_iter().map(ServerEntry::new).collect(),
servers: servers.into_iter().map(|server| ServerEntry::new(server, server_transmission_limit)).collect(),
current_server_index: 0,
}
}
Expand Down

0 comments on commit 6e73839

Please sign in to comment.