veilid/veilid-core/src/veilid_config.rs

1174 lines
40 KiB
Rust
Raw Normal View History

use std::path::PathBuf;
use directories::ProjectDirs;
2022-06-07 21:31:05 -04:00
use crate::*;
2022-02-06 21:18:42 -05:00
2022-05-31 19:54:52 -04:00
////////////////////////////////////////////////////////////////////////////////////////////////
2023-05-29 15:24:57 -04:00
pub type ConfigCallbackReturn = VeilidAPIResult<Box<dyn core::any::Any + Send>>;
2022-07-12 08:02:22 -04:00
pub type ConfigCallback = Arc<dyn Fn(String) -> ConfigCallbackReturn + Send + Sync>;
2021-11-22 11:28:30 -05:00
/// Enable and configure HTTPS access to the Veilid node
///
/// ```yaml
/// https:
/// enabled: false
/// listen_address: ':5150'
/// path: 'app'
/// url: 'https://localhost:5150'
/// ```
///
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
2023-08-31 22:01:00 -04:00
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
2021-11-22 11:28:30 -05:00
pub struct VeilidConfigHTTPS {
pub enabled: bool,
pub listen_address: String,
pub path: String,
2023-08-31 22:01:00 -04:00
#[cfg_attr(target_arch = "wasm32", tsify(optional))]
pub url: Option<String>, // Fixed URL is not optional for TLS-based protocols and is dynamically validated
2021-11-22 11:28:30 -05:00
}
impl Default for VeilidConfigHTTPS {
fn default() -> Self {
Self {
enabled: false,
listen_address: String::from(":5150"),
path: String::from("app"),
url: None,
}
}
}
/// Enable and configure HTTP access to the Veilid node
///
/// ```yaml
/// http:
/// enabled: false
/// listen_address: ':5150'
/// path: 'app"
/// url: 'https://localhost:5150'
/// ```
///
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
2023-08-31 22:01:00 -04:00
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
2021-11-22 11:28:30 -05:00
pub struct VeilidConfigHTTP {
pub enabled: bool,
pub listen_address: String,
pub path: String,
2023-08-31 22:01:00 -04:00
#[cfg_attr(target_arch = "wasm32", tsify(optional))]
pub url: Option<String>,
2021-11-22 11:28:30 -05:00
}
impl Default for VeilidConfigHTTP {
fn default() -> Self {
Self {
enabled: false,
listen_address: String::from(":5150"),
path: String::from("app"),
url: None,
}
}
}
/// Application configuration
///
/// Configure web access to the Progressive Web App (PWA)
///
/// To be implemented...
///
2023-08-31 22:01:00 -04:00
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
2021-11-22 11:28:30 -05:00
pub struct VeilidConfigApplication {
pub https: VeilidConfigHTTPS,
pub http: VeilidConfigHTTP,
}
/// Enable and configure UDP
///
/// ```yaml
/// udp:
/// enabled: true
/// socket_pool_size: 0
/// listen_address: ':5150'
/// public_address: ''
/// ```
///
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
2023-08-31 22:01:00 -04:00
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
2021-11-22 11:28:30 -05:00
pub struct VeilidConfigUDP {
pub enabled: bool,
pub socket_pool_size: u32,
pub listen_address: String,
2023-08-31 22:01:00 -04:00
#[cfg_attr(target_arch = "wasm32", tsify(optional))]
2021-11-22 11:28:30 -05:00
pub public_address: Option<String>,
}
impl Default for VeilidConfigUDP {
fn default() -> Self {
Self {
enabled: true,
socket_pool_size: 0,
listen_address: String::from(":5150"),
public_address: None,
}
}
}
/// Enable and configure TCP
///
/// ```yaml
/// tcp:
/// connect: true
/// listen: true
/// max_connections: 32
/// listen_address: ':5150'
/// public_address: ''
///
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
2023-08-31 22:01:00 -04:00
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
2021-11-22 11:28:30 -05:00
pub struct VeilidConfigTCP {
pub connect: bool,
pub listen: bool,
pub max_connections: u32,
pub listen_address: String,
2023-08-31 22:01:00 -04:00
#[cfg_attr(target_arch = "wasm32", tsify(optional))]
2021-11-22 11:28:30 -05:00
pub public_address: Option<String>,
}
impl Default for VeilidConfigTCP {
fn default() -> Self {
Self {
connect: true,
listen: true,
max_connections: 32,
listen_address: String::from(":5150"),
public_address: None,
}
}
}
/// Enable and configure Web Sockets
///
/// ```yaml
/// ws:
/// connect: true
/// listen: true
/// max_connections: 16
/// listen_address: ':5150'
/// path: 'ws'
/// url: 'ws://localhost:5150/ws'
///
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
2023-08-31 22:01:00 -04:00
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
2023-07-15 16:18:13 -04:00
2021-11-22 11:28:30 -05:00
pub struct VeilidConfigWS {
pub connect: bool,
pub listen: bool,
pub max_connections: u32,
pub listen_address: String,
pub path: String,
2023-08-31 22:01:00 -04:00
#[cfg_attr(target_arch = "wasm32", tsify(optional))]
pub url: Option<String>,
2021-11-22 11:28:30 -05:00
}
impl Default for VeilidConfigWS {
fn default() -> Self {
Self {
connect: true,
listen: true,
max_connections: 16,
listen_address: String::from(":5150"),
path: String::from("ws"),
url: None,
}
}
}
/// Enable and configure Secure Web Sockets
///
/// ```yaml
/// wss:
/// connect: true
2022-10-13 22:05:43 -04:00
/// listen: false
/// max_connections: 16
/// listen_address: ':5150'
/// path: 'ws'
/// url: ''
///
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
2023-08-31 22:01:00 -04:00
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
2023-07-15 16:18:13 -04:00
2021-11-22 11:28:30 -05:00
pub struct VeilidConfigWSS {
pub connect: bool,
pub listen: bool,
pub max_connections: u32,
pub listen_address: String,
pub path: String,
2023-08-31 22:01:00 -04:00
#[cfg_attr(target_arch = "wasm32", tsify(optional))]
pub url: Option<String>, // Fixed URL is not optional for TLS-based protocols and is dynamically validated
2021-11-22 11:28:30 -05:00
}
impl Default for VeilidConfigWSS {
fn default() -> Self {
Self {
connect: true,
listen: false,
max_connections: 16,
listen_address: String::from(":5150"),
path: String::from("ws"),
url: None,
}
}
}
/// Configure Network Protocols
///
/// Veilid can communicate over UDP, TCP, and Web Sockets.
///
/// All protocols are available by default, and the Veilid node will
/// sort out which protocol is used for each peer connection.
///
2023-08-31 22:01:00 -04:00
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
2023-07-15 16:18:13 -04:00
2021-11-22 11:28:30 -05:00
pub struct VeilidConfigProtocol {
pub udp: VeilidConfigUDP,
pub tcp: VeilidConfigTCP,
pub ws: VeilidConfigWS,
pub wss: VeilidConfigWSS,
}
/// Configure TLS
///
/// ```yaml
/// tls:
/// certificate_path: /path/to/cert
/// private_key_path: /path/to/private/key
/// connection_initial_timeout_ms: 2000
///
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
2023-08-31 22:01:00 -04:00
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
2021-11-22 11:28:30 -05:00
pub struct VeilidConfigTLS {
pub certificate_path: String,
pub private_key_path: String,
2022-01-27 09:53:01 -05:00
pub connection_initial_timeout_ms: u32,
2021-11-22 11:28:30 -05:00
}
impl Default for VeilidConfigTLS {
fn default() -> Self {
Self {
certificate_path: get_default_ssl_directory("certs/server.crt"),
private_key_path: get_default_ssl_directory("keys/server.key"),
connection_initial_timeout_ms: 2000,
}
}
}
pub fn get_default_ssl_directory(sub_path: &str) -> String {
let default_path = PathBuf::from("/etc/veilid-server/ssl").join(sub_path);
#[cfg(unix)]
if default_path.exists() {
return default_path.to_string_lossy().into();
}
ProjectDirs::from("org", "Veilid", "Veilid")
.map(|dirs| dirs.data_local_dir().join("ssl").join(sub_path))
.unwrap_or_else(|| PathBuf::from("./ssl").join(sub_path))
.to_string_lossy()
.into()
}
/// Configure the Distributed Hash Table (DHT)
///
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
2023-08-31 22:01:00 -04:00
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
2021-11-22 11:28:30 -05:00
pub struct VeilidConfigDHT {
2023-05-29 15:24:57 -04:00
pub max_find_node_count: u32,
pub resolve_node_timeout_ms: u32,
2021-11-22 11:28:30 -05:00
pub resolve_node_count: u32,
pub resolve_node_fanout: u32,
2023-05-29 15:24:57 -04:00
pub get_value_timeout_ms: u32,
2021-11-22 11:28:30 -05:00
pub get_value_count: u32,
pub get_value_fanout: u32,
2023-05-29 15:24:57 -04:00
pub set_value_timeout_ms: u32,
2021-11-22 11:28:30 -05:00
pub set_value_count: u32,
pub set_value_fanout: u32,
pub min_peer_count: u32,
2022-01-27 09:53:01 -05:00
pub min_peer_refresh_time_ms: u32,
pub validate_dial_info_receipt_time_ms: u32,
2023-05-29 15:24:57 -04:00
pub local_subkey_cache_size: u32,
pub local_max_subkey_cache_memory_mb: u32,
pub remote_subkey_cache_size: u32,
pub remote_max_records: u32,
pub remote_max_subkey_cache_memory_mb: u32,
pub remote_max_storage_space_mb: u32,
2023-11-19 21:14:58 -05:00
pub public_watch_limit: u32,
pub member_watch_limit: u32,
2023-11-25 18:59:43 -05:00
pub max_watch_expiration_ms: u32,
2021-11-22 11:28:30 -05:00
}
impl Default for VeilidConfigDHT {
fn default() -> Self {
Self {
// Assuming some reasonable defaults
max_find_node_count: 20,
resolve_node_timeout_ms: 10000,
resolve_node_count: 1,
resolve_node_fanout: 4,
get_value_timeout_ms: 10000,
get_value_count: 3,
get_value_fanout: 4,
set_value_timeout_ms: 10000,
set_value_count: 5,
set_value_fanout: 4,
min_peer_count: 20,
min_peer_refresh_time_ms: 60000,
validate_dial_info_receipt_time_ms: 2000,
local_subkey_cache_size: 1024,
local_max_subkey_cache_memory_mb: 256,
remote_subkey_cache_size: 128,
remote_max_records: 128,
remote_max_subkey_cache_memory_mb: 256,
remote_max_storage_space_mb: 256,
}
}
}
/// Configure RPC
///
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
2023-08-31 22:01:00 -04:00
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
2021-11-22 11:28:30 -05:00
pub struct VeilidConfigRPC {
pub concurrency: u32,
pub queue_size: u32,
2023-08-31 22:01:00 -04:00
#[cfg_attr(target_arch = "wasm32", tsify(optional))]
2022-01-27 09:53:01 -05:00
pub max_timestamp_behind_ms: Option<u32>,
2023-08-31 22:01:00 -04:00
#[cfg_attr(target_arch = "wasm32", tsify(optional))]
2022-01-27 09:53:01 -05:00
pub max_timestamp_ahead_ms: Option<u32>,
pub timeout_ms: u32,
2021-11-22 11:28:30 -05:00
pub max_route_hop_count: u8,
2022-10-13 22:05:43 -04:00
pub default_route_hop_count: u8,
2021-11-22 11:28:30 -05:00
}
impl Default for VeilidConfigRPC {
fn default() -> Self {
Self {
concurrency: 0,
queue_size: 1024,
max_timestamp_behind_ms: None,
max_timestamp_ahead_ms: None,
timeout_ms: 5000,
max_route_hop_count: 4,
default_route_hop_count: 1,
}
}
}
/// Configure the network routing table
///
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
2023-08-31 22:01:00 -04:00
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
2022-03-24 10:14:50 -04:00
pub struct VeilidConfigRoutingTable {
2023-06-03 18:33:27 -04:00
#[schemars(with = "Vec<String>")]
pub node_id: TypedKeyGroup,
2023-06-03 18:33:27 -04:00
#[schemars(with = "Vec<String>")]
pub node_id_secret: TypedSecretGroup,
2023-02-07 21:44:50 -05:00
pub bootstrap: Vec<String>,
2022-03-24 10:14:50 -04:00
pub limit_over_attached: u32,
pub limit_fully_attached: u32,
pub limit_attached_strong: u32,
pub limit_attached_good: u32,
pub limit_attached_weak: u32,
2022-12-26 16:33:48 -05:00
// xxx pub enable_public_internet: bool,
// xxx pub enable_local_network: bool,
2022-03-24 10:14:50 -04:00
}
2021-11-22 11:28:30 -05:00
impl Default for VeilidConfigRoutingTable {
fn default() -> Self {
Self {
node_id: TypedKeyGroup::default(),
node_id_secret: TypedSecretGroup::default(),
bootstrap: vec!["bootstrap.veilid.net".to_string()],
limit_over_attached: 64,
limit_fully_attached: 32,
limit_attached_strong: 16,
limit_attached_good: 8,
limit_attached_weak: 4,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
2023-08-31 22:01:00 -04:00
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
2021-11-22 11:28:30 -05:00
pub struct VeilidConfigNetwork {
2022-01-27 09:53:01 -05:00
pub connection_initial_timeout_ms: u32,
2022-03-19 18:19:40 -04:00
pub connection_inactivity_timeout_ms: u32,
2022-05-04 20:40:10 -04:00
pub max_connections_per_ip4: u32,
pub max_connections_per_ip6_prefix: u32,
pub max_connections_per_ip6_prefix_size: u32,
pub max_connection_frequency_per_min: u32,
pub client_allowlist_timeout_ms: u32,
2022-04-16 11:18:54 -04:00
pub reverse_connection_receipt_time_ms: u32,
pub hole_punch_receipt_time_ms: u32,
2023-08-31 22:01:00 -04:00
#[cfg_attr(target_arch = "wasm32", tsify(optional))]
2023-06-23 21:12:48 -04:00
pub network_key_password: Option<String>,
2022-03-24 10:14:50 -04:00
pub routing_table: VeilidConfigRoutingTable,
2021-11-22 11:28:30 -05:00
pub rpc: VeilidConfigRPC,
pub dht: VeilidConfigDHT,
pub upnp: bool,
2022-08-07 14:55:48 -04:00
pub detect_address_changes: bool,
2021-11-23 20:19:16 -05:00
pub restricted_nat_retries: u32,
2021-11-22 11:28:30 -05:00
pub tls: VeilidConfigTLS,
pub application: VeilidConfigApplication,
pub protocol: VeilidConfigProtocol,
}
impl Default for VeilidConfigNetwork {
fn default() -> Self {
Self {
connection_initial_timeout_ms: 2000,
connection_inactivity_timeout_ms: 60000,
max_connections_per_ip4: 32,
max_connections_per_ip6_prefix: 32,
max_connections_per_ip6_prefix_size: 56,
max_connection_frequency_per_min: 128,
client_allowlist_timeout_ms: 300000,
reverse_connection_receipt_time_ms: 5000,
hole_punch_receipt_time_ms: 5000,
network_key_password: None,
routing_table: VeilidConfigRoutingTable::default(),
rpc: VeilidConfigRPC::default(),
dht: VeilidConfigDHT::default(),
upnp: true,
detect_address_changes: true,
restricted_nat_retries: 0,
tls: VeilidConfigTLS::default(),
application: VeilidConfigApplication::default(),
protocol: VeilidConfigProtocol::default(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
2023-08-31 22:01:00 -04:00
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
2021-11-22 11:28:30 -05:00
pub struct VeilidConfigTableStore {
pub directory: String,
2022-01-18 21:21:11 -05:00
pub delete: bool,
}
impl Default for VeilidConfigTableStore {
fn default() -> Self {
Self {
directory: get_default_store_path("table_store"),
delete: false,
}
}
}
fn get_default_store_path(store_type: &str) -> String {
#[cfg(unix)]
{
let globalpath = PathBuf::from(format!("/var/db/veilid-server/{}", store_type));
if globalpath.exists() {
return globalpath.to_string_lossy().into();
}
}
ProjectDirs::from("org", "Veilid", "Veilid")
.map(|dirs| dirs.data_local_dir().to_path_buf())
.unwrap_or_else(|| PathBuf::from("./"))
.join(store_type)
.to_string_lossy()
.into()
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
2023-08-31 22:01:00 -04:00
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
2022-01-18 21:21:11 -05:00
pub struct VeilidConfigBlockStore {
pub directory: String,
pub delete: bool,
2021-11-22 11:28:30 -05:00
}
impl Default for VeilidConfigBlockStore {
fn default() -> Self {
Self {
directory: get_default_store_path("block_store"),
delete: false,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
2023-08-31 22:01:00 -04:00
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
2022-01-08 23:33:25 -05:00
pub struct VeilidConfigProtectedStore {
pub allow_insecure_fallback: bool,
pub always_use_insecure_storage: bool,
2023-05-29 15:24:57 -04:00
pub directory: String,
2022-01-18 21:21:11 -05:00
pub delete: bool,
2023-05-29 15:24:57 -04:00
pub device_encryption_key_password: String,
2023-08-31 22:01:00 -04:00
#[cfg_attr(target_arch = "wasm32", tsify(optional))]
2023-05-29 15:24:57 -04:00
pub new_device_encryption_key_password: Option<String>,
2022-01-08 23:33:25 -05:00
}
impl Default for VeilidConfigProtectedStore {
fn default() -> Self {
Self {
allow_insecure_fallback: false,
always_use_insecure_storage: false,
directory: get_default_store_path("protected_store"),
delete: false,
device_encryption_key_password: String::from(""),
new_device_encryption_key_password: None,
}
}
}
2023-08-31 22:01:00 -04:00
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
2021-11-22 11:28:30 -05:00
pub struct VeilidConfigCapabilities {
2023-07-03 15:10:28 -04:00
pub disable: Vec<FourCC>,
2021-11-22 11:28:30 -05:00
}
2023-08-31 22:01:00 -04:00
#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
#[cfg_attr(target_arch = "wasm32", tsify(namespace, from_wasm_abi))]
2022-01-31 22:47:17 -05:00
pub enum VeilidConfigLogLevel {
Off,
Error,
Warn,
Info,
Debug,
Trace,
}
impl VeilidConfigLogLevel {
2022-06-07 21:31:05 -04:00
pub fn to_veilid_log_level(&self) -> Option<VeilidLogLevel> {
2022-01-31 22:47:17 -05:00
match self {
2022-06-07 21:31:05 -04:00
Self::Off => None,
Self::Error => Some(VeilidLogLevel::Error),
Self::Warn => Some(VeilidLogLevel::Warn),
Self::Info => Some(VeilidLogLevel::Info),
Self::Debug => Some(VeilidLogLevel::Debug),
Self::Trace => Some(VeilidLogLevel::Trace),
}
}
2022-06-15 21:51:38 -04:00
pub fn to_tracing_level_filter(&self) -> level_filters::LevelFilter {
match self {
Self::Off => level_filters::LevelFilter::OFF,
Self::Error => level_filters::LevelFilter::ERROR,
Self::Warn => level_filters::LevelFilter::WARN,
Self::Info => level_filters::LevelFilter::INFO,
Self::Debug => level_filters::LevelFilter::DEBUG,
Self::Trace => level_filters::LevelFilter::TRACE,
}
}
2022-06-07 21:31:05 -04:00
pub fn from_veilid_log_level(level: Option<VeilidLogLevel>) -> Self {
match level {
None => Self::Off,
Some(VeilidLogLevel::Error) => Self::Error,
Some(VeilidLogLevel::Warn) => Self::Warn,
Some(VeilidLogLevel::Info) => Self::Info,
Some(VeilidLogLevel::Debug) => Self::Debug,
Some(VeilidLogLevel::Trace) => Self::Trace,
2022-01-31 22:47:17 -05:00
}
}
2022-07-01 12:13:52 -04:00
pub fn from_tracing_level_filter(level: level_filters::LevelFilter) -> Self {
match level {
level_filters::LevelFilter::OFF => Self::Off,
level_filters::LevelFilter::ERROR => Self::Error,
level_filters::LevelFilter::WARN => Self::Warn,
level_filters::LevelFilter::INFO => Self::Info,
level_filters::LevelFilter::DEBUG => Self::Debug,
level_filters::LevelFilter::TRACE => Self::Trace,
}
}
2022-01-31 22:47:17 -05:00
}
impl Default for VeilidConfigLogLevel {
fn default() -> Self {
Self::Off
}
}
2023-06-09 19:08:49 -04:00
impl FromStr for VeilidConfigLogLevel {
type Err = VeilidAPIError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"Off" => Self::Off,
"Error" => Self::Error,
"Warn" => Self::Warn,
"Info" => Self::Info,
"Debug" => Self::Debug,
"Trace" => Self::Trace,
_ => {
apibail_invalid_argument!("Can't convert str", "s", s);
}
})
}
}
impl fmt::Display for VeilidConfigLogLevel {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
let text = match self {
Self::Off => "Off",
Self::Error => "Error",
Self::Warn => "Warn",
Self::Info => "Info",
Self::Debug => "Debug",
Self::Trace => "Trace",
};
write!(f, "{}", text)
}
}
2022-01-31 22:47:17 -05:00
2023-08-31 22:01:00 -04:00
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
2021-11-22 11:28:30 -05:00
pub struct VeilidConfigInner {
2022-01-08 23:33:25 -05:00
pub program_name: String,
2021-11-22 11:28:30 -05:00
pub namespace: String,
pub capabilities: VeilidConfigCapabilities,
2022-01-08 23:33:25 -05:00
pub protected_store: VeilidConfigProtectedStore,
pub table_store: VeilidConfigTableStore,
2022-01-18 21:21:11 -05:00
pub block_store: VeilidConfigBlockStore,
2021-11-22 11:28:30 -05:00
pub network: VeilidConfigNetwork,
}
2022-09-19 21:18:46 -04:00
/// The Veilid Configuration
///
2022-10-13 22:05:43 -04:00
/// Veilid is configured
2021-11-22 11:28:30 -05:00
#[derive(Clone)]
pub struct VeilidConfig {
2022-11-16 12:49:53 -05:00
update_cb: Option<UpdateCallback>,
2021-11-22 11:28:30 -05:00
inner: Arc<RwLock<VeilidConfigInner>>,
}
2022-06-10 17:07:10 -04:00
impl fmt::Debug for VeilidConfig {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let inner = self.inner.read();
f.debug_struct("VeilidConfig")
.field("inner", &*inner)
.finish()
}
}
2021-11-27 12:44:21 -05:00
impl Default for VeilidConfig {
fn default() -> Self {
Self::new()
}
}
2021-11-22 11:28:30 -05:00
impl VeilidConfig {
fn new_inner() -> VeilidConfigInner {
VeilidConfigInner::default()
}
pub fn new() -> Self {
Self {
2022-11-16 12:49:53 -05:00
update_cb: None,
2021-11-22 11:28:30 -05:00
inner: Arc::new(RwLock::new(Self::new_inner())),
}
}
2022-11-16 12:49:53 -05:00
pub fn setup_from_json(
&mut self,
config: String,
update_cb: UpdateCallback,
2023-05-29 15:24:57 -04:00
) -> VeilidAPIResult<()> {
2022-11-16 12:49:53 -05:00
self.update_cb = Some(update_cb);
2022-02-09 09:47:36 -05:00
2022-11-16 12:49:53 -05:00
self.with_mut(|inner| {
*inner = serde_json::from_str(&config).map_err(VeilidAPIError::generic)?;
Ok(())
})
}
pub fn setup_from_config(
&mut self,
config: VeilidConfigInner,
update_cb: UpdateCallback,
) -> VeilidAPIResult<()> {
self.update_cb = Some(update_cb);
self.with_mut(|inner| {
*inner = config;
Ok(())
2022-11-16 12:49:53 -05:00
})
2022-02-09 09:47:36 -05:00
}
2023-05-29 15:24:57 -04:00
pub fn setup(&mut self, cb: ConfigCallback, update_cb: UpdateCallback) -> VeilidAPIResult<()> {
2023-03-01 15:50:30 -05:00
self.update_cb = Some(update_cb);
self.with_mut(|inner| {
// Simple config transformation
macro_rules! get_config {
($key:expr) => {
let keyname = &stringify!($key)[6..];
let v = cb(keyname.to_owned())?;
$key = match v.downcast() {
Ok(v) => *v,
2023-03-01 20:12:30 -05:00
Err(e) => {
apibail_generic!(format!(
2023-03-03 10:55:31 -05:00
"incorrect type for key {}: {:?}",
keyname,
2023-03-01 20:12:30 -05:00
type_name_of_val(&*e)
))
2023-03-01 15:50:30 -05:00
}
};
2023-02-07 21:44:50 -05:00
};
2023-03-01 15:50:30 -05:00
}
2022-11-16 12:49:53 -05:00
2022-01-08 23:33:25 -05:00
get_config!(inner.program_name);
2021-11-22 11:28:30 -05:00
get_config!(inner.namespace);
2023-07-03 15:10:28 -04:00
get_config!(inner.capabilities.disable);
2022-01-08 23:33:25 -05:00
get_config!(inner.table_store.directory);
2022-01-18 21:21:11 -05:00
get_config!(inner.table_store.delete);
get_config!(inner.block_store.directory);
get_config!(inner.block_store.delete);
2022-01-08 23:33:25 -05:00
get_config!(inner.protected_store.allow_insecure_fallback);
get_config!(inner.protected_store.always_use_insecure_storage);
2023-05-29 15:24:57 -04:00
get_config!(inner.protected_store.directory);
2022-01-18 21:21:11 -05:00
get_config!(inner.protected_store.delete);
2023-05-29 15:24:57 -04:00
get_config!(inner.protected_store.device_encryption_key_password);
get_config!(inner.protected_store.new_device_encryption_key_password);
2022-01-27 09:53:01 -05:00
get_config!(inner.network.connection_initial_timeout_ms);
2022-03-19 18:19:40 -04:00
get_config!(inner.network.connection_inactivity_timeout_ms);
2022-05-04 20:40:10 -04:00
get_config!(inner.network.max_connections_per_ip4);
get_config!(inner.network.max_connections_per_ip6_prefix);
get_config!(inner.network.max_connections_per_ip6_prefix_size);
get_config!(inner.network.max_connection_frequency_per_min);
get_config!(inner.network.client_allowlist_timeout_ms);
get_config!(inner.network.reverse_connection_receipt_time_ms);
2023-03-03 10:55:31 -05:00
get_config!(inner.network.hole_punch_receipt_time_ms);
2023-06-23 21:12:48 -04:00
get_config!(inner.network.network_key_password);
2023-03-03 10:55:31 -05:00
get_config!(inner.network.routing_table.node_id);
get_config!(inner.network.routing_table.node_id_secret);
2023-02-07 21:44:50 -05:00
get_config!(inner.network.routing_table.bootstrap);
2022-03-24 10:14:50 -04:00
get_config!(inner.network.routing_table.limit_over_attached);
get_config!(inner.network.routing_table.limit_fully_attached);
get_config!(inner.network.routing_table.limit_attached_strong);
get_config!(inner.network.routing_table.limit_attached_good);
get_config!(inner.network.routing_table.limit_attached_weak);
2023-05-29 15:24:57 -04:00
get_config!(inner.network.dht.max_find_node_count);
2022-01-27 09:53:01 -05:00
get_config!(inner.network.dht.resolve_node_timeout_ms);
2021-11-22 11:28:30 -05:00
get_config!(inner.network.dht.resolve_node_count);
get_config!(inner.network.dht.resolve_node_fanout);
2022-01-27 09:53:01 -05:00
get_config!(inner.network.dht.get_value_timeout_ms);
2021-11-22 11:28:30 -05:00
get_config!(inner.network.dht.get_value_count);
get_config!(inner.network.dht.get_value_fanout);
2022-01-27 09:53:01 -05:00
get_config!(inner.network.dht.set_value_timeout_ms);
2021-11-22 11:28:30 -05:00
get_config!(inner.network.dht.set_value_count);
get_config!(inner.network.dht.set_value_fanout);
get_config!(inner.network.dht.min_peer_count);
2022-01-27 09:53:01 -05:00
get_config!(inner.network.dht.min_peer_refresh_time_ms);
get_config!(inner.network.dht.validate_dial_info_receipt_time_ms);
2023-05-29 15:24:57 -04:00
get_config!(inner.network.dht.local_subkey_cache_size);
get_config!(inner.network.dht.local_max_subkey_cache_memory_mb);
get_config!(inner.network.dht.remote_subkey_cache_size);
get_config!(inner.network.dht.remote_max_records);
get_config!(inner.network.dht.remote_max_subkey_cache_memory_mb);
get_config!(inner.network.dht.remote_max_storage_space_mb);
2023-11-19 21:14:58 -05:00
get_config!(inner.network.dht.public_watch_limit);
get_config!(inner.network.dht.member_watch_limit);
2021-11-22 11:28:30 -05:00
get_config!(inner.network.rpc.concurrency);
get_config!(inner.network.rpc.queue_size);
2022-01-27 09:53:01 -05:00
get_config!(inner.network.rpc.max_timestamp_behind_ms);
get_config!(inner.network.rpc.max_timestamp_ahead_ms);
get_config!(inner.network.rpc.timeout_ms);
2021-11-22 11:28:30 -05:00
get_config!(inner.network.rpc.max_route_hop_count);
2022-10-13 22:05:43 -04:00
get_config!(inner.network.rpc.default_route_hop_count);
2021-11-22 11:28:30 -05:00
get_config!(inner.network.upnp);
2022-08-07 14:55:48 -04:00
get_config!(inner.network.detect_address_changes);
2021-11-23 20:19:16 -05:00
get_config!(inner.network.restricted_nat_retries);
2021-11-22 11:28:30 -05:00
get_config!(inner.network.tls.certificate_path);
get_config!(inner.network.tls.private_key_path);
2022-01-27 09:53:01 -05:00
get_config!(inner.network.tls.connection_initial_timeout_ms);
2021-11-22 11:28:30 -05:00
get_config!(inner.network.application.https.enabled);
get_config!(inner.network.application.https.listen_address);
get_config!(inner.network.application.https.path);
get_config!(inner.network.application.https.url);
2021-11-22 11:28:30 -05:00
get_config!(inner.network.application.http.enabled);
get_config!(inner.network.application.http.listen_address);
get_config!(inner.network.application.http.path);
get_config!(inner.network.application.http.url);
2021-11-22 11:28:30 -05:00
get_config!(inner.network.protocol.udp.enabled);
get_config!(inner.network.protocol.udp.socket_pool_size);
get_config!(inner.network.protocol.udp.listen_address);
get_config!(inner.network.protocol.udp.public_address);
get_config!(inner.network.protocol.tcp.connect);
get_config!(inner.network.protocol.tcp.listen);
get_config!(inner.network.protocol.tcp.max_connections);
get_config!(inner.network.protocol.tcp.listen_address);
get_config!(inner.network.protocol.tcp.public_address);
get_config!(inner.network.protocol.ws.connect);
get_config!(inner.network.protocol.ws.listen);
get_config!(inner.network.protocol.ws.max_connections);
get_config!(inner.network.protocol.ws.listen_address);
get_config!(inner.network.protocol.ws.path);
get_config!(inner.network.protocol.ws.url);
2021-11-22 11:28:30 -05:00
get_config!(inner.network.protocol.wss.connect);
get_config!(inner.network.protocol.wss.listen);
get_config!(inner.network.protocol.wss.max_connections);
get_config!(inner.network.protocol.wss.listen_address);
get_config!(inner.network.protocol.wss.path);
get_config!(inner.network.protocol.wss.url);
2022-11-16 12:49:53 -05:00
Ok(())
})
}
2023-09-18 15:22:40 -04:00
pub fn get_veilid_state(&self) -> Box<VeilidStateConfig> {
2022-11-16 12:49:53 -05:00
let inner = self.inner.read();
2023-09-18 15:22:40 -04:00
Box::new(VeilidStateConfig {
2022-11-16 12:49:53 -05:00
config: inner.clone(),
2023-09-18 15:22:40 -04:00
})
2021-11-22 11:28:30 -05:00
}
pub fn get(&self) -> RwLockReadGuard<VeilidConfigInner> {
self.inner.read()
}
fn safe_config_inner(&self) -> VeilidConfigInner {
2023-03-03 10:55:31 -05:00
let mut safe_cfg = self.inner.read().clone();
// Remove secrets
safe_cfg.network.routing_table.node_id_secret = TypedSecretGroup::new();
2023-05-29 15:24:57 -04:00
safe_cfg.protected_store.device_encryption_key_password = "".to_owned();
safe_cfg.protected_store.new_device_encryption_key_password = None;
2023-03-03 10:55:31 -05:00
safe_cfg
}
pub fn safe_config(&self) -> VeilidConfig {
let mut safe_cfg = self.inner.read().clone();
// Remove secrets
safe_cfg.network.routing_table.node_id_secret = TypedSecretGroup::new();
safe_cfg.protected_store.device_encryption_key_password = "".to_owned();
safe_cfg.protected_store.new_device_encryption_key_password = None;
VeilidConfig {
update_cb: self.update_cb.clone(),
inner: Arc::new(RwLock::new(safe_cfg)),
}
}
2023-05-29 15:24:57 -04:00
pub fn with_mut<F, R>(&self, f: F) -> VeilidAPIResult<R>
2022-11-16 12:49:53 -05:00
where
2023-05-29 15:24:57 -04:00
F: FnOnce(&mut VeilidConfigInner) -> VeilidAPIResult<R>,
2022-11-16 12:49:53 -05:00
{
2023-03-03 10:55:31 -05:00
let out = {
2022-11-16 12:49:53 -05:00
let inner = &mut *self.inner.write();
// Edit a copy
let mut editedinner = inner.clone();
// Make changes
let out = f(&mut editedinner)?;
// Validate
2023-09-18 15:22:40 -04:00
Self::validate(&editedinner)?;
2023-06-07 17:39:10 -04:00
// See if things have changed
if *inner == editedinner {
// No changes, return early
return Ok(out);
}
2022-11-16 12:49:53 -05:00
// Commit changes
*inner = editedinner.clone();
2023-03-03 10:55:31 -05:00
out
2022-11-16 12:49:53 -05:00
};
// Send configuration update to clients
if let Some(update_cb) = &self.update_cb {
let safe_cfg = self.safe_config_inner();
2023-09-18 15:22:40 -04:00
update_cb(VeilidUpdate::Config(Box::new(VeilidStateConfig {
config: safe_cfg,
})));
2022-11-16 12:49:53 -05:00
}
Ok(out)
2022-03-08 22:32:12 -05:00
}
pub fn get_key_json(&self, key: &str, pretty: bool) -> VeilidAPIResult<String> {
2022-03-08 22:32:12 -05:00
let c = self.get();
// Generate json from whole config
2022-07-06 23:15:51 -04:00
let jc = serde_json::to_string(&*c).map_err(VeilidAPIError::generic)?;
let jvc = json::parse(&jc).map_err(VeilidAPIError::generic)?;
2022-03-08 22:32:12 -05:00
// Find requested subkey
2022-03-10 09:51:53 -05:00
if key.is_empty() {
Ok(if pretty {
jvc.pretty(2)
} else {
jvc.to_string()
})
2022-03-10 09:51:53 -05:00
} else {
// Split key into path parts
let keypath: Vec<&str> = key.split('.').collect();
let mut out = &jvc;
for k in keypath {
if !out.has_key(k) {
2022-11-26 14:16:02 -05:00
apibail_parse_error!(format!("invalid subkey in key '{}'", key), k);
2022-03-10 09:51:53 -05:00
}
out = &out[k];
2022-03-08 22:32:12 -05:00
}
Ok(if pretty {
out.pretty(2)
} else {
out.to_string()
})
2022-03-08 22:32:12 -05:00
}
}
2023-05-29 15:24:57 -04:00
pub fn set_key_json(&self, key: &str, value: &str) -> VeilidAPIResult<()> {
2022-11-16 12:49:53 -05:00
self.with_mut(|c| {
// Split key into path parts
let keypath: Vec<&str> = key.split('.').collect();
2022-03-08 22:32:12 -05:00
2022-11-16 12:49:53 -05:00
// Convert value into jsonvalue
let newval = json::parse(value).map_err(VeilidAPIError::generic)?;
// Generate json from whole config
let jc = serde_json::to_string(&*c).map_err(VeilidAPIError::generic)?;
let mut jvc = json::parse(&jc).map_err(VeilidAPIError::generic)?;
// Find requested subkey
let newconfigstring = if let Some((objkeyname, objkeypath)) = keypath.split_last() {
// Replace subkey
let mut out = &mut jvc;
for k in objkeypath {
2023-09-18 15:22:40 -04:00
if !out.has_key(k) {
2022-11-26 14:16:02 -05:00
apibail_parse_error!(format!("invalid subkey in key '{}'", key), k);
2022-11-16 12:49:53 -05:00
}
out = &mut out[*k];
2022-03-08 22:32:12 -05:00
}
2022-11-16 12:49:53 -05:00
if !out.has_key(objkeyname) {
2022-11-26 14:16:02 -05:00
apibail_parse_error!(format!("invalid subkey in key '{}'", key), objkeyname);
2022-11-16 12:49:53 -05:00
}
out[*objkeyname] = newval;
jvc.to_string()
} else {
newval.to_string()
};
2022-03-08 22:32:12 -05:00
2022-11-16 12:49:53 -05:00
// Generate new config
*c = serde_json::from_str(&newconfigstring).map_err(VeilidAPIError::generic)?;
Ok(())
})
}
2022-01-08 23:33:25 -05:00
2023-05-29 15:24:57 -04:00
fn validate(inner: &VeilidConfigInner) -> VeilidAPIResult<()> {
2022-01-08 23:33:25 -05:00
if inner.program_name.is_empty() {
2022-07-06 23:15:51 -04:00
apibail_generic!("Program name must not be empty in 'program_name'");
2022-01-08 23:33:25 -05:00
}
2021-12-09 16:27:17 -05:00
// if inner.network.protocol.udp.enabled {
// // Validate UDP settings
// }
if inner.network.protocol.tcp.listen {
// Validate TCP settings
if inner.network.protocol.tcp.max_connections == 0 {
2022-07-06 23:15:51 -04:00
apibail_generic!("TCP max connections must be > 0 in config key 'network.protocol.tcp.max_connections'");
}
}
if inner.network.protocol.ws.listen {
// Validate WS settings
if inner.network.protocol.ws.max_connections == 0 {
2022-07-06 23:15:51 -04:00
apibail_generic!("WS max connections must be > 0 in config key 'network.protocol.ws.max_connections'");
}
if inner.network.application.https.enabled
&& inner.network.application.https.path == inner.network.protocol.ws.path
{
2022-07-06 23:15:51 -04:00
apibail_generic!("WS path conflicts with HTTPS application path in config key 'network.protocol.ws.path'");
}
if inner.network.application.http.enabled
&& inner.network.application.http.path == inner.network.protocol.ws.path
{
2022-07-06 23:15:51 -04:00
apibail_generic!("WS path conflicts with HTTP application path in config key 'network.protocol.ws.path'");
}
}
if inner.network.protocol.wss.listen {
// Validate WSS settings
if inner.network.protocol.wss.max_connections == 0 {
2022-07-06 23:15:51 -04:00
apibail_generic!("WSS max connections must be > 0 in config key 'network.protocol.wss.max_connections'");
}
if inner
.network
.protocol
.wss
.url
.as_ref()
.map(|u| u.is_empty())
.unwrap_or_default()
{
2022-07-06 23:15:51 -04:00
apibail_generic!(
"WSS URL must be specified in config key 'network.protocol.wss.url'"
);
}
if inner.network.application.https.enabled
&& inner.network.application.https.path == inner.network.protocol.wss.path
{
2022-07-06 23:15:51 -04:00
apibail_generic!("WSS path conflicts with HTTPS application path in config key 'network.protocol.ws.path'");
}
if inner.network.application.http.enabled
&& inner.network.application.http.path == inner.network.protocol.wss.path
{
2022-07-06 23:15:51 -04:00
apibail_generic!("WSS path conflicts with HTTP application path in config key 'network.protocol.ws.path'");
}
}
if inner.network.application.https.enabled {
// Validate HTTPS settings
if inner
.network
.application
.https
.url
.as_ref()
.map(|u| u.is_empty())
.unwrap_or_default()
{
2022-07-06 23:15:51 -04:00
apibail_generic!(
"HTTPS URL must be specified in config key 'network.application.https.url'"
);
}
}
2022-10-13 22:05:43 -04:00
if inner.network.rpc.max_route_hop_count == 0 {
apibail_generic!(
"max route hop count must be >= 1 in 'network.rpc.max_route_hop_count'"
);
}
2022-10-16 19:59:59 -04:00
if inner.network.rpc.max_route_hop_count > 5 {
2022-10-13 22:05:43 -04:00
apibail_generic!(
2022-10-16 19:59:59 -04:00
"max route hop count must be <= 5 in 'network.rpc.max_route_hop_count'"
2022-10-13 22:05:43 -04:00
);
}
if inner.network.rpc.default_route_hop_count == 0 {
apibail_generic!(
"default route hop count must be >= 1 in 'network.rpc.default_route_hop_count'"
);
}
if inner.network.rpc.default_route_hop_count > inner.network.rpc.max_route_hop_count {
apibail_generic!(
"default route hop count must be <= max route hop count in 'network.rpc.default_route_hop_count <= network.rpc.max_route_hop_count'"
);
}
if inner.network.rpc.queue_size < 256 {
apibail_generic!("rpc queue size must be >= 256 in 'network.rpc.queue_size'");
}
if inner.network.rpc.timeout_ms < 1000 {
apibail_generic!("rpc timeout must be >= 1000 in 'network.rpc.timeout_ms'");
}
Ok(())
}
2023-03-13 16:14:31 -04:00
#[cfg(not(test))]
async fn init_node_id(
&self,
vcrypto: CryptoSystemVersion,
2023-05-29 15:24:57 -04:00
table_store: TableStore,
) -> VeilidAPIResult<(TypedKey, TypedSecret)> {
2023-03-13 16:14:31 -04:00
let ck = vcrypto.kind();
let mut node_id = self.inner.read().network.routing_table.node_id.get(ck);
let mut node_id_secret = self
.inner
.read()
.network
.routing_table
.node_id_secret
.get(ck);
2023-05-29 15:24:57 -04:00
// See if node id was previously stored in the table store
let config_table = table_store.open("__veilid_config", 1).await?;
let table_key_node_id = format!("node_id_{}", ck);
let table_key_node_id_secret = format!("node_id_secret_{}", ck);
2023-03-13 16:14:31 -04:00
if node_id.is_none() {
2023-05-29 15:24:57 -04:00
debug!("pulling {} from storage", table_key_node_id);
if let Ok(Some(stored_node_id)) = config_table
.load_json::<TypedKey>(0, table_key_node_id.as_bytes())
2023-03-13 16:14:31 -04:00
.await
{
2023-05-29 15:24:57 -04:00
debug!("{} found in storage", table_key_node_id);
node_id = Some(stored_node_id);
2023-03-13 16:14:31 -04:00
} else {
2023-05-29 15:24:57 -04:00
debug!("{} not found in storage", table_key_node_id);
2023-03-13 16:14:31 -04:00
}
}
// See if node id secret was previously stored in the protected store
if node_id_secret.is_none() {
2023-05-29 15:24:57 -04:00
debug!("pulling {} from storage", table_key_node_id_secret);
if let Ok(Some(stored_node_id_secret)) = config_table
.load_json::<TypedSecret>(0, table_key_node_id_secret.as_bytes())
2023-03-13 16:14:31 -04:00
.await
{
2023-05-29 15:24:57 -04:00
debug!("{} found in storage", table_key_node_id_secret);
node_id_secret = Some(stored_node_id_secret);
2023-03-13 16:14:31 -04:00
} else {
2023-05-29 15:24:57 -04:00
debug!("{} not found in storage", table_key_node_id_secret);
2023-03-13 16:14:31 -04:00
}
}
// If we have a node id from storage, check it
let (node_id, node_id_secret) =
if let (Some(node_id), Some(node_id_secret)) = (node_id, node_id_secret) {
// Validate node id
if !vcrypto.validate_keypair(&node_id.value, &node_id_secret.value) {
apibail_generic!(format!(
"node_id_secret_{} and node_id_key_{} don't match",
ck, ck
));
}
(node_id, node_id_secret)
} else {
// If we still don't have a valid node id, generate one
debug!("generating new node_id_{}", ck);
let kp = vcrypto.generate_keypair();
(TypedKey::new(ck, kp.key), TypedSecret::new(ck, kp.secret))
};
info!("Node Id: {}", node_id);
// Save the node id / secret in storage
2023-05-29 15:24:57 -04:00
config_table
.store_json(0, table_key_node_id.as_bytes(), &node_id)
.await?;
config_table
.store_json(0, table_key_node_id_secret.as_bytes(), &node_id_secret)
.await?;
2023-03-13 16:14:31 -04:00
Ok((node_id, node_id_secret))
}
/// Get the node id from config if one is specified
/// Must be done -after- protected store startup
#[cfg_attr(test, allow(unused_variables))]
2023-02-07 21:44:50 -05:00
pub async fn init_node_ids(
2022-07-06 23:15:51 -04:00
&self,
2023-02-07 21:44:50 -05:00
crypto: Crypto,
2023-05-29 15:24:57 -04:00
table_store: TableStore,
) -> VeilidAPIResult<()> {
let mut out_node_id = TypedKeyGroup::new();
let mut out_node_id_secret = TypedSecretGroup::new();
2023-03-03 10:55:31 -05:00
2023-02-07 21:44:50 -05:00
for ck in VALID_CRYPTO_KINDS {
2023-02-08 16:50:07 -05:00
let vcrypto = crypto
.get(ck)
.expect("Valid crypto kind is not actually valid.");
2021-11-22 11:28:30 -05:00
2023-03-13 16:14:31 -04:00
#[cfg(test)]
let (node_id, node_id_secret) = {
let kp = vcrypto.generate_keypair();
(TypedKey::new(ck, kp.key), TypedSecret::new(ck, kp.secret))
};
#[cfg(not(test))]
2023-05-29 15:24:57 -04:00
let (node_id, node_id_secret) = self.init_node_id(vcrypto, table_store.clone()).await?;
2021-11-22 11:28:30 -05:00
2023-03-03 10:55:31 -05:00
// Save for config
out_node_id.add(node_id);
out_node_id_secret.add(node_id_secret);
2023-02-07 21:44:50 -05:00
}
2023-03-03 10:55:31 -05:00
// Commit back to config
self.with_mut(|c| {
c.network.routing_table.node_id = out_node_id;
c.network.routing_table.node_id_secret = out_node_id_secret;
Ok(())
})?;
2023-02-08 16:50:07 -05:00
trace!("init_node_ids complete");
2021-11-22 11:28:30 -05:00
Ok(())
}
}