Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 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
18 changes: 18 additions & 0 deletions nym-vpn-core/crates/nym-vpn-lib-types/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ pub struct VpnServiceConfig {
pub enable_custom_dns: bool,
pub custom_dns: Vec<IpAddr>,
pub network_stats: NetworkStatisticsConfig,
pub poisson_parameter: Option<u32>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking about it, we need another name for that option, looking at it, I have zero clue of what it is

Copy link
Contributor

Choose a reason for hiding this comment

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

We currently have a disable_poisson_rate field in the VpnServiceConfig but it doesn't appear to be used for anything useful.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking about it, this and disable_poisson_rate are redundant!
We could "merge" them and disable_poisson_rate would have the same effect as setting poisson_parameter to 0, i.e. disable the real traffic poisson

pub average_packet_delay: Option<u32>,
pub message_sending_average_delay: Option<u32>,
}

impl fmt::Display for VpnServiceConfig {
Expand Down Expand Up @@ -82,6 +85,18 @@ impl fmt::Display for VpnServiceConfig {
.join(", ")
)?;
writeln!(f, "networks stats config: {}", self.network_stats)?;
writeln!(f, "poisson_parameter: {:?}", self.poisson_parameter)?;
writeln!(
f,
"average_packet_delay: {} ms, message_sending_average_delay: {} ms",
self.average_packet_delay
.map(|v| format!("{v}"))
.unwrap_or_else(|| "<None>".to_string()),
self.message_sending_average_delay
.map(|v| format!("{v}"))
.unwrap_or_else(|| "<None>".to_string())
)?;

Ok(())
}
}
Expand All @@ -105,6 +120,9 @@ impl Default for VpnServiceConfig {
enable_custom_dns: false,
custom_dns: vec![],
network_stats: Default::default(),
poisson_parameter: None,
average_packet_delay: None,
message_sending_average_delay: None,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl Default for TunnelConstants {
}
}

#[derive(Debug, Clone, Eq, PartialEq)]
#[derive(Debug, Clone, PartialEq)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Unnecessary changes in that file, you can revert the whole file

pub struct TunnelSettings {
/// Whether to enable support for IPv6.
pub enable_ipv6: bool,
Expand Down Expand Up @@ -737,7 +737,6 @@ impl TunnelStateMachine {
&mut self.shared_state,
)
.await;

match next_state {
NextTunnelState::NewState((new_state_handler, new_state)) => {
self.current_state_handler = new_state_handler;
Expand Down
37 changes: 36 additions & 1 deletion nym-vpn-core/crates/nym-vpn-proto/proto/nym_vpn_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,26 @@ message Threshold {
uint32 min_performance = 1;
}

message ConnectRequest {
EntryNode entry = 1;
ExitNode exit = 2;
Dns dns = 3;
bool disable_ipv6 = 14;
bool enable_two_hop = 5;
bool enable_bridges = 21;
bool netstack = 13;
bool disable_poisson_rate = 6;
bool disable_background_cover_traffic = 7;
bool enable_credentials_mode = 8;
UserAgent user_agent = 12;
}

message SetPoissonParameterRequest {
uint32 poisson_parameter = 1;
}

message SetPoissonParameterResponse {}

message VpnServiceConfig {
EntryNode entry_point = 1;
ExitNode exit_point = 2;
Expand All @@ -262,6 +282,9 @@ message VpnServiceConfig {
bool enable_custom_dns = 17;
IpAddrList custom_dns = 16;
NetworkStatsConfig network_stats = 18;
optional uint32 poisson_parameter = 24;
optional uint32 average_packet_delay = 22;
optional uint32 message_sending_average_delay = 23;
}

message NetworkStatsConfig {
Expand Down Expand Up @@ -800,6 +823,9 @@ message DeleteLogFileResponse {
bool success = 1;
DeleteLogFileError error = 2;
}
message SetAveragePacketDelayRequest {
uint32 delay_ms = 1;
}

// Enable SOCKS5 proxy request
message EnableSocks5Request {
Expand Down Expand Up @@ -843,10 +869,17 @@ message NetworkStatisticsIdentity {
string id = 2;
}

message SetMessageSendingAverageDelayRequest {
uint32 delay_ms = 1;
}
message SetDisablePoissonRateRequest {
bool disable = 1;
}
service NymVpnService {
// Get info regarding the nym-vpnd in general, like version etc.
rpc Info (google.protobuf.Empty) returns (InfoResponse) {}

rpc SetPoissonParameter (SetPoissonParameterRequest) returns (google.protobuf.Empty);
rpc SetDisablePoissonRate (SetDisablePoissonRateRequest) returns (google.protobuf.Empty);
// Get the VPN service configuration
rpc GetConfig (google.protobuf.Empty) returns (GetConfigResponse) {}

Expand Down Expand Up @@ -983,4 +1016,6 @@ service NymVpnService {

// Get socks5 proxy status
rpc GetSocks5Status (google.protobuf.Empty) returns (Socks5Status) {}
rpc SetAveragePacketDelay(SetAveragePacketDelayRequest) returns (google.protobuf.Empty);
rpc SetMessageSendingAverageDelay(SetMessageSendingAverageDelayRequest) returns (google.protobuf.Empty);
}
6 changes: 6 additions & 0 deletions nym-vpn-core/crates/nym-vpn-proto/src/conversions/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ impl TryFrom<proto::VpnServiceConfig> for nym_vpn_lib_types::VpnServiceConfig {
enable_custom_dns: value.enable_custom_dns,
custom_dns,
network_stats,
poisson_parameter: value.poisson_parameter,
average_packet_delay: value.average_packet_delay,
message_sending_average_delay: value.message_sending_average_delay,
};
Ok(config)
}
Expand Down Expand Up @@ -77,6 +80,9 @@ impl From<nym_vpn_lib_types::VpnServiceConfig> for proto::VpnServiceConfig {
enable_custom_dns: value.enable_custom_dns,
custom_dns,
network_stats: Some(proto::NetworkStatsConfig::from(value.network_stats)),
poisson_parameter: value.poisson_parameter,
average_packet_delay: value.average_packet_delay,
message_sending_average_delay: value.message_sending_average_delay,
}
}
}
44 changes: 44 additions & 0 deletions nym-vpn-core/crates/nym-vpn-proto/src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,51 @@ impl RpcClient {

Ok(())
}
pub async fn set_poisson_parameter(&mut self, value: u32) -> Result<()> {
let request = proto::SetPoissonParameterRequest {
poisson_parameter: value,
};

self.0
.set_poisson_parameter(request)
.await
.map_err(Error::Rpc)?;
Ok(())
}
/// Sets the average per-mixnode packet delay (in milliseconds)
pub async fn set_average_packet_delay(&mut self, delay_ms: u32) -> Result<()> {
let request = proto::SetAveragePacketDelayRequest { delay_ms };

self.0
.set_average_packet_delay(request)
.await
.map_err(Error::Rpc)?
.into_inner();

Ok(())
}

/// Sets the average real traffic message-sending delay (in milliseconds)
pub async fn set_message_sending_average_delay(&mut self, delay_ms: u32) -> Result<()> {
let request = proto::SetMessageSendingAverageDelayRequest { delay_ms };

self.0
.set_message_sending_average_delay(request)
.await
.map_err(Error::Rpc)?
.into_inner();

Ok(())
}
pub async fn set_disable_poisson_rate(&mut self, disable: bool) -> Result<()> {
let request = proto::SetDisablePoissonRateRequest { disable };
self.0
.set_disable_poisson_rate(request)
.await
.map_err(Error::Rpc)?
.into_inner();
Ok(())
}
pub async fn set_disable_ipv6(&mut self, disable_ipv6: bool) -> Result<()> {
self.0
.set_disable_ipv6(disable_ipv6)
Expand Down
69 changes: 69 additions & 0 deletions nym-vpn-core/crates/nym-vpnc/src/commands/tunnel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use anyhow::Result;
use nym_vpn_proto::rpc_client::RpcClient;

use crate::{boolean_option::BooleanOption, display_helpers::display_on_off};
use clap::builder::ValueParser;

#[derive(Debug, Clone, clap::Subcommand)]
pub enum Command {
Expand Down Expand Up @@ -35,6 +36,56 @@ pub struct SetParams {
/// Enable Circumvention Transport (CT) wrapping for the connection to the entry gateway in two hop wireguard mode.
#[arg(long, alias = "ct", value_parser = clap::value_parser!(BooleanOption))]
circumvention_transports: Option<BooleanOption>,
/// Set the average delay for a loop cover packet (milliseconds)
#[arg(
long,
value_name = "MILLISECONDS",
value_parser = ValueParser::from(|s: &str| -> Result<u32, String> {
Copy link
Contributor

Choose a reason for hiding this comment

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

@pronebird @trojanfoe How do feel about the parameters validation on that layer?
I reckon it should happen in the daemon and not here

Copy link
Contributor

Choose a reason for hiding this comment

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

The type should be u32. Is there a reason why it isn't?

let val: u32 = s.parse().map_err(|_| format!("Invalid integer: {}", s))?;
if !(0..=200).contains(&val) {
return Err(format!("Value must be between 0 and 200 (got {val})"));
}
Ok(val)
})
)]
pub loop_cover_stream_average_delay: Option<u32>,

/// Set average packet delay at each mixnode (milliseconds)
#[arg(
long,
value_name = "MILLISECONDS",
value_parser = ValueParser::from(|s: &str| -> Result<u32, String> {
let val: u32 = s.parse().map_err(|_| format!("Invalid integer: {}", s))?;
if !(0..=200).contains(&val) {
return Err(format!("Packet delay must be between 0 and 200 (got {val})"));
}
Ok(val)
})
)]
pub average_packet_delay: Option<u32>,

/// Set average real message sending delay (milliseconds)
#[arg(
long,
value_name = "MILLISECONDS",
value_parser = ValueParser::from(|s: &str| -> Result<u32, String> {
let val: u32 = s.parse().map_err(|_| format!("Invalid integer: {}", s))?;
if !(5..=50).contains(&val) {
return Err(format!(
"Message sending delay must be between 5 and 50 (got {val})"
));
}
Ok(val)
})
)]
pub message_sending_delay: Option<u32>,

#[arg(
long,
help = "Disable Poisson process rate limiting for real traffic",
value_parser = BooleanOption::custom_parser("on","off")
)]
pub disable_real_traffic_poisson_rate: Option<BooleanOption>,
}

impl Command {
Expand All @@ -57,6 +108,10 @@ impl Command {
netstack,
ipv6,
circumvention_transports,
loop_cover_stream_average_delay,
average_packet_delay,
message_sending_delay,
disable_real_traffic_poisson_rate,
}) => {
if let Some(two_hop) = two_hop {
rpc_client.set_enable_two_hop(*two_hop).await?;
Expand All @@ -73,7 +128,21 @@ impl Command {
if let Some(enable_ct) = circumvention_transports {
rpc_client.set_enable_bridges(*enable_ct).await?;
}
if let Some(poisson) = loop_cover_stream_average_delay {
rpc_client.set_poisson_parameter(poisson).await?;
}
if let Some(delay_ms) = average_packet_delay {
rpc_client.set_average_packet_delay(delay_ms).await?;
}

if let Some(delay_ms) = message_sending_delay {
rpc_client
.set_message_sending_average_delay(delay_ms)
.await?;
}
if let Some(disable) = disable_real_traffic_poisson_rate {
rpc_client.set_disable_poisson_rate(*disable).await?;
}
Ok(())
}
}
Expand Down
62 changes: 62 additions & 0 deletions nym-vpn-core/crates/nym-vpnd/src/command_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,69 @@ impl NymVpnService for CommandInterface {

Ok(tonic::Response::new(()))
}
async fn set_poisson_parameter(
&self,
request: tonic::Request<proto::SetPoissonParameterRequest>,
) -> Result<tonic::Response<()>> {
let value = request.into_inner().poisson_parameter;
tracing::debug!("Received set_poisson_parameter RPC with value: {}", value);

let _ = self
.send_and_wait(VpnServiceCommand::SetPoissonParameter, value)
.await
.map_err(|e| {
tonic::Status::internal(format!("Failed to set Poisson parameter: {e}"))
})?;

Ok(tonic::Response::new(()))
}
async fn set_average_packet_delay(
&self,
request: tonic::Request<proto::SetAveragePacketDelayRequest>,
) -> Result<tonic::Response<()>> {
let delay_ms = request.into_inner().delay_ms;
tracing::debug!("Received SetAveragePacketDelay: {} ms", delay_ms);

let _ = self
.send_and_wait(VpnServiceCommand::SetAveragePacketDelay, delay_ms)
.await
.map_err(|e| {
tonic::Status::internal(format!("Failed to set average packet delay: {e}"))
})?;

Ok(tonic::Response::new(()))
}
async fn set_disable_poisson_rate(
&self,
request: tonic::Request<proto::SetDisablePoissonRateRequest>,
) -> Result<tonic::Response<()>> {
let disable_poisson_rate = request.into_inner().disable;

self.send_and_wait(
VpnServiceCommand::SetDisablePoissonRate,
disable_poisson_rate,
)
.await
.map_err(|e| tonic::Status::internal(format!("Failed to set disable Poisson rate: {e}")))?;

Ok(tonic::Response::new(()))
}
async fn set_message_sending_average_delay(
&self,
request: tonic::Request<proto::SetMessageSendingAverageDelayRequest>,
) -> Result<tonic::Response<()>> {
let delay_ms = request.into_inner().delay_ms;
tracing::debug!("Received SetMessageSendingAverageDelay: {} ms", delay_ms);

let _ = self
.send_and_wait(VpnServiceCommand::SetMessageSendingAverageDelay, delay_ms)
.await
.map_err(|e| {
tonic::Status::internal(format!("Failed to set message sending average delay: {e}"))
})?;

Ok(tonic::Response::new(()))
}
async fn set_enable_two_hop(
&self,
request: tonic::Request<bool>,
Expand Down
2 changes: 0 additions & 2 deletions nym-vpn-core/crates/nym-vpnd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ async fn run_vpn_service(args: CliArgs) -> anyhow::Result<()> {

#[cfg(not(windows))]
run_standalone(run_parameters, remove_log_file_signal, shutdown_token).await?;

let _worker_guard = if let Some(setup) = logging_setup {
Copy link
Contributor

Choose a reason for hiding this comment

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

Unnecessary changes here, you can revert the whole file

if setup.log_file_remover_join_handle.await.is_err() {
tracing::error!("Failed to join on file logging handle");
Expand Down Expand Up @@ -204,7 +203,6 @@ impl VpnServiceHandle {
if let Err(e) = self.vpn_service_handle.await {
tracing::error!("Failed to join on vpn service: {}", e);
}

self.command_shutdown_token.cancel();

if let Err(e) = self.command_handle.await {
Expand Down
Loading
Loading