// Copyright 2023 - Nym Technologies SA // SPDX-License-Identifier: GPL-3.0-only use nym_config::defaults::{DEFAULT_NYM_NODE_HTTP_PORT, WG_PORT}; use serde::{Deserialize, Serialize}; use serde_helpers::*; use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use std::path::PathBuf; pub mod persistence; mod serde_helpers; pub const DEFAULT_WIREGUARD_PORT: u16 = WG_PORT; pub const DEFAULT_WIREGUARD_PREFIX: u8 = 16; pub const DEFAULT_HTTP_PORT: u16 = DEFAULT_NYM_NODE_HTTP_PORT; // TODO: this is very much a WIP. we need proper ssl certificate support here #[derive(Debug, Deserialize, PartialEq, Serialize)] #[serde(deny_unknown_fields)] pub struct Host { /// Ip address(es) of this host, such as 1.1.1.1 that external clients will use for connections. pub public_ips: Vec, /// Optional hostname of this node, for example nymtech.net. // TODO: this is temporary. to be replaced by pulling the data directly from the certs. #[serde(deserialize_with = "de_maybe_string")] pub hostname: Option, } impl Host { pub fn validate(&self) -> bool { if self.public_ips.is_empty() { return false; } true } } #[derive(Debug, Deserialize, PartialEq, Serialize)] #[serde(default)] #[serde(deny_unknown_fields)] pub struct Http { /// Socket address this node will use for binding its http API. /// default: `0.0.0.0:8080` /// note: for legacy reasons, it defaults to port `8000` for mixnodes. pub bind_address: SocketAddr, /// Path to assets directory of custom landing page of this node. #[serde(deserialize_with = "de_maybe_path")] pub landing_page_assets_path: Option, } impl Default for Http { fn default() -> Self { Http { bind_address: SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), DEFAULT_HTTP_PORT), landing_page_assets_path: None, } } } #[derive(Debug, Deserialize, PartialEq, Serialize)] #[serde(default)] #[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, /// Paths for wireguard keys, client registries, etc. pub storage_paths: persistence::WireguardPaths, } impl Default for Wireguard { fn default() -> Self { Wireguard { enabled: false, bind_address: SocketAddr::new( IpAddr::V4(Ipv4Addr::UNSPECIFIED), DEFAULT_WIREGUARD_PORT, ), announced_port: DEFAULT_WIREGUARD_PORT, private_network_prefix: DEFAULT_WIREGUARD_PREFIX, storage_paths: persistence::WireguardPaths {}, } } }