Support nym node first
This commit is contained in:
@@ -89,7 +89,6 @@ pub struct GatewayNodeDetailsResponse {
|
||||
|
||||
pub network_requester: Option<GatewayNetworkRequesterDetails>,
|
||||
pub ip_packet_router: Option<GatewayIpPacketRouterDetails>,
|
||||
pub wireguard: Option<GatewayWireguardDetails>,
|
||||
}
|
||||
|
||||
impl fmt::Display for GatewayNodeDetailsResponse {
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
use std::{
|
||||
io,
|
||||
net::{IpAddr, Ipv4Addr, SocketAddr},
|
||||
path::Path,
|
||||
};
|
||||
|
||||
use nym_network_defaults::WG_PORT;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Deserialize, PartialEq, Serialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Wireguard {
|
||||
/// Specifies whether the wireguard service is enabled on this node.
|
||||
pub enabled: bool,
|
||||
|
||||
/// Socket address this node will use for binding its wireguard interface.
|
||||
/// default: `0.0.0.0:51822`
|
||||
pub bind_address: SocketAddr,
|
||||
|
||||
/// Port announced to external clients wishing to connect to the wireguard interface.
|
||||
/// Useful in the instances where the node is behind a proxy.
|
||||
pub announced_port: u16,
|
||||
|
||||
/// The prefix denoting the maximum number of the clients that can be connected via Wireguard.
|
||||
/// The maximum value for IPv4 is 32 and for IPv6 is 128
|
||||
pub private_network_prefix: u8,
|
||||
}
|
||||
|
||||
impl Default for Wireguard {
|
||||
fn default() -> Self {
|
||||
Wireguard {
|
||||
enabled: false,
|
||||
bind_address: SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), WG_PORT),
|
||||
announced_port: WG_PORT,
|
||||
private_network_prefix: 16,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Wireguard {
|
||||
pub fn read_from_toml_file<P: AsRef<Path>>(path: P) -> io::Result<Self> {
|
||||
nym_config::read_config_from_toml_file(path)
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
pub mod config;
|
||||
pub mod error;
|
||||
pub mod public_key;
|
||||
pub mod registration;
|
||||
|
||||
@@ -101,10 +101,6 @@ impl OverrideConfig {
|
||||
config = config.with_default_ip_packet_router_config_path();
|
||||
}
|
||||
|
||||
if config.wireguard.enabled && config.storage_paths.wireguard_config.is_none() {
|
||||
config = config.with_default_wireguard_config_path();
|
||||
}
|
||||
|
||||
Ok(config)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ use nym_config::{
|
||||
DEFAULT_CONFIG_DIR, DEFAULT_CONFIG_FILENAME, DEFAULT_DATA_DIR, NYM_DIR,
|
||||
};
|
||||
use nym_network_defaults::{mainnet, DEFAULT_NYM_NODE_HTTP_PORT};
|
||||
use nym_wireguard_types::config::Wireguard;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::io;
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||
@@ -94,9 +93,6 @@ pub struct Config {
|
||||
#[serde(default)]
|
||||
pub ip_packet_router: IpPacketRouter,
|
||||
|
||||
#[serde(default)]
|
||||
pub wireguard: Wireguard,
|
||||
|
||||
#[serde(default)]
|
||||
pub logging: LoggingSettings,
|
||||
|
||||
@@ -122,7 +118,6 @@ impl Config {
|
||||
},
|
||||
http: Default::default(),
|
||||
gateway: default_gateway,
|
||||
wireguard: Default::default(),
|
||||
storage_paths: GatewayPaths::new_default(id.as_ref()),
|
||||
network_requester: Default::default(),
|
||||
ip_packet_router: Default::default(),
|
||||
@@ -136,7 +131,6 @@ impl Config {
|
||||
host: impl Into<Host>,
|
||||
http: impl Into<Http>,
|
||||
gateway: impl Into<Gateway>,
|
||||
wireguard: impl Into<Wireguard>,
|
||||
storage_paths: impl Into<GatewayPaths>,
|
||||
network_requester: impl Into<NetworkRequester>,
|
||||
ip_packet_router: impl Into<IpPacketRouter>,
|
||||
@@ -148,7 +142,6 @@ impl Config {
|
||||
host: host.into(),
|
||||
http: http.into(),
|
||||
gateway: gateway.into(),
|
||||
wireguard: wireguard.into(),
|
||||
storage_paths: storage_paths.into(),
|
||||
network_requester: network_requester.into(),
|
||||
ip_packet_router: ip_packet_router.into(),
|
||||
@@ -228,11 +221,6 @@ impl Config {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_enabled_wireguard(mut self, enabled_wireguard: bool) -> Self {
|
||||
self.wireguard.enabled = enabled_wireguard;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_default_wireguard_config_path(mut self) -> Self {
|
||||
self.storage_paths = self
|
||||
.storage_paths
|
||||
@@ -275,8 +263,6 @@ impl Config {
|
||||
|
||||
let http_port = self.http.bind_address.port();
|
||||
self.http.bind_address = SocketAddr::new(listening_address, http_port);
|
||||
let wg_port = self.wireguard.bind_address.port();
|
||||
self.wireguard.bind_address = SocketAddr::new(listening_address, wg_port);
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ use std::time::Duration;
|
||||
use url::Url;
|
||||
|
||||
use super::persistence::paths::KeysPaths;
|
||||
use super::{Config, Debug, Gateway, Host, Http, IpPacketRouter, NetworkRequester, Wireguard};
|
||||
use super::{Config, Debug, Gateway, Host, Http, IpPacketRouter, NetworkRequester};
|
||||
|
||||
const DEFAULT_GATEWAYS_DIR: &str = "gateways";
|
||||
|
||||
@@ -128,12 +128,6 @@ impl From<ConfigV1_1_36> for Config {
|
||||
nyxd_urls: value.gateway.nyxd_urls,
|
||||
cosmos_mnemonic: value.gateway.cosmos_mnemonic,
|
||||
},
|
||||
wireguard: Wireguard {
|
||||
enabled: value.wireguard.enabled,
|
||||
bind_address: value.wireguard.bind_address,
|
||||
announced_port: value.wireguard.announced_port,
|
||||
private_network_prefix: value.wireguard.private_network_prefix,
|
||||
},
|
||||
storage_paths: GatewayPaths {
|
||||
keys: KeysPaths {
|
||||
private_identity_key_file: value.storage_paths.keys.private_identity_key_file,
|
||||
|
||||
+1
-15
@@ -1,9 +1,9 @@
|
||||
// Copyright 2024 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use crate::config::Config;
|
||||
use crate::node::helpers::load_keypair;
|
||||
use crate::GatewayError;
|
||||
use crate::{config::Config, node::helpers::load_wireguard_config};
|
||||
use nym_config::OptionalSet;
|
||||
use nym_crypto::asymmetric::{encryption, identity};
|
||||
use nym_pemstore::traits::PemStorableKey;
|
||||
@@ -11,7 +11,6 @@ use nym_pemstore::KeyPairPath;
|
||||
use nym_sphinx::addressing::clients::Recipient;
|
||||
use nym_types::gateway::{
|
||||
GatewayIpPacketRouterDetails, GatewayNetworkRequesterDetails, GatewayNodeDetailsResponse,
|
||||
GatewayWireguardDetails,
|
||||
};
|
||||
use std::path::Path;
|
||||
|
||||
@@ -193,18 +192,6 @@ pub async fn node_details(config: &Config) -> Result<GatewayNodeDetailsResponse,
|
||||
None
|
||||
};
|
||||
|
||||
let wireguard = if let Some(nr_cfg_path) = &config.storage_paths.wireguard_config {
|
||||
let cfg = load_wireguard_config(&config.gateway.id, nr_cfg_path).await?;
|
||||
|
||||
Some(GatewayWireguardDetails {
|
||||
enabled: cfg.enabled,
|
||||
announced_port: cfg.announced_port,
|
||||
private_network_prefix: cfg.private_network_prefix,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Ok(GatewayNodeDetailsResponse {
|
||||
identity_key: gateway_identity_public_key.to_base58_string(),
|
||||
sphinx_key: gateway_sphinx_public_key.to_base58_string(),
|
||||
@@ -215,6 +202,5 @@ pub async fn node_details(config: &Config) -> Result<GatewayNodeDetailsResponse,
|
||||
data_store: display_path(&config.storage_paths.clients_storage),
|
||||
network_requester,
|
||||
ip_packet_router,
|
||||
wireguard,
|
||||
})
|
||||
}
|
||||
|
||||
+2
-28
@@ -4,7 +4,6 @@
|
||||
use crate::config::Config;
|
||||
use crate::error::GatewayError;
|
||||
use crate::helpers::load_public_key;
|
||||
use ipnetwork::IpNetwork;
|
||||
use log::{debug, error, warn};
|
||||
use nym_bin_common::bin_info_owned;
|
||||
use nym_crypto::asymmetric::{encryption, identity};
|
||||
@@ -12,30 +11,19 @@ use nym_network_requester::RequestFilter;
|
||||
use nym_node_http_api::api::api_requests;
|
||||
use nym_node_http_api::api::api_requests::v1::network_requester::exit_policy::models::UsedExitPolicy;
|
||||
use nym_node_http_api::api::api_requests::SignedHostInformation;
|
||||
use nym_node_http_api::router::WireguardAppState;
|
||||
use nym_node_http_api::NymNodeHttpError;
|
||||
use nym_sphinx::addressing::clients::Recipient;
|
||||
use nym_task::TaskClient;
|
||||
use nym_wireguard_types::registration::GatewayClientRegistry;
|
||||
use std::net::{IpAddr, Ipv4Addr};
|
||||
use std::sync::Arc;
|
||||
|
||||
fn load_gateway_details(
|
||||
config: &Config,
|
||||
) -> Result<api_requests::v1::gateway::models::Gateway, GatewayError> {
|
||||
let wireguard = if config.wireguard.enabled {
|
||||
Some(api_requests::v1::gateway::models::Wireguard {
|
||||
port: config.wireguard.announced_port,
|
||||
public_key: "placeholder key value".to_string(),
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Ok(api_requests::v1::gateway::models::Gateway {
|
||||
enforces_zk_nyms: config.gateway.only_coconut_credentials,
|
||||
client_interfaces: api_requests::v1::gateway::models::ClientInterfaces {
|
||||
wireguard,
|
||||
wireguard: None,
|
||||
mixnet_websockets: Some(api_requests::v1::gateway::models::WebSockets {
|
||||
ws_port: config.gateway.clients_port,
|
||||
wss_port: config.gateway.clients_wss_port,
|
||||
@@ -281,22 +269,8 @@ impl<'a> HttpApiBuilder<'a> {
|
||||
)?);
|
||||
}
|
||||
|
||||
let wireguard_private_network = IpNetwork::new(
|
||||
IpAddr::from(Ipv4Addr::new(10, 1, 0, 0)),
|
||||
self.gateway_config.wireguard.private_network_prefix,
|
||||
)?;
|
||||
let wg_state = self.client_registry.and_then(|client_registry| {
|
||||
WireguardAppState::new(
|
||||
client_registry,
|
||||
Default::default(),
|
||||
self.gateway_config.wireguard.bind_address.port(),
|
||||
wireguard_private_network,
|
||||
)
|
||||
.ok()
|
||||
});
|
||||
|
||||
let bind_address = self.gateway_config.http.bind_address;
|
||||
let router = nym_node_http_api::NymNodeRouter::new(config, None, wg_state);
|
||||
let router = nym_node_http_api::NymNodeRouter::new(config, None, None);
|
||||
|
||||
tokio::spawn(async move {
|
||||
let server = match router.build_server(&bind_address).await {
|
||||
|
||||
@@ -37,19 +37,6 @@ pub async fn load_ip_packet_router_config<P: AsRef<Path>>(
|
||||
read_ip_packet_router_config(id, path)
|
||||
}
|
||||
|
||||
pub async fn load_wireguard_config<P: AsRef<Path>>(
|
||||
id: &str,
|
||||
path: P,
|
||||
) -> Result<nym_wireguard_types::config::Wireguard, GatewayError> {
|
||||
let path = path.as_ref();
|
||||
if let Ok(cfg) = read_wireguard_config(id, path) {
|
||||
return Ok(cfg);
|
||||
}
|
||||
|
||||
nym_ip_packet_router::config::helpers::try_upgrade_config(path).await?;
|
||||
read_wireguard_config(id, path)
|
||||
}
|
||||
|
||||
pub fn read_network_requester_config<P: AsRef<Path>>(
|
||||
id: &str,
|
||||
path: P,
|
||||
@@ -78,20 +65,6 @@ pub fn read_ip_packet_router_config<P: AsRef<Path>>(
|
||||
})
|
||||
}
|
||||
|
||||
pub fn read_wireguard_config<P: AsRef<Path>>(
|
||||
id: &str,
|
||||
path: P,
|
||||
) -> Result<nym_wireguard_types::config::Wireguard, GatewayError> {
|
||||
let path = path.as_ref();
|
||||
nym_wireguard_types::config::Wireguard::read_from_toml_file(path).map_err(|err| {
|
||||
GatewayError::WireguardConfigLoadFailure {
|
||||
id: id.to_string(),
|
||||
path: path.to_path_buf(),
|
||||
source: err,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) async fn initialise_main_storage(
|
||||
config: &Config,
|
||||
) -> Result<PersistentStorage, GatewayError> {
|
||||
|
||||
@@ -60,3 +60,6 @@ nym-ip-packet-router = { path = "../service-providers/ip-packet-router" }
|
||||
[build-dependencies]
|
||||
# temporary bonding information v1 (to grab and parse nym-mixnode and nym-gateway package versions)
|
||||
cargo_metadata = "0.18.1"
|
||||
|
||||
[features]
|
||||
wireguard = []
|
||||
|
||||
@@ -18,8 +18,8 @@ use nym_mixnode::MixnodeError;
|
||||
use nym_network_requester::{CustomGatewayDetails, GatewayDetails};
|
||||
use nym_node::config;
|
||||
use nym_node::config::mixnode::DEFAULT_VERLOC_PORT;
|
||||
use nym_node::config::Config;
|
||||
use nym_node::config::{default_config_filepath, ConfigBuilder, NodeMode};
|
||||
use nym_node::config::{Config, DEFAULT_WIREGUARD_NETWORK_IP};
|
||||
use nym_node::error::{EntryGatewayError, ExitGatewayError, NymNodeError};
|
||||
use nym_node_http_api::api::api_requests::v1::node::models::NodeDescription;
|
||||
use rand::rngs::OsRng;
|
||||
@@ -400,15 +400,6 @@ async fn migrate_gateway(mut args: Args) -> Result<(), NymNodeError> {
|
||||
},
|
||||
..config::MixnodeConfig::new_default()
|
||||
}))
|
||||
.with_wireguard(args.wireguard.override_config_section(config::Wireguard {
|
||||
enabled: cfg.wireguard.enabled,
|
||||
bind_address: cfg.wireguard.bind_address,
|
||||
private_network_ip: DEFAULT_WIREGUARD_NETWORK_IP,
|
||||
announced_port: cfg.wireguard.announced_port,
|
||||
private_network_prefix: cfg.wireguard.private_network_prefix,
|
||||
// this is fine as currently the paths stored inside gateway itself are empty
|
||||
storage_paths: config::persistence::WireguardPaths::new(&data_dir),
|
||||
}))
|
||||
.with_entry_gateway(args.entry_gateway.override_config_section(
|
||||
config::EntryGatewayConfig {
|
||||
storage_paths: config::persistence::EntryGatewayPaths::new(&data_dir),
|
||||
|
||||
@@ -13,6 +13,8 @@ use serde::{Deserialize, Serialize};
|
||||
use std::path::Path;
|
||||
use url::Url;
|
||||
|
||||
use super::LocalWireguardOpts;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct ExitGatewayConfig {
|
||||
@@ -136,6 +138,7 @@ pub struct EphemeralConfig {
|
||||
pub gateway: nym_gateway::config::Config,
|
||||
pub nr_opts: LocalNetworkRequesterOpts,
|
||||
pub ipr_opts: LocalIpPacketRouterOpts,
|
||||
pub wg_opts: LocalWireguardOpts,
|
||||
}
|
||||
|
||||
fn base_client_config(config: &Config) -> nym_client_core_config_types::Client {
|
||||
@@ -241,6 +244,18 @@ pub fn ephemeral_exit_gateway_config(
|
||||
let ipr_enabled = config.exit_gateway.ip_packet_router.debug.enabled;
|
||||
let nr_enabled = config.exit_gateway.network_requester.debug.enabled;
|
||||
|
||||
let wg_opts = LocalWireguardOpts {
|
||||
config: super::Wireguard {
|
||||
enabled: config.wireguard.enabled,
|
||||
bind_address: config.wireguard.bind_address,
|
||||
private_network_ip: config.wireguard.private_network_ip,
|
||||
announced_port: config.wireguard.announced_port,
|
||||
private_network_prefix: config.wireguard.private_network_prefix,
|
||||
storage_paths: config.wireguard.storage_paths.clone(),
|
||||
},
|
||||
custom_mixnet_path: None,
|
||||
};
|
||||
|
||||
let mut gateway = ephemeral_gateway_config(config, mnemonic)?;
|
||||
gateway.ip_packet_router.enabled = ipr_enabled;
|
||||
gateway.network_requester.enabled = nr_enabled;
|
||||
@@ -253,6 +268,7 @@ pub fn ephemeral_exit_gateway_config(
|
||||
Ok(EphemeralConfig {
|
||||
nr_opts,
|
||||
ipr_opts,
|
||||
wg_opts,
|
||||
gateway,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -57,18 +57,10 @@ pub fn ephemeral_gateway_config(
|
||||
cosmos_mnemonic: mnemonic.clone(),
|
||||
};
|
||||
|
||||
let wireguard = nym_wireguard_types::config::Wireguard {
|
||||
enabled: config.wireguard.enabled,
|
||||
bind_address: config.wireguard.bind_address,
|
||||
announced_port: config.wireguard.announced_port,
|
||||
private_network_prefix: config.wireguard.private_network_prefix,
|
||||
};
|
||||
|
||||
Ok(nym_gateway::config::Config::externally_loaded(
|
||||
host,
|
||||
http,
|
||||
gateway,
|
||||
wireguard,
|
||||
nym_gateway::config::GatewayPaths::new_empty(),
|
||||
nym_gateway::config::NetworkRequester { enabled: false },
|
||||
nym_gateway::config::IpPacketRouter { enabled: false },
|
||||
|
||||
@@ -531,3 +531,10 @@ impl Wireguard {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct LocalWireguardOpts {
|
||||
pub config: Wireguard,
|
||||
|
||||
pub custom_mixnet_path: Option<PathBuf>,
|
||||
}
|
||||
|
||||
@@ -43,6 +43,10 @@ pub const DEFAULT_IPR_ACK_KEY_FILENAME: &str = "aes128ctr_ipr_ack";
|
||||
pub const DEFAULT_IPR_REPLY_SURB_DB_FILENAME: &str = "ipr_persistent_reply_store.sqlite";
|
||||
pub const DEFAULT_IPR_GATEWAYS_DB_FILENAME: &str = "ipr_gateways_info_store.sqlite";
|
||||
|
||||
// Wireguard
|
||||
pub const DEFAULT_X25519_WG_DH_KEY_FILENAME: &str = "x25519_wg_dh";
|
||||
pub const DEFAULT_X25519_WG_PUBLIC_DH_KEY_FILENAME: &str = "x25519_wg_dh.pub";
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq, Eq, Serialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct NymNodePaths {
|
||||
@@ -366,11 +370,16 @@ impl ExitGatewayPaths {
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq, Eq, Serialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct WireguardPaths {
|
||||
// pub keys:
|
||||
pub private_diffie_hellman_key_file: PathBuf,
|
||||
pub public_diffie_hellman_key_file: PathBuf,
|
||||
}
|
||||
|
||||
impl WireguardPaths {
|
||||
pub fn new<P: AsRef<Path>>(_data_dir: P) -> Self {
|
||||
WireguardPaths {}
|
||||
pub fn new<P: AsRef<Path>>(data_dir: P) -> Self {
|
||||
let data_dir = data_dir.as_ref();
|
||||
WireguardPaths {
|
||||
private_diffie_hellman_key_file: data_dir.join(DEFAULT_X25519_WG_DH_KEY_FILENAME),
|
||||
public_diffie_hellman_key_file: data_dir.join(DEFAULT_X25519_WG_PUBLIC_DH_KEY_FILENAME),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,9 +127,12 @@ announced_port = {{ wireguard.announced_port }}
|
||||
# The maximum value for IPv4 is 32 and for IPv6 is 128
|
||||
private_network_prefix = {{ wireguard.private_network_prefix }}
|
||||
|
||||
# Paths for wireguard keys, client registries, etc.
|
||||
[wireguard.storage_paths]
|
||||
# currently empty
|
||||
# Path to file containing wireguard x25519 diffie hellman private key.
|
||||
private_x25519_diffie_hellman_key_file = '{{ wireguard.storage_paths.private_diffie_hellman_key_file }}'
|
||||
|
||||
# Path to file containing wireguard x25519 diffie hellman public key.
|
||||
public_x25519_diffie_hellman_key_file = '{{ wireguard.storage_paths.public_diffie_hellman_key_file }}'
|
||||
|
||||
|
||||
##### mixnode mode nym-node config options #####
|
||||
|
||||
Reference in New Issue
Block a user