Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make exit status requests for registered and GotInfo routers only eve… #801

Merged
merged 1 commit into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions rita_client/src/exit_manager/exit_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ use std::time::{Duration, Instant};
const EXIT_LOOP_SPEED: Duration = Duration::from_secs(5);
const PING_TEST_SPEED: Duration = Duration::from_secs(100);
const REBOOT_TIMEOUT: Duration = Duration::from_secs(600);
/// How often we make a exit status request for registered exits. Prevents us from bogging up exit processing
/// power
const STATUS_REQUEST_QUERY: Duration = Duration::from_secs(600);

/// This asnyc loop runs functions related to Exit management.
pub fn start_exit_manager_loop() {
Expand Down Expand Up @@ -239,6 +242,7 @@ pub fn start_exit_manager_loop() {
// code that manages requesting details to exits, run in parallel becuse they respond slowly
let mut general_requests = Vec::new();
let mut status_requests = Vec::new();
let mut exit_status_requested = false;
let servers = { settings::get_rita_client().exit_client.exits };
for (k, s) in servers {
match s.info {
Expand All @@ -250,7 +254,16 @@ pub fn start_exit_manager_loop() {
// Ops has registered us. This will move our GotInfo -> Registered state for an exit
ExitState::GotInfo { .. } => {
trace!("Exit {} is in state GotInfo, calling status request", k);
status_requests.push(exit_status_request(k.clone()))
// This is only for clients registered via ops
if let Some(last_query) = em_state.last_status_request {
if Instant::now() - last_query > STATUS_REQUEST_QUERY {
exit_status_requested = true;
status_requests.push(exit_status_request(k.clone()));
}
} else {
exit_status_requested = true;
status_requests.push(exit_status_request(k.clone()));
}
},
// For routers that register normally, (not through ops), GotInfo -> Pending. In this state, we
// continue to query until we reach Registered
Expand All @@ -260,13 +273,25 @@ pub fn start_exit_manager_loop() {
},
ExitState::Registered { .. } => {
trace!("Exit {} is in state Registered, calling status request", k);
status_requests.push(exit_status_request(k.clone()));
// Make a status request every STATUS_REQUEST_QUERY seconds
if let Some(last_query) = em_state.last_status_request {
if Instant::now() - last_query > STATUS_REQUEST_QUERY {
exit_status_requested = true;
status_requests.push(exit_status_request(k.clone()));
}
} else {
exit_status_requested = true;
status_requests.push(exit_status_request(k.clone()));
}
},
_ => {
trace!("Exit {} is in state {:?} calling status request", k, s.info);
}
}
}
if exit_status_requested {
em_state.last_status_request = Some(Instant::now());
}
join!(join_all(general_requests), join_all(status_requests));

// This block runs after an exit manager tick (an exit is selected),
Expand Down
3 changes: 3 additions & 0 deletions rita_client/src/exit_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ pub struct ExitManager {
pub last_exit: Option<IpAddr>,
/// Store exit connection status. If no update in > 10, perform a power cycle
pub last_connection_time: Instant,
/// Store the last exit status request for all registered exits
pub last_status_request: Option<Instant>,
}

impl Default for ExitManager {
Expand All @@ -99,6 +101,7 @@ impl Default for ExitManager {
exit_list: ExitList::default(),
last_exit: None,
last_connection_time: Instant::now(),
last_status_request: None,
}
}
}
Expand Down
Loading