Skip to content

Commit 6937dac

Browse files
committed
Add AC command to reset the vpn-api client
1 parent 95aa867 commit 6937dac

File tree

7 files changed

+48
-0
lines changed

7 files changed

+48
-0
lines changed

nym-vpn-core/crates/nym-vpn-account-controller/src/commander.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,17 @@ impl AccountControllerCommander {
128128
.map_err(RequestZkNymError::internal)?;
129129
rx.await.map_err(RequestZkNymError::internal)?
130130
}
131+
132+
pub async fn reset_vpn_api_client(
133+
&self,
134+
vpn_api_client: nym_vpn_api_client::VpnApiClient,
135+
) -> Result<(), AccountCommandError> {
136+
let (tx, rx) = ReturnSender::new();
137+
self.command_tx
138+
.send(AccountCommand::ResetVpnApiClient(tx, vpn_api_client))
139+
.map_err(AccountCommandError::internal)?;
140+
rx.await.map_err(AccountCommandError::internal)?
141+
}
131142
}
132143

133144
// Set of commands used to ensure that the account controller is in the correct state before

nym-vpn-core/crates/nym-vpn-account-controller/src/commands/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ pub enum AccountCommand {
9898
GetZkNymById(String),
9999
ConfirmZkNymIdDownloaded(String),
100100
GetAvailableTickets(ReturnSender<AvailableTicketbooks, AccountCommandError>),
101+
ResetVpnApiClient(
102+
ReturnSender<(), AccountCommandError>,
103+
nym_vpn_api_client::VpnApiClient,
104+
),
101105
}
102106

103107
impl AccountCommand {

nym-vpn-core/crates/nym-vpn-account-controller/src/commands/request_zknym/cached_data.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ impl CachedData {
2727
}
2828
}
2929

30+
pub fn update_vpn_api_client(&mut self, vpn_api_client: VpnApiClient) {
31+
self.vpn_api_client = vpn_api_client;
32+
}
33+
3034
pub async fn get_partial_verification_keys(
3135
&self,
3236
epoch_id: u64,

nym-vpn-core/crates/nym-vpn-account-controller/src/commands/request_zknym/handler.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ impl WaitingRequestZkNymCommandHandler {
8585
pub(crate) async fn max_fails_reached(&self) -> bool {
8686
self.zk_nym_fails_in_a_row.load(Ordering::Relaxed) >= ZK_NYM_MAX_FAILS
8787
}
88+
89+
pub(crate) fn update_vpn_api_client(&mut self, vpn_api_client: VpnApiClient) {
90+
self.vpn_api_client = vpn_api_client.clone();
91+
self.cached_data.update_vpn_api_client(vpn_api_client);
92+
}
8893
}
8994

9095
pub(crate) struct RequestZkNymCommandHandler {

nym-vpn-core/crates/nym-vpn-account-controller/src/commands/sync_account.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ impl WaitingSyncAccountCommandHandler {
4646
previous_account_summary_response: self.previous_account_summary_response.clone(),
4747
}
4848
}
49+
50+
pub(crate) fn update_vpn_api_client(
51+
&mut self,
52+
vpn_api_client: nym_vpn_api_client::VpnApiClient,
53+
) {
54+
self.vpn_api_client = vpn_api_client;
55+
}
4956
}
5057

5158
pub(crate) struct SyncStateCommandHandler {

nym-vpn-core/crates/nym-vpn-account-controller/src/commands/sync_device.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ impl WaitingSyncDeviceCommandHandler {
5151
previous_devices_response: self.previous_devices_response.clone(),
5252
}
5353
}
54+
55+
pub(crate) fn update_vpn_api_client(
56+
&mut self,
57+
vpn_api_client: nym_vpn_api_client::VpnApiClient,
58+
) {
59+
self.vpn_api_client = vpn_api_client;
60+
}
5461
}
5562

5663
pub(crate) struct SyncDeviceStateCommandHandler {

nym-vpn-core/crates/nym-vpn-account-controller/src/controller.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,16 @@ where
734734
let result = self.handle_get_available_tickets().await;
735735
result_tx.send(result);
736736
}
737+
AccountCommand::ResetVpnApiClient(result_tx, vpn_api_client) => {
738+
self.vpn_api_client = vpn_api_client.clone();
739+
self.waiting_sync_account_command_handler
740+
.update_vpn_api_client(vpn_api_client.clone());
741+
self.waiting_sync_device_command_handler
742+
.update_vpn_api_client(vpn_api_client.clone());
743+
self.waiting_request_zknym_command_handler
744+
.update_vpn_api_client(vpn_api_client);
745+
result_tx.send(Ok(()));
746+
}
737747
};
738748
}
739749

0 commit comments

Comments
 (0)