Skip to content

Commit

Permalink
Add AC command to reset the vpn-api client
Browse files Browse the repository at this point in the history
  • Loading branch information
octol committed Feb 18, 2025
1 parent 95aa867 commit 6937dac
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 0 deletions.
11 changes: 11 additions & 0 deletions nym-vpn-core/crates/nym-vpn-account-controller/src/commander.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ impl AccountControllerCommander {
.map_err(RequestZkNymError::internal)?;
rx.await.map_err(RequestZkNymError::internal)?
}

pub async fn reset_vpn_api_client(
&self,
vpn_api_client: nym_vpn_api_client::VpnApiClient,
) -> Result<(), AccountCommandError> {
let (tx, rx) = ReturnSender::new();
self.command_tx
.send(AccountCommand::ResetVpnApiClient(tx, vpn_api_client))
.map_err(AccountCommandError::internal)?;
rx.await.map_err(AccountCommandError::internal)?
}
}

// Set of commands used to ensure that the account controller is in the correct state before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ pub enum AccountCommand {
GetZkNymById(String),
ConfirmZkNymIdDownloaded(String),
GetAvailableTickets(ReturnSender<AvailableTicketbooks, AccountCommandError>),
ResetVpnApiClient(
ReturnSender<(), AccountCommandError>,
nym_vpn_api_client::VpnApiClient,
),
}

impl AccountCommand {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ impl CachedData {
}
}

pub fn update_vpn_api_client(&mut self, vpn_api_client: VpnApiClient) {
self.vpn_api_client = vpn_api_client;
}

pub async fn get_partial_verification_keys(
&self,
epoch_id: u64,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ impl WaitingRequestZkNymCommandHandler {
pub(crate) async fn max_fails_reached(&self) -> bool {
self.zk_nym_fails_in_a_row.load(Ordering::Relaxed) >= ZK_NYM_MAX_FAILS
}

pub(crate) fn update_vpn_api_client(&mut self, vpn_api_client: VpnApiClient) {
self.vpn_api_client = vpn_api_client.clone();
self.cached_data.update_vpn_api_client(vpn_api_client);
}
}

pub(crate) struct RequestZkNymCommandHandler {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ impl WaitingSyncAccountCommandHandler {
previous_account_summary_response: self.previous_account_summary_response.clone(),
}
}

pub(crate) fn update_vpn_api_client(
&mut self,
vpn_api_client: nym_vpn_api_client::VpnApiClient,
) {
self.vpn_api_client = vpn_api_client;
}
}

pub(crate) struct SyncStateCommandHandler {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ impl WaitingSyncDeviceCommandHandler {
previous_devices_response: self.previous_devices_response.clone(),
}
}

pub(crate) fn update_vpn_api_client(
&mut self,
vpn_api_client: nym_vpn_api_client::VpnApiClient,
) {
self.vpn_api_client = vpn_api_client;
}
}

pub(crate) struct SyncDeviceStateCommandHandler {
Expand Down
10 changes: 10 additions & 0 deletions nym-vpn-core/crates/nym-vpn-account-controller/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,16 @@ where
let result = self.handle_get_available_tickets().await;
result_tx.send(result);
}
AccountCommand::ResetVpnApiClient(result_tx, vpn_api_client) => {
self.vpn_api_client = vpn_api_client.clone();
self.waiting_sync_account_command_handler
.update_vpn_api_client(vpn_api_client.clone());
self.waiting_sync_device_command_handler
.update_vpn_api_client(vpn_api_client.clone());
self.waiting_request_zknym_command_handler
.update_vpn_api_client(vpn_api_client);
result_tx.send(Ok(()));
}
};
}

Expand Down

0 comments on commit 6937dac

Please sign in to comment.