Skip to content

Commit

Permalink
Extend diagnostics and info types for accounts (#1369)
Browse files Browse the repository at this point in the history
* Structured return type for account state

* Add missing states

* Add IsAccountStored to vpnc

* Update the some of the names in the proto API

* github workflow updates

* Add notice about restart required

* Fix downcast

* Reduce logging a tad

* Update another set of names

* Add sandbox

* Add account check for fetch calls

* Handle DeviceState::DeleteMe

* update tauri grpc client

* fix

* fix

---------

Co-authored-by: pierre <[email protected]>
  • Loading branch information
octol and doums authored Oct 23, 2024
1 parent 652f975 commit b5e0c7c
Show file tree
Hide file tree
Showing 20 changed files with 525 additions and 297 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build-nym-vpn-core-deb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ jobs:
run: |
cargo install --locked cargo-deb
- name: Install Protoc
uses: arduino/setup-protoc@v3
with:
version: "21.12" # 3.21.12: the version on ubuntu 24.04. Don't change this!
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Download wireguard-go artifacts
uses: actions/download-artifact@v4
with:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/build-nym-vpn-core-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ jobs:
toolchain: stable
components: rustfmt, clippy

- name: Install Protoc
uses: arduino/setup-protoc@v3
with:
version: "21.12" # 3.21.12: the version on ubuntu 24.04. Don't change this!
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Download wireguard-go artifacts
uses: actions/download-artifact@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-nym-vpn-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ jobs:

- name: Install Protoc
uses: arduino/setup-protoc@v3
if: ${{ !contains(matrix.os, 'ubuntu') }}
with:
version: "21.12" # 3.21.12: the version on ubuntu 24.04. Don't change this!
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup MSBuild.exe
Expand Down
6 changes: 3 additions & 3 deletions nym-vpn-app/src-tauri/src/grpc/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use nym_vpn_proto::{
health_check_response::ServingStatus, health_client::HealthClient,
is_account_stored_response::Resp as IsAccountStoredResp, nym_vpnd_client::NymVpndClient,
ConnectRequest, ConnectionStatus, DisconnectRequest, Dns, Empty, EntryNode, ExitNode,
GatewayType, GetAccountSummaryRequest, HealthCheckRequest, InfoRequest, InfoResponse,
FetchRawAccountSummaryRequest, GatewayType, HealthCheckRequest, InfoRequest, InfoResponse,
IsAccountStoredRequest, ListCountriesRequest, Location, SetNetworkRequest, StatusRequest,
StatusResponse, StoreAccountRequest, UserAgent,
};
Expand Down Expand Up @@ -458,9 +458,9 @@ impl GrpcClient {
debug!("get_account_summary");
let mut vpnd = self.vpnd().await?;

let request = Request::new(GetAccountSummaryRequest {});
let request = Request::new(FetchRawAccountSummaryRequest {});
let response = vpnd
.get_account_summary(request)
.fetch_raw_account_summary(request)
.await
.map_err(|e| {
error!("grpc get_account_summary: {}", e);
Expand Down
41 changes: 23 additions & 18 deletions nym-vpn-core/crates/nym-vpn-account-controller/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ use nym_credentials::{
};
use nym_credentials_interface::{RequestInfo, TicketType};
use nym_ecash_time::EcashTime;
use nym_http_api_client::{HttpClientError, UserAgent};
use nym_http_api_client::UserAgent;
use nym_sdk::mixnet::CredentialStorage;
use nym_vpn_api_client::{
response::{NymVpnZkNym, NymVpnZkNymStatus},
response::{NymErrorResponse, NymVpnZkNym, NymVpnZkNymStatus},
types::{Device, VpnApiAccount},
VpnApiClientError,
HttpClientError, VpnApiClientError,
};
use nym_vpn_store::{keys::KeyStore, mnemonic::MnemonicStorage};
use serde::{Deserialize, Serialize};
Expand All @@ -33,7 +33,7 @@ use crate::{
ecash_client::VpnEcashApiClient,
error::Error,
shared_state::{
DeviceState, MnemonicState, ReadyToRegisterDevice, RemoteAccountState, SharedAccountState,
AccountState, DeviceState, MnemonicState, ReadyToRegisterDevice, SharedAccountState,
SubscriptionState,
},
};
Expand Down Expand Up @@ -388,7 +388,7 @@ where
}

async fn update_verification_key(&mut self) -> Result<(), Error> {
tracing::info!("Updating verification key");
tracing::debug!("Updating verification key");

let master_verification_key = self
.vpn_ecash_api_client
Expand Down Expand Up @@ -420,7 +420,7 @@ where
}

async fn update_coin_indices_signatures(&mut self) -> Result<(), Error> {
tracing::info!("Updating coin indices signatures");
tracing::debug!("Updating coin indices signatures");

let aggregated_coin_indices_signatures = self
.vpn_ecash_api_client
Expand All @@ -439,7 +439,7 @@ where
}

async fn update_expiration_date_signatures(&mut self) -> Result<(), Error> {
tracing::info!("Updating expiration date signatures");
tracing::debug!("Updating expiration date signatures");

let aggregated_expiration_data_signatures = self
.vpn_ecash_api_client
Expand Down Expand Up @@ -476,24 +476,27 @@ where

async fn update_account_state(&self, account: &VpnApiAccount) -> Result<(), Error> {
tracing::info!("Updating account state");

let response = self.vpn_api_client.get_account_summary(account).await;

// Check if the response indicates that we are not registered
if let Some(403) = &response.as_ref().err().and_then(extract_status_code) {
tracing::warn!("NymVPN API reports: access denied (403)");
self.account_state
.set_account(RemoteAccountState::NotRegistered)
.set_account(AccountState::NotRegistered)
.await;
}

let account_summary = response.map_err(|source| Error::GetAccountSummary {
base_url: self.vpn_api_client.current_url().clone(),
source: Box::new(source),
let account_summary = response.map_err(|source| {
tracing::warn!("NymVPN API error response: {:?}", source);
Error::GetAccountSummary {
base_url: self.vpn_api_client.current_url().clone(),
source: Box::new(source),
}
})?;
tracing::info!("Account summary: {:#?}", account_summary);

self.account_state
.set_account(RemoteAccountState::from(account_summary.account.status))
.set_account(AccountState::from(account_summary.account.status))
.await;

self.account_state
Expand Down Expand Up @@ -699,19 +702,19 @@ where
self.update_verification_key()
.await
.inspect_err(|err| {
tracing::error!("Failed to update master verification key: {:?}", err)
tracing::debug!("Failed to update master verification key: {:?}", err)
})
.ok();
self.update_coin_indices_signatures()
.await
.inspect_err(|err| {
tracing::error!("Failed to update coin indices signatures: {:?}", err)
tracing::debug!("Failed to update coin indices signatures: {:?}", err)
})
.ok();
self.update_expiration_date_signatures()
.await
.inspect_err(|err| {
tracing::error!("Failed to update expiration date signatures: {:?}", err)
tracing::debug!("Failed to update expiration date signatures: {:?}", err)
})
.ok();

Expand Down Expand Up @@ -812,7 +815,7 @@ where
let mut source = err.source();
while let Some(err) = source {
if let Some(status) = err
.downcast_ref::<HttpClientError>()
.downcast_ref::<HttpClientError<NymErrorResponse>>()
.and_then(extract_status_code_inner)
{
return Some(status);
Expand All @@ -822,7 +825,9 @@ where
None
}

fn extract_status_code_inner(err: &HttpClientError) -> Option<u16> {
fn extract_status_code_inner(
err: &nym_vpn_api_client::HttpClientError<NymErrorResponse>,
) -> Option<u16> {
match err {
HttpClientError::EndpointFailure { status, .. } => Some((*status).into()),
_ => None,
Expand Down
4 changes: 2 additions & 2 deletions nym-vpn-core/crates/nym-vpn-account-controller/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
mod controller;
mod ecash_client;
mod error;
mod shared_state;
pub mod shared_state;

pub use controller::{AccountCommand, AccountController};
pub use shared_state::{AccountState, ReadyToConnect, SharedAccountState};
pub use shared_state::{AccountStateSummary, ReadyToConnect, SharedAccountState};
Loading

0 comments on commit b5e0c7c

Please sign in to comment.