From 8d013bab0dbbea9313018ddd352f8b03d6bf2d16 Mon Sep 17 00:00:00 2001 From: Pranay Tulugu Date: Mon, 18 Sep 2023 13:52:50 -0700 Subject: [PATCH] Run exit manager ping test only when registered to an exit --- rita_client/src/exit_manager/exit_loop.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/rita_client/src/exit_manager/exit_loop.rs b/rita_client/src/exit_manager/exit_loop.rs index ceebedee5..a729295e1 100644 --- a/rita_client/src/exit_manager/exit_loop.rs +++ b/rita_client/src/exit_manager/exit_loop.rs @@ -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.