Skip to content

Commit

Permalink
wip: parse
Browse files Browse the repository at this point in the history
  • Loading branch information
octol committed Nov 9, 2024
1 parent fde540a commit 81b7507
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 7 deletions.
2 changes: 1 addition & 1 deletion nym-vpn-core/crates/nym-vpn-network-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// SPDX-License-Identifier: GPL-3.0-only

pub mod system_messages;
pub mod feature_flags;

pub(crate) mod response;

mod account_management;
mod discovery;
mod envs;
mod feature_flags;
mod nym_network;
mod nym_vpn_network;
mod refresh;
Expand Down
1 change: 1 addition & 0 deletions nym-vpn-core/crates/nym-vpnc/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub(crate) enum Command {
Info,
SetNetwork(SetNetworkArgs),
GetSystemMessages,
GetFeatureFlags,
StoreAccount(StoreAccountArgs),
IsAccountStored,
RemoveAccount,
Expand Down
17 changes: 13 additions & 4 deletions nym-vpn-core/crates/nym-vpnc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use nym_vpn_proto::{
ConnectRequest, DisconnectRequest, Empty, FetchRawAccountSummaryRequest,
FetchRawDevicesRequest, GetAccountIdentityRequest, GetAccountLinksRequest,
GetAccountStateRequest, GetDeviceIdentityRequest, GetDeviceZkNymsRequest,
GetSystemMessagesRequest, InfoRequest, InfoResponse, IsAccountStoredRequest,
IsReadyToConnectRequest, ListCountriesRequest, ListGatewaysRequest, RefreshAccountStateRequest,
RegisterDeviceRequest, RemoveAccountRequest, RequestZkNymRequest, ResetDeviceIdentityRequest,
SetNetworkRequest, StatusRequest, StoreAccountRequest, UserAgent,
GetFeatureFlagsRequest, GetSystemMessagesRequest, InfoRequest, InfoResponse,
IsAccountStoredRequest, IsReadyToConnectRequest, ListCountriesRequest, ListGatewaysRequest,
RefreshAccountStateRequest, RegisterDeviceRequest, RemoveAccountRequest, RequestZkNymRequest,
ResetDeviceIdentityRequest, SetNetworkRequest, StatusRequest, StoreAccountRequest, UserAgent,
};
use protobuf_conversion::{into_gateway_type, into_threshold};
use sysinfo::System;
Expand Down Expand Up @@ -44,6 +44,7 @@ async fn main() -> Result<()> {
Command::Info => info(client_type).await?,
Command::SetNetwork(ref args) => set_network(client_type, args).await?,
Command::GetSystemMessages => get_system_messages(client_type).await?,
Command::GetFeatureFlags => get_feature_flags(client_type).await?,
Command::StoreAccount(ref store_args) => store_account(client_type, store_args).await?,
Command::RefreshAccountState => refresh_account_state(client_type).await?,
Command::IsAccountStored => is_account_stored(client_type).await?,
Expand Down Expand Up @@ -193,6 +194,14 @@ async fn get_system_messages(client_type: ClientType) -> Result<()> {
Ok(())
}

async fn get_feature_flags(client_type: ClientType) -> Result<()> {
let mut client = vpnd_client::get_client(client_type).await?;
let request = tonic::Request::new(GetFeatureFlagsRequest {});
let response = client.get_feature_flags(request).await?.into_inner();
println!("{:#?}", response);
Ok(())
}

async fn store_account(client_type: ClientType, store_args: &cli::StoreAccountArgs) -> Result<()> {
let mut client = vpnd_client::get_client(client_type).await?;
let request = tonic::Request::new(StoreAccountRequest {
Expand Down
42 changes: 40 additions & 2 deletions nym-vpn-core/crates/nym-vpnd/src/command_interface/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ use std::{
};

use futures::{stream::BoxStream, StreamExt};
use nym_vpn_network_config::feature_flags::Flags;
use tokio::sync::{broadcast, mpsc::UnboundedSender};

use nym_vpn_api_client::types::GatewayMinPerformance;
use nym_vpn_lib::tunnel_state_machine::MixnetEvent;
use nym_vpn_proto::{
nym_vpnd_server::NymVpnd, AccountError, ConnectRequest, ConnectResponse, ConnectionStateChange,
ConnectionStatusUpdate, DisconnectRequest, DisconnectResponse, Empty,
ConnectionStatusUpdate, DisconnectRequest, DisconnectResponse, Empty, FeatureFlagGroup,
FetchRawAccountSummaryRequest, FetchRawAccountSummaryResponse, FetchRawDevicesRequest,
FetchRawDevicesResponse, GetAccountIdentityRequest, GetAccountIdentityResponse,
GetAccountLinksRequest, GetAccountLinksResponse, GetAccountStateRequest,
Expand Down Expand Up @@ -180,7 +181,44 @@ impl NymVpnd for CommandInterface {
.await?
.ok_or(tonic::Status::not_found("Feature flags not found"))?;

todo!();
let mut response = GetFeatureFlagsResponse {
flags: Default::default(),
groups: Default::default(),
};

match result.flags {
Flags::String(s) => {
// top-level
panic!();
}
Flags::Map(m) => {
for (k, v) in m {
match v {
Flags::String(s) => {
response.flags.insert(k, s);
}
Flags::Map(m) => {
let mut group = FeatureFlagGroup {
map: Default::default(),
};
for (k, v) in m {
match v {
Flags::String(s) => {
group.map.insert(k, s);
}
Flags::Map(_) => {
panic!();
}
}
}
response.groups.insert(k, group);
}
}
}
}
};

Ok(tonic::Response::new(response))
}

async fn vpn_connect(
Expand Down

0 comments on commit 81b7507

Please sign in to comment.