refactor reg_timeout to reduce fail try
This commit is contained in:
parent
1f16b5236b
commit
2cf83b41cc
@ -154,7 +154,9 @@ impl RendezvousMediator {
|
||||
|
||||
let mut timer = interval(TIMER_OUT);
|
||||
let mut last_timer: Option<Instant> = None;
|
||||
const REG_TIMEOUT: i64 = 3_000;
|
||||
const MIN_REG_TIMEOUT: i64 = 3_000;
|
||||
const MAX_REG_TIMEOUT: i64 = 30_000;
|
||||
let mut reg_timeout = MIN_REG_TIMEOUT;
|
||||
const MAX_FAILS1: i64 = 3;
|
||||
const MAX_FAILS2: i64 = 6;
|
||||
const DNS_INTERVAL: i64 = 60_000;
|
||||
@ -168,6 +170,7 @@ impl RendezvousMediator {
|
||||
let mut update_latency = || {
|
||||
last_register_resp = Some(Instant::now());
|
||||
fails = 0;
|
||||
reg_timeout = MIN_REG_TIMEOUT;
|
||||
let mut latency = last_register_sent
|
||||
.map(|x| x.elapsed().as_micros() as i64)
|
||||
.unwrap_or(0);
|
||||
@ -218,11 +221,14 @@ 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);
|
||||
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 {
|
||||
Config::update_latency(&host, -1);
|
||||
old_latency = 0;
|
||||
if last_dns_check.elapsed().as_millis() as i64 > DNS_INTERVAL {
|
||||
@ -234,7 +240,7 @@ impl RendezvousMediator {
|
||||
}
|
||||
last_dns_check = Instant::now();
|
||||
}
|
||||
} else if fails > MAX_FAILS1 {
|
||||
} else if fails >= MAX_FAILS1 {
|
||||
Config::update_latency(&host, 0);
|
||||
old_latency = 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user