Skip to content

Commit

Permalink
Run exit manager ping test only when registered to an exit
Browse files Browse the repository at this point in the history
  • Loading branch information
Pranay Tulugu committed Sep 18, 2023
1 parent 2631eae commit ce84f6f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
22 changes: 14 additions & 8 deletions rita_client/src/exit_manager/exit_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,22 @@ pub fn start_exit_manager_loop() {
}
};

// Run this ping test every PING_TEST_SPEED seconds
if Instant::now() - em_state.last_connection_time > PING_TEST_SPEED {
if run_ping_test() {
em_state.last_connection_time = Instant::now();
} else {
// If this router has been in a bad state for >10 mins, reboot
if (Instant::now() - em_state.last_connection_time) > REBOOT_TIMEOUT {
let _res = KI.run_command("reboot", &[]);
// Run ping test only when we are registered to prevent constant reboots
if let ExitState::Registered { .. } = exit.info {
// Run this ping test every PING_TEST_SPEED seconds
if Instant::now() - em_state.last_connection_time > PING_TEST_SPEED {
if run_ping_test() {
em_state.last_connection_time = Instant::now();
} else {
// If this router has been in a bad state for >10 mins, reboot
if (Instant::now() - em_state.last_connection_time) > REBOOT_TIMEOUT {
let _res = KI.run_command("reboot", &[]);
}
}
}
} else {
// reset our reboot timer every tick if not registered
em_state.last_connection_time = Instant::now();
}

// Get cluster exit list. This is saved locally and updated every tick depending on what exit we connect to.
Expand Down
2 changes: 1 addition & 1 deletion rita_client/src/exit_manager/exit_switcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ mod tests {
u16::MAX,
tracking_exit,
u16::MAX,
best_exit,
best_exit,
400
),
&mut vec,
Expand Down

0 comments on commit ce84f6f

Please sign in to comment.