Skip to content

Commit

Permalink
Reorder to match proto
Browse files Browse the repository at this point in the history
  • Loading branch information
octol committed Nov 9, 2024
1 parent fde8297 commit 4ef0004
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,25 @@ impl CommandInterfaceConnectionHandler {
Self { vpn_command_tx }
}

pub(crate) async fn handle_info(&self) -> Result<VpnServiceInfo, VpnCommandSendError> {
self.send_and_wait(VpnServiceCommand::Info, ()).await
}

pub(crate) async fn handle_set_network(
&self,
network: String,
) -> Result<Result<(), SetNetworkError>, VpnCommandSendError> {
self.send_and_wait(VpnServiceCommand::SetNetwork, network)
.await
}

pub(crate) async fn handle_get_system_messages(
&self,
) -> Result<SystemMessages, VpnCommandSendError> {
self.send_and_wait(VpnServiceCommand::GetSystemMessages, ())
.await
}

pub(crate) async fn handle_connect(
&self,
entry: Option<EntryPoint>,
Expand All @@ -74,18 +93,6 @@ impl CommandInterfaceConnectionHandler {
self.send_and_wait(VpnServiceCommand::Disconnect, ()).await
}

pub(crate) async fn handle_info(&self) -> Result<VpnServiceInfo, VpnCommandSendError> {
self.send_and_wait(VpnServiceCommand::Info, ()).await
}

pub(crate) async fn handle_set_network(
&self,
network: String,
) -> Result<Result<(), SetNetworkError>, VpnCommandSendError> {
self.send_and_wait(VpnServiceCommand::SetNetwork, network)
.await
}

pub(crate) async fn handle_status(&self) -> Result<VpnServiceStatus, VpnCommandSendError> {
self.send_and_wait(VpnServiceCommand::Status, ()).await
}
Expand Down Expand Up @@ -118,13 +125,6 @@ impl CommandInterfaceConnectionHandler {
Ok(gateways.into_iter().map(gateway::Country::from).collect())
}

pub(crate) async fn handle_get_system_messages(
&self,
) -> Result<SystemMessages, VpnCommandSendError> {
self.send_and_wait(VpnServiceCommand::GetSystemMessages, ())
.await
}

pub(crate) async fn handle_store_account(
&self,
account: String,
Expand Down
38 changes: 19 additions & 19 deletions nym-vpn-core/crates/nym-vpnd/src/command_interface/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,25 @@ impl NymVpnd for CommandInterface {
Ok(tonic::Response::new(response))
}

async fn get_system_messages(
&self,
_request: tonic::Request<GetSystemMessagesRequest>,
) -> Result<tonic::Response<GetSystemMessagesResponse>, tonic::Status> {
tracing::debug!("Got get system messages request");

let messages = CommandInterfaceConnectionHandler::new(self.vpn_command_tx.clone())
.handle_get_system_messages()
.await?;

let messages = messages
.into_current_messages()
.map(into_proto_system_message)
.collect();
let response = GetSystemMessagesResponse { messages };

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

async fn vpn_connect(
&self,
request: tonic::Request<ConnectRequest>,
Expand Down Expand Up @@ -378,25 +397,6 @@ impl NymVpnd for CommandInterface {
Ok(tonic::Response::new(response))
}

async fn get_system_messages(
&self,
_request: tonic::Request<GetSystemMessagesRequest>,
) -> Result<tonic::Response<GetSystemMessagesResponse>, tonic::Status> {
tracing::debug!("Got get system messages request");

let messages = CommandInterfaceConnectionHandler::new(self.vpn_command_tx.clone())
.handle_get_system_messages()
.await?;

let messages = messages
.into_current_messages()
.map(into_proto_system_message)
.collect();
let response = GetSystemMessagesResponse { messages };

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

async fn store_account(
&self,
request: tonic::Request<StoreAccountRequest>,
Expand Down
36 changes: 18 additions & 18 deletions nym-vpn-core/crates/nym-vpnd/src/service/vpn_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ type Locale = String;

#[allow(clippy::large_enum_variant)]
pub enum VpnServiceCommand {
Info(oneshot::Sender<VpnServiceInfo>, ()),
SetNetwork(oneshot::Sender<Result<(), SetNetworkError>>, String),
GetSystemMessages(oneshot::Sender<SystemMessages>, ()),
Connect(
oneshot::Sender<Result<(), VpnServiceConnectError>>,
(ConnectArgs, nym_vpn_lib::UserAgent),
),
Disconnect(oneshot::Sender<Result<(), VpnServiceDisconnectError>>, ()),
Status(oneshot::Sender<VpnServiceStatus>, ()),
Info(oneshot::Sender<VpnServiceInfo>, ()),
SetNetwork(oneshot::Sender<Result<(), SetNetworkError>>, String),
GetSystemMessages(oneshot::Sender<SystemMessages>, ()),
StoreAccount(oneshot::Sender<Result<(), AccountError>>, String),
IsAccountStored(oneshot::Sender<Result<bool, AccountError>>, ()),
RemoveAccount(oneshot::Sender<Result<(), AccountError>>, ()),
Expand Down Expand Up @@ -135,14 +135,14 @@ pub enum VpnServiceCommand {
impl fmt::Display for VpnServiceCommand {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
VpnServiceCommand::Info(..) => write!(f, "Info"),
VpnServiceCommand::SetNetwork(..) => write!(f, "SetNetwork"),
VpnServiceCommand::GetSystemMessages(..) => write!(f, "GetSystemMessages"),
VpnServiceCommand::Connect(_, (args, user_agent)) => {
write!(f, "Connect {{ {args:?}, {user_agent:?} }}")
}
VpnServiceCommand::Disconnect(..) => write!(f, "Disconnect"),
VpnServiceCommand::Status(..) => write!(f, "Status"),
VpnServiceCommand::Info(..) => write!(f, "Info"),
VpnServiceCommand::SetNetwork(..) => write!(f, "SetNetwork"),
VpnServiceCommand::GetSystemMessages(..) => write!(f, "GetSystemMessages"),
VpnServiceCommand::StoreAccount(..) => write!(f, "StoreAccount"),
VpnServiceCommand::IsAccountStored(..) => write!(f, "IsAccountStored"),
VpnServiceCommand::RemoveAccount(..) => write!(f, "RemoveAccount"),
Expand Down Expand Up @@ -553,18 +553,6 @@ where

async fn handle_service_command(&mut self, command: VpnServiceCommand) {
match command {
VpnServiceCommand::Connect(tx, (connect_args, user_agent)) => {
let result = self.handle_connect(connect_args, user_agent).await;
let _ = tx.send(result);
}
VpnServiceCommand::Disconnect(tx, ()) => {
let result = self.handle_disconnect().await;
let _ = tx.send(result);
}
VpnServiceCommand::Status(tx, ()) => {
let result = self.handle_status().await;
let _ = tx.send(result);
}
VpnServiceCommand::Info(tx, ()) => {
let result = self.handle_info().await;
let _ = tx.send(result);
Expand All @@ -577,6 +565,18 @@ where
let result = self.handle_get_system_messages().await;
let _ = tx.send(result);
}
VpnServiceCommand::Connect(tx, (connect_args, user_agent)) => {
let result = self.handle_connect(connect_args, user_agent).await;
let _ = tx.send(result);
}
VpnServiceCommand::Disconnect(tx, ()) => {
let result = self.handle_disconnect().await;
let _ = tx.send(result);
}
VpnServiceCommand::Status(tx, ()) => {
let result = self.handle_status().await;
let _ = tx.send(result);
}
VpnServiceCommand::StoreAccount(tx, account) => {
let result = self.handle_store_account(account).await;
let _ = tx.send(result);
Expand Down
6 changes: 3 additions & 3 deletions proto/nym/vpn.proto
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,9 @@ service NymVpnd {
// Set the network. This requires a restart to take effect
rpc SetNetwork (SetNetworkRequest) returns (SetNetworkResponse) {}

// List messages fetched from nym-vpn-api
rpc GetSystemMessages (GetSystemMessagesRequest) returns (GetSystemMessagesResponse) {}

// Start the tunnel and connect
rpc VpnConnect (ConnectRequest) returns (ConnectResponse) {}

Expand All @@ -807,9 +810,6 @@ service NymVpnd {
// List the avaiable countries for the selected mode
rpc ListCountries (ListCountriesRequest) returns (ListCountriesResponse) {}

// List messages fetched from nym-vpn-api
rpc GetSystemMessages (GetSystemMessagesRequest) returns (GetSystemMessagesResponse) {}

// -- Unstable --
// These below are considered unstable, in the sense that their definitions
// are still being interated upon and their meaning might change
Expand Down

0 comments on commit 4ef0004

Please sign in to comment.