Skip to content

Commit

Permalink
Update rendezvous_mediator.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangbo8418 authored Feb 4, 2024
1 parent 0244982 commit d56bfb6
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/rendezvous_mediator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,11 @@ impl RendezvousMediator {

let mut timer = interval(TIMER_OUT);
let mut last_timer: Option<Instant> = None;
const MIN_REG_TIMEOUT: i64 = 3_000;
const MAX_REG_TIMEOUT: i64 = 30_000;
let mut reg_timeout = MIN_REG_TIMEOUT;
// const MIN_REG_TIMEOUT: i64 = 3_000;
// const MAX_REG_TIMEOUT: i64 = 30_000;
// let mut reg_timeout = MIN_REG_TIMEOUT;
const REG_TIMEOUT: i64 = 3_000;

const MAX_FAILS1: i64 = 2;
const MAX_FAILS2: i64 = 4;
const DNS_INTERVAL: i64 = 60_000;
Expand All @@ -170,7 +172,7 @@ impl RendezvousMediator {
let mut update_latency = || {
last_register_resp = Some(Instant::now());
fails = 0;
reg_timeout = MIN_REG_TIMEOUT;
// reg_timeout = MIN_REG_TIMEOUT;
let mut latency = last_register_sent
.map(|x| x.elapsed().as_micros() as i64)
.unwrap_or(0);
Expand Down Expand Up @@ -221,14 +223,16 @@ impl RendezvousMediator {
}
last_timer = now;
let expired = last_register_resp.map(|x| x.elapsed().as_millis() as i64 >= REG_INTERVAL).unwrap_or(true);
let timeout = last_register_sent.map(|x| x.elapsed().as_millis() as i64 >= reg_timeout).unwrap_or(false);
if timeout && reg_timeout < MAX_REG_TIMEOUT {
reg_timeout += MIN_REG_TIMEOUT;
}
let timeout = last_register_sent.map(|x| x.elapsed().as_millis() as i64 >= REG_TIMEOUT).unwrap_or(false);
// let timeout = last_register_sent.map(|x| x.elapsed().as_millis() as i64 >= reg_timeout).unwrap_or(false);
// if timeout && reg_timeout < MAX_REG_TIMEOUT {
// reg_timeout += MIN_REG_TIMEOUT;
// }
if timeout || (last_register_sent.is_none() && expired) {
if timeout {
fails += 1;
if fails >= MAX_FAILS2 {
// if fails >= MAX_FAILS2 {
if fails > MAX_FAILS2 {
Config::update_latency(&host, -1);
old_latency = 0;
if last_dns_check.elapsed().as_millis() as i64 > DNS_INTERVAL {
Expand All @@ -240,7 +244,8 @@ impl RendezvousMediator {
}
last_dns_check = Instant::now();
}
} else if fails >= MAX_FAILS1 {
// } else if fails >= MAX_FAILS1 {
} else if fails > MAX_FAILS1 {
Config::update_latency(&host, 0);
old_latency = 0;
}
Expand Down

0 comments on commit d56bfb6

Please sign in to comment.