Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions nym-vpn-app/src-tauri/src/commands/socks5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub async fn enable_socks5(
http_rpc_settings: HttpRpcSettings,
exit: Node,
) -> Result<(), BackendError> {
info!("enabling SOCKS5 proxy with exit_node: {}", exit);
info!("Enabling SOCKS5 proxy with exit_node: {exit}");
vpnd.enable_socks5(socks5_settings, http_rpc_settings, exit)
.await?;
Ok(())
Expand All @@ -23,7 +23,7 @@ pub async fn enable_socks5(
#[instrument(skip_all)]
#[tauri::command]
pub async fn disable_socks5(vpnd: State<'_, VpndClient>) -> Result<(), BackendError> {
info!("disabling SOCKS5 proxy");
info!("Disabling SOCKS5 proxy");
vpnd.disable_socks5().await?;
Ok(())
}
Expand Down
5 changes: 3 additions & 2 deletions nym-vpn-app/src-tauri/src/vpnd/socks5.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
use nym_vpn_lib_types as lib;
use serde::{Deserialize, Serialize};
use std::net::SocketAddr;
use ts_rs::TS;

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, TS)]
#[ts(export, export_to = "tauri.ts")]
#[serde(rename_all = "camelCase")]
pub struct Socks5Settings {
pub listen_address: String,
pub listen_address: Option<SocketAddr>,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, TS)]
#[ts(export, export_to = "tauri.ts")]
#[serde(rename_all = "camelCase")]
pub struct HttpRpcSettings {
pub listen_address: String,
pub listen_address: Option<SocketAddr>,
}

#[derive(Serialize, Clone, Debug, PartialEq, TS)]
Expand Down
1 change: 1 addition & 0 deletions nym-vpn-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Add custom DNS setting for mobile platforms (https://github.com/nymtech/nym-vpn-client/pull/4106)
- Login with signature string in addition to mnemonic (https://github.com/nymtech/nym-vpn-client/pull/4117)
- SOCKS5 proxy can now be controlled via `nym-vpnc` (https://github.com/nymtech/nym-vpn-client/pull/4148)

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion nym-vpn-core/crates/nym-vpn-lib-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub use rpc_requests::{
ListGatewaysOptions, StoreAccountRequest,
};
pub use service::{TargetState, VpnServiceConfig, VpnServiceInfo};
pub use socks5::{HttpRpcSettings, Socks5Settings, Socks5State, Socks5Status};
pub use socks5::{EnableSocks5Request, HttpRpcSettings, Socks5Settings, Socks5State, Socks5Status};
pub use tunnel_event::{
BandwidthEvent, ConnectionEvent, ConnectionStatisticsEvent, MixnetEvent, SphinxPacketRates,
TunnelEvent,
Expand Down
26 changes: 23 additions & 3 deletions nym-vpn-core/crates/nym-vpn-lib-types/src/socks5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,29 @@

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use std::net::SocketAddr;
#[cfg(feature = "typescript-bindings")]
use ts_rs::TS;

use crate::ExitPoint;

/// SOCKS5 enable request
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "uniffi-bindings", derive(uniffi::Record))]
#[cfg_attr(
feature = "typescript-bindings",
derive(TS),
ts(export),
ts(export_to = "bindings.ts")
)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "typescript-bindings", serde(rename_all = "camelCase"))]
pub struct EnableSocks5Request {
pub socks5_settings: Socks5Settings,
pub http_rpc_settings: HttpRpcSettings,
pub exit_point: ExitPoint,
}

/// SOCKS5 proxy settings
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "uniffi-bindings", derive(uniffi::Record))]
Expand All @@ -18,8 +38,8 @@ use ts_rs::TS;
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "typescript-bindings", serde(rename_all = "camelCase"))]
pub struct Socks5Settings {
/// SOCKS5 listen address, e.g., "127.0.0.1:1080"
pub listen_address: String,
/// SOCKS5 listen address, e.g., 127.0.0.1:1080
pub listen_address: Option<SocketAddr>,
}

/// HTTP RPC proxy settings
Expand All @@ -35,7 +55,7 @@ pub struct Socks5Settings {
#[cfg_attr(feature = "typescript-bindings", serde(rename_all = "camelCase"))]
pub struct HttpRpcSettings {
/// HTTP RPC listen address, e.g., 127.0.0.1:8545
pub listen_address: String,
pub listen_address: Option<SocketAddr>,
}

/// SOCKS5 service state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@ message DeleteLogFileResponse {
}

// Enable SOCKS5 proxy request
// TODO: Change arguments to EnableSocks5Request (at the time of writing I didn't want to disturb the client code)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What needs to be changed?

message EnableSocks5Request {
Socks5Settings socks5_settings = 1;
HttpRpcSettings http_rpc_settings = 2;
Expand Down
117 changes: 90 additions & 27 deletions nym-vpn-core/crates/nym-vpn-proto/src/conversions/socks5.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Copyright 2025 - Nym Technologies SA <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only

use nym_vpn_lib_types::{HttpRpcSettings, Socks5Settings, Socks5State, Socks5Status};
use nym_vpn_lib_types::{
EnableSocks5Request, ExitPoint, HttpRpcSettings, Socks5Settings, Socks5State, Socks5Status,
};
use std::net::SocketAddr;

use crate::{conversions::ConversionError, proto};

Expand All @@ -13,19 +16,19 @@ impl TryFrom<proto::Socks5Status> for Socks5Status {
.map_err(|e| ConversionError::Decode("Socks5Status.state", e))
.map(Socks5State::from)?;

let socks5_settings = value
let socks5_settings: Socks5Settings = value
.socks5_settings
.map(Socks5Settings::from)
.unwrap_or_else(|| Socks5Settings {
listen_address: String::new(),
});
.ok_or(ConversionError::NoValueSet(
"EnableSocks5Request.socks5_settings",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, good spot

))?
.try_into()?;

let http_rpc_settings = value
let http_rpc_settings: HttpRpcSettings = value
.http_rpc_settings
.map(HttpRpcSettings::from)
.unwrap_or_else(|| HttpRpcSettings {
listen_address: String::new(),
});
.ok_or(ConversionError::NoValueSet(
"EnableSocks5Request.http_rpc_settings",
))?
.try_into()?;

Ok(Self {
state,
Expand All @@ -48,19 +51,73 @@ impl From<proto::socks5_status::State> for Socks5State {
}
}

impl From<proto::Socks5Settings> for Socks5Settings {
fn from(value: proto::Socks5Settings) -> Self {
Self {
listen_address: value.listen_address,
}
impl TryFrom<proto::EnableSocks5Request> for EnableSocks5Request {
type Error = ConversionError;

fn try_from(value: proto::EnableSocks5Request) -> Result<Self, Self::Error> {
let socks5_settings: Socks5Settings = value
.socks5_settings
.ok_or(ConversionError::NoValueSet(
"EnableSocks5Request.socks5_settings",
))?
.try_into()?;

let http_rpc_settings: HttpRpcSettings = value
.http_rpc_settings
.ok_or(ConversionError::NoValueSet(
"EnableSocks5Request.http_rpc_settings",
))?
.try_into()?;

let exit_point = value
.exit
.map(ExitPoint::try_from)
.transpose()?
.ok_or(ConversionError::NoValueSet("VpnServiceConfig.exit_point"))?;

Ok(Self {
socks5_settings,
http_rpc_settings,
exit_point,
})
}
}

impl From<proto::HttpRpcSettings> for HttpRpcSettings {
fn from(value: proto::HttpRpcSettings) -> Self {
Self {
listen_address: value.listen_address,
}
impl TryFrom<proto::Socks5Settings> for Socks5Settings {
type Error = ConversionError;

fn try_from(value: proto::Socks5Settings) -> Result<Self, Self::Error> {
let listen_address: Option<SocketAddr> = if !value.listen_address.is_empty() {
Some(
value
.listen_address
.parse::<SocketAddr>()
.map_err(|e| ConversionError::ParseAddr("Socks5Settings.listen_address", e))?,
)
} else {
None
};

Ok(Self { listen_address })
}
}

impl TryFrom<proto::HttpRpcSettings> for HttpRpcSettings {
type Error = ConversionError;

fn try_from(value: proto::HttpRpcSettings) -> Result<Self, Self::Error> {
let listen_address: Option<SocketAddr> = if !value.listen_address.is_empty() {
Some(
value
.listen_address
.parse::<SocketAddr>()
.map_err(|e| ConversionError::ParseAddr("HttpRpcSettings.listen_address", e))?,
)
} else {
None
};

Ok(Self { listen_address })
}
}

Expand All @@ -79,17 +136,23 @@ impl From<Socks5State> for proto::socks5_status::State {

impl From<Socks5Settings> for proto::Socks5Settings {
fn from(value: Socks5Settings) -> Self {
Self {
listen_address: value.listen_address,
}
let listen_address = match value.listen_address {
Some(addr) => addr.to_string(),
None => String::new(),
};

Self { listen_address }
}
}

impl From<HttpRpcSettings> for proto::HttpRpcSettings {
fn from(value: HttpRpcSettings) -> Self {
Self {
listen_address: value.listen_address,
}
let listen_address = match value.listen_address {
Some(addr) => addr.to_string(),
None => String::new(),
};

Self { listen_address }
}
}

Expand Down
10 changes: 8 additions & 2 deletions nym-vpn-core/crates/nym-vpn-proto/src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,10 +573,16 @@ impl RpcClient {
) -> Result<()> {
let request = proto::EnableSocks5Request {
socks5_settings: Some(proto::Socks5Settings {
listen_address: socks5_settings.listen_address,
listen_address: match socks5_settings.listen_address {
Some(addr) => addr.to_string(),
None => String::new(),
},
}),
http_rpc_settings: Some(proto::HttpRpcSettings {
listen_address: http_rpc_settings.listen_address,
listen_address: match http_rpc_settings.listen_address {
Some(addr) => addr.to_string(),
None => String::new(),
},
}),
exit: Some(proto::ExitNode::from(exit_point)),
};
Expand Down
1 change: 1 addition & 0 deletions nym-vpn-core/crates/nym-vpnc/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ pub mod lan;
pub mod network;
pub mod network_stats;
pub mod sentry;
pub mod socks5;
pub mod tunnel;
Loading
Loading