renamed paths to storage_paths and fixed mixnode template

This commit is contained in:
Jędrzej Stuczyński
2023-05-26 17:08:19 +01:00
parent e0e5317b44
commit edc404d6d7
25 changed files with 92 additions and 98 deletions
+2 -2
View File
@@ -74,7 +74,7 @@ pub struct Config {
pub socket: Socket,
// pub paths: CommonClientPathfinder,
pub paths: ClientPaths,
pub storage_paths: ClientPaths,
pub logging: LoggingSettings,
}
@@ -89,7 +89,7 @@ impl Config {
pub fn new<S: AsRef<str>>(id: S) -> Self {
Config {
base: BaseClientConfig::new(id.as_ref()),
paths: ClientPaths::new_default(default_data_directory(id.as_ref())),
storage_paths: ClientPaths::new_default(default_data_directory(id.as_ref())),
logging: Default::default(),
socket: Default::default(),
}
+7 -3
View File
@@ -50,7 +50,7 @@ impl SocketClient {
config: &Config,
) -> BandwidthController<Client<QueryNyxdClient>, PersistentStorage> {
let storage = nym_credential_storage::initialise_persistent_storage(
&config.paths.common_paths.credentials_database,
&config.storage_paths.common_paths.credentials_database,
)
.await;
@@ -107,7 +107,7 @@ impl SocketClient {
}
fn key_store(&self) -> OnDiskKeys {
OnDiskKeys::new(self.config.paths.common_paths.keys_paths.clone())
OnDiskKeys::new(self.config.storage_paths.common_paths.keys_paths.clone())
}
// TODO: see if this could also be shared with socks5 client / nym-sdk maybe
@@ -124,7 +124,11 @@ impl SocketClient {
self.key_store(),
bandwidth_controller,
non_wasm_helpers::setup_fs_reply_surb_backend(
&self.config.paths.common_paths.reply_surb_database_path,
&self
.config
.storage_paths
.common_paths
.reply_surb_database_path,
&self.config.base.debug.reply_surbs,
)
.await?,
+2 -2
View File
@@ -163,7 +163,7 @@ pub(crate) async fn execute(args: &Init) -> Result<(), ClientError> {
// Setup gateway by either registering a new one, or creating a new config from the selected
// one but with keys kept, or reusing the gateway configuration.
let key_store = OnDiskKeys::new(config.paths.common_paths.keys_paths.clone());
let key_store = OnDiskKeys::new(config.storage_paths.common_paths.keys_paths.clone());
let gateway = nym_client_core::init::setup_gateway_from_config::<_>(
&key_store,
register_gateway,
@@ -186,7 +186,7 @@ pub(crate) async fn execute(args: &Init) -> Result<(), ClientError> {
);
let address = nym_client_core::init::get_client_address_from_stored_ondisk_keys(
&config.paths.common_paths.keys_paths,
&config.storage_paths.common_paths.keys_paths,
&config.base.client.gateway_endpoint,
)?;
+2 -2
View File
@@ -169,7 +169,7 @@ pub(crate) async fn execute(args: &Init) -> Result<(), Socks5ClientError> {
// Setup gateway by either registering a new one, or creating a new config from the selected
// one but with keys kept, or reusing the gateway configuration.
let key_store = OnDiskKeys::new(config.paths.common_paths.keys_paths.clone());
let key_store = OnDiskKeys::new(config.storage_paths.common_paths.keys_paths.clone());
let gateway = nym_client_core::init::setup_gateway_from_config::<_>(
&key_store,
register_gateway,
@@ -194,7 +194,7 @@ pub(crate) async fn execute(args: &Init) -> Result<(), Socks5ClientError> {
);
let address = nym_client_core::init::get_client_address_from_stored_ondisk_keys(
&config.paths.common_paths.keys_paths,
&config.storage_paths.common_paths.keys_paths,
&config.core.base.client.gateway_endpoint,
)?;
let init_results = InitResults::new(&config, &address);
+1 -1
View File
@@ -140,6 +140,6 @@ pub(crate) async fn execute(args: &Run) -> Result<(), Box<dyn std::error::Error
}
let storage =
OnDiskPersistent::from_paths(config.paths.common_paths, &config.core.base.debug).await?;
OnDiskPersistent::from_paths(config.storage_paths.common_paths, &config.core.base.debug).await?;
NymClient::new(config.core, storage).run_forever().await
}
+2 -2
View File
@@ -54,7 +54,7 @@ pub struct Config {
#[serde(flatten)]
pub core: CoreConfig,
pub paths: SocksClientPaths,
pub storage_paths: SocksClientPaths,
pub logging: LoggingSettings,
}
@@ -69,7 +69,7 @@ impl Config {
pub fn new<S: AsRef<str>>(id: S, provider_mix_address: S) -> Self {
Config {
core: CoreConfig::new(id.as_ref(), provider_mix_address.as_ref()),
paths: SocksClientPaths::new_default(default_data_directory(id.as_ref())),
storage_paths: SocksClientPaths::new_default(default_data_directory(id.as_ref())),
logging: Default::default(),
}
}
+6 -5
View File
@@ -44,11 +44,12 @@ pub trait NymConfigTemplate: Serialize {
if let Err(err) =
Handlebars::new().render_template_to_write(Self::template(), &self, writer)
{
if let TemplateRenderError::IOError(err, _) = err {
return Err(err);
} else {
// it is responsibility of whoever is implementing the trait to ensure the template is valid
panic!("invalid template")
match err {
TemplateRenderError::IOError(err, _) => return Err(err),
other_err => {
// it is responsibility of whoever is implementing the trait to ensure the template is valid
panic!("invalid template: {other_err}")
}
}
}
+4 -4
View File
@@ -127,8 +127,8 @@ pub async fn execute(args: Init) -> Result<(), Box<dyn Error + Send + Sync>> {
nym_pemstore::store_keypair(
&identity_keys,
&nym_pemstore::KeyPairPath::new(
config.paths.private_identity_key(),
config.paths.public_identity_key(),
config.storage_paths.private_identity_key(),
config.storage_paths.public_identity_key(),
),
)
.expect("Failed to save identity keys");
@@ -136,8 +136,8 @@ pub async fn execute(args: Init) -> Result<(), Box<dyn Error + Send + Sync>> {
nym_pemstore::store_keypair(
&sphinx_keys,
&nym_pemstore::KeyPairPath::new(
config.paths.private_encryption_key(),
config.paths.public_encryption_key(),
config.storage_paths.private_encryption_key(),
config.storage_paths.public_encryption_key(),
),
)
.expect("Failed to save sphinx keys");
+3 -3
View File
@@ -66,7 +66,7 @@ pub fn default_data_directory<P: AsRef<Path>>(id: P) -> PathBuf {
pub struct Config {
pub gateway: Gateway,
pub paths: GatewayPaths,
pub storage_paths: GatewayPaths,
#[serde(default)]
pub logging: LoggingSettings,
@@ -85,7 +85,7 @@ impl Config {
pub fn new<S: AsRef<str>>(id: S) -> Self {
Config {
gateway: Gateway::new_default(id.as_ref()),
paths: GatewayPaths::new_default(id.as_ref()),
storage_paths: GatewayPaths::new_default(id.as_ref()),
logging: Default::default(),
debug: Default::default(),
}
@@ -154,7 +154,7 @@ impl Config {
}
pub fn with_custom_persistent_store(mut self, store_dir: PathBuf) -> Self {
self.paths.clients_storage = store_dir;
self.storage_paths.clients_storage = store_dir;
self
}
+6 -6
View File
@@ -37,7 +37,7 @@ pub(crate) async fn create_gateway(config: Config) -> Gateway<PersistentStorage>
}
async fn initialise_storage(config: &Config) -> PersistentStorage {
let path = &config.paths.clients_storage;
let path = &config.storage_paths.clients_storage;
let retrieval_limit = config.debug.message_retrieval_limit;
match PersistentStorage::init(path, retrieval_limit).await {
Err(err) => panic!("failed to initialise gateway storage: {err}"),
@@ -84,8 +84,8 @@ impl<St> Gateway<St> {
pub(crate) fn load_identity_keys(config: &Config) -> identity::KeyPair {
let identity_keypair: identity::KeyPair =
nym_pemstore::load_keypair(&nym_pemstore::KeyPairPath::new(
config.paths.keys.private_identity_key(),
config.paths.keys.public_identity_key(),
config.storage_paths.keys.private_identity_key(),
config.storage_paths.keys.public_identity_key(),
))
.expect("Failed to read stored identity key files");
identity_keypair
@@ -95,8 +95,8 @@ impl<St> Gateway<St> {
fn load_sphinx_keys(config: &Config) -> encryption::KeyPair {
let sphinx_keypair: encryption::KeyPair =
nym_pemstore::load_keypair(&nym_pemstore::KeyPairPath::new(
config.paths.keys.private_encryption_key(),
config.paths.keys.public_encryption_key(),
config.storage_paths.keys.private_encryption_key(),
config.storage_paths.keys.public_encryption_key(),
))
.expect("Failed to read stored sphinx key files");
sphinx_keypair
@@ -110,7 +110,7 @@ impl<St> Gateway<St> {
version: self.config.gateway.version.clone(),
mix_port: self.config.gateway.mix_port,
clients_port: self.config.gateway.clients_port,
data_store: self.config.paths.clients_storage.display().to_string(),
data_store: self.config.storage_paths.clients_storage.display().to_string(),
};
println!("{}", output.format(&node_details));
+1 -1
View File
@@ -80,5 +80,5 @@ pub(crate) fn execute(args: Describe) {
};
// save the struct
NodeDescription::save_to_file(&node_description, config.paths.node_description).unwrap()
NodeDescription::save_to_file(&node_description, config.storage_paths.node_description).unwrap()
}
+4 -4
View File
@@ -88,8 +88,8 @@ pub(crate) fn execute(args: &Init) {
nym_pemstore::store_keypair(
&identity_keys,
&nym_pemstore::KeyPairPath::new(
config.paths.private_identity_key(),
config.paths.public_identity_key(),
config.storage_paths.private_identity_key(),
config.storage_paths.public_identity_key(),
),
)
.expect("Failed to save identity keys");
@@ -97,8 +97,8 @@ pub(crate) fn execute(args: &Init) {
nym_pemstore::store_keypair(
&sphinx_keys,
&nym_pemstore::KeyPairPath::new(
config.paths.private_encryption_key(),
config.paths.public_encryption_key(),
config.storage_paths.private_encryption_key(),
config.storage_paths.public_encryption_key(),
),
)
.expect("Failed to save sphinx keys");
+2 -2
View File
@@ -74,7 +74,7 @@ pub fn default_data_directory<P: AsRef<Path>>(id: P) -> PathBuf {
pub struct Config {
pub mixnode: MixNode,
pub paths: MixNodePaths,
pub storage_paths: MixNodePaths,
#[serde(default)]
pub verloc: Verloc,
@@ -96,7 +96,7 @@ impl Config {
pub fn new<S: AsRef<str>>(id: S) -> Self {
Config {
mixnode: MixNode::new_default(id.as_ref()),
paths: MixNodePaths::new_default(id.as_ref()),
storage_paths: MixNodePaths::new_default(id.as_ref()),
verloc: Default::default(),
logging: Default::default(),
debug: Default::default(),
+13 -24
View File
@@ -21,25 +21,6 @@ id = '{{ mixnode.id }}'
# Socket address to which this mixnode will bind to and will be listening for packets.
listening_address = '{{ mixnode.listening_address }}'
# Path to file containing private identity key.
private_identity_key_file = '{{ mixnode.private_identity_key_file }}'
# Path to file containing public identity key.
public_identity_key_file = '{{ mixnode.public_identity_key_file }}'
# Path to file containing private identity key.
private_sphinx_key_file = '{{ mixnode.private_sphinx_key_file }}'
# Path to file containing public sphinx key.
public_sphinx_key_file = '{{ mixnode.public_sphinx_key_file }}'
##### additional mixnode config options #####
# Optional address announced to the directory server for the clients to connect to.
# It is useful, say, in NAT scenarios or wanting to more easily update actual IP address
# later on by using name resolvable with a DNS query, such as `nymtech.net`.
announce_address = '{{ mixnode.announce_address }}'
# Port used for listening for all mixnet traffic.
# (default: 1789)
mix_port = {{ mixnode.mix_port }}
@@ -59,14 +40,22 @@ nym_api_urls = [
{{/each}}
]
# Nym wallet address on the blockchain that should control this mixnode
wallet_address = '{{ mixnode.wallet_address }}'
[storage_paths]
##### advanced configuration options #####
# Path to file containing private identity key.
keys.private_identity_key_file = '{{ storage_paths.keys.private_identity_key_file }}'
# Absolute path to the home Nym Clients directory.
nym_root_directory = '{{ mixnode.nym_root_directory }}'
# Path to file containing public identity key.
keys.public_identity_key_file = '{{ storage_paths.keys.public_identity_key_file }}'
# Path to file containing private identity key.
keys.private_sphinx_key_file = '{{ storage_paths.keys.private_sphinx_key_file }}'
# Path to file containing public sphinx key.
keys.public_sphinx_key_file = '{{ storage_paths.keys.public_sphinx_key_file }}'
# Path to file containing description of this node.
node_description = '{{ storage_paths.node_description }}'
##### logging configuration options #####
+5 -5
View File
@@ -54,15 +54,15 @@ impl MixNode {
}
fn load_node_description(config: &Config) -> NodeDescription {
NodeDescription::load_from_file(&config.paths.node_description).unwrap_or_default()
NodeDescription::load_from_file(&config.storage_paths.node_description).unwrap_or_default()
}
/// Loads identity keys stored on disk
pub(crate) fn load_identity_keys(config: &Config) -> identity::KeyPair {
let identity_keypair: identity::KeyPair =
nym_pemstore::load_keypair(&nym_pemstore::KeyPairPath::new(
config.paths.keys.private_identity_key(),
config.paths.keys.public_identity_key(),
config.storage_paths.keys.private_identity_key(),
config.storage_paths.keys.public_identity_key(),
))
.expect("Failed to read stored identity key files");
identity_keypair
@@ -72,8 +72,8 @@ impl MixNode {
fn load_sphinx_keys(config: &Config) -> encryption::KeyPair {
let sphinx_keypair: encryption::KeyPair =
nym_pemstore::load_keypair(&nym_pemstore::KeyPairPath::new(
config.paths.keys.private_encryption_key(),
config.paths.keys.public_encryption_key(),
config.storage_paths.keys.private_encryption_key(),
config.storage_paths.keys.public_encryption_key(),
))
.expect("Failed to read stored sphinx key files");
sphinx_keypair
+10 -10
View File
@@ -30,8 +30,8 @@ pub(crate) fn init_keypair(config: &config::CoconutSigner) -> Result<()> {
nym_pemstore::store_keypair(
&kp,
&nym_pemstore::KeyPairPath::new(
&config.paths.decryption_key_path,
&config.paths.public_key_with_proof_path,
&config.storage_paths.decryption_key_path,
&config.storage_paths.public_key_with_proof_path,
),
)?;
Ok(())
@@ -54,27 +54,27 @@ impl<R: RngCore + CryptoRng + Clone> DkgController<R> {
rng: R,
) -> Result<Self> {
let dkg_keypair = nym_pemstore::load_keypair(&nym_pemstore::KeyPairPath::new(
&config.paths.decryption_key_path,
&config.paths.public_key_with_proof_path,
&config.storage_paths.decryption_key_path,
&config.storage_paths.public_key_with_proof_path,
))?;
if let Ok(coconut_keypair_value) =
nym_pemstore::load_keypair(&nym_pemstore::KeyPairPath::new(
&config.paths.secret_key_path,
&config.paths.verification_key_path,
&config.storage_paths.secret_key_path,
&config.storage_paths.verification_key_path,
))
{
coconut_keypair.set(Some(coconut_keypair_value)).await;
}
let persistent_state =
PersistentState::load_from_file(&config.paths.dkg_persistent_state_path)
PersistentState::load_from_file(&config.storage_paths.dkg_persistent_state_path)
.unwrap_or_default();
Ok(DkgController {
dkg_client: DkgClient::new(nyxd_client),
secret_key_path: config.paths.secret_key_path.clone(),
verification_key_path: config.paths.verification_key_path.clone(),
secret_key_path: config.storage_paths.secret_key_path.clone(),
verification_key_path: config.storage_paths.verification_key_path.clone(),
state: State::new(
config.paths.dkg_persistent_state_path.clone(),
config.storage_paths.dkg_persistent_state_path.clone(),
persistent_state,
config.announce_address.clone(),
dkg_keypair,
+1 -1
View File
@@ -94,7 +94,7 @@ impl<'a> NetworkMonitorBuilder<'a> {
let bandwidth_controller = {
BandwidthController::new(
nym_credential_storage::initialise_persistent_storage(
&self.config.paths.credentials_database_path,
&self.config.storage_paths.credentials_database_path,
)
.await,
self.nyxd_client.clone(),
+6 -6
View File
@@ -255,7 +255,7 @@ pub struct NetworkMonitor {
pub enabled: bool,
#[serde(flatten)]
pub paths: NetworkMonitorPaths,
pub storage_paths: NetworkMonitorPaths,
#[serde(flatten)]
pub debug: NetworkMonitorDebug,
@@ -265,7 +265,7 @@ impl NetworkMonitor {
pub fn new_default<P: AsRef<Path>>(id: P) -> Self {
NetworkMonitor {
enabled: false,
paths: NetworkMonitorPaths::new_default(id),
storage_paths: NetworkMonitorPaths::new_default(id),
debug: Default::default(),
}
}
@@ -351,7 +351,7 @@ impl Default for NetworkMonitorDebug {
pub struct NodeStatusAPI {
// pub enabled: bool,
#[serde(flatten)]
pub paths: NodeStatusAPIPaths,
pub storage_paths: NodeStatusAPIPaths,
#[serde(flatten)]
pub debug: NodeStatusAPIDebug,
@@ -360,7 +360,7 @@ pub struct NodeStatusAPI {
impl NodeStatusAPI {
pub fn new_default<P: AsRef<Path>>(id: P) -> Self {
NodeStatusAPI {
paths: NodeStatusAPIPaths::new_default(id),
storage_paths: NodeStatusAPIPaths::new_default(id),
debug: Default::default(),
}
}
@@ -489,7 +489,7 @@ pub struct CoconutSigner {
pub announce_address: Url,
#[serde(flatten)]
pub paths: CoconutSignerPaths,
pub storage_paths: CoconutSignerPaths,
#[serde(flatten)]
pub debug: CoconutSignerDebug,
@@ -508,7 +508,7 @@ impl CoconutSigner {
CoconutSigner {
enabled: false,
announce_address: default_announce_address,
paths: CoconutSignerPaths::new_default(id),
storage_paths: CoconutSignerPaths::new_default(id),
debug: Default::default(),
}
}
+1 -1
View File
@@ -46,7 +46,7 @@ pub(crate) async fn setup_rocket(
// This is not a very nice approach. A lazy value would be more suitable, but that's still
// a nightly feature: https://github.com/rust-lang/rust/issues/74465
let storage = if config.coconut_signer.enabled || config.network_monitor.enabled {
Some(storage::NymApiStorage::init(&config.node_status_api.paths.database_path).await?)
Some(storage::NymApiStorage::init(&config.node_status_api.storage_paths.database_path).await?)
} else {
None
};
@@ -54,7 +54,7 @@ pub fn default_data_directory<P: AsRef<Path>>(id: P) -> PathBuf {
pub struct Config {
pub socks5: Socks5CoreConfig,
pub paths: NymConnectPaths,
pub storage_paths: NymConnectPaths,
}
impl NymConfigTemplate for Config {
@@ -71,7 +71,7 @@ impl Config {
pub fn new<S: AsRef<str>>(id: S, provider_mix_address: S) -> Self {
Config {
socks5: Socks5CoreConfig::new(id.as_ref(), provider_mix_address.as_ref()),
paths: NymConnectPaths::new_default(default_data_directory(id.as_ref())),
storage_paths: NymConnectPaths::new_default(default_data_directory(id.as_ref())),
}
}
@@ -154,7 +154,7 @@ pub async fn init_socks5_config(provider_address: String, chosen_gateway_id: Str
.map_err(|_| BackendError::UnableToParseGateway)?;
// Setup gateway by either registering a new one, or reusing exiting keys
let key_store = OnDiskKeys::new(config.paths.common_paths.keys_paths.clone());
let key_store = OnDiskKeys::new(config.storage_paths.common_paths.keys_paths.clone());
let gateway = nym_client_core::init::setup_gateway_from_config::<_>(
&key_store,
register_gateway,
@@ -175,7 +175,7 @@ pub async fn init_socks5_config(provider_address: String, chosen_gateway_id: Str
print_saved_config(&config);
let address = nym_client_core::init::get_client_address_from_stored_ondisk_keys(
&config.paths.common_paths.keys_paths,
&config.storage_paths.common_paths.keys_paths,
&config.socks5.base.client.gateway_endpoint,
)?;
log::info!("The address of this client is: {}", address);
@@ -20,7 +20,7 @@ pub async fn get_identity_key(
state.load_config()?
};
let paths = config.paths.common_paths.keys_paths;
let paths = config.storage_paths.common_paths.keys_paths;
// wtf, why are we loading EVERYTHING to just get identity key??
let key_store = OnDiskKeys::from(paths);
@@ -52,7 +52,7 @@ pub async fn export_keys(state: tauri::State<'_, Arc<RwLock<State>>>) -> Result<
state.load_config()?
};
let key_paths = config.paths.common_paths.keys_paths;
let key_paths = config.storage_paths.common_paths.keys_paths;
// Get key paths
let ack_key_file = key_paths.ack_key();
+1 -1
View File
@@ -62,7 +62,7 @@ pub fn start_nym_socks5_client(
.expect("Failed to create runtime for SOCKS5 client")
.block_on(async move {
let storage = OnDiskPersistent::from_paths(
config.paths.common_paths,
config.storage_paths.common_paths,
&config.socks5.base.debug,
)
.await?;
@@ -137,7 +137,7 @@ pub(crate) async fn execute(args: &Init) -> Result<(), NetworkRequesterError> {
// Setup gateway by either registering a new one, or creating a new config from the selected
// one but with keys kept, or reusing the gateway configuration.
let key_store = OnDiskKeys::new(config.paths.common_paths.keys_paths.clone());
let key_store = OnDiskKeys::new(config.storage_paths.common_paths.keys_paths.clone());
let gateway = nym_client_core::init::setup_gateway_from_config::<_>(
&key_store,
register_gateway,
@@ -163,7 +163,7 @@ pub(crate) async fn execute(args: &Init) -> Result<(), NetworkRequesterError> {
);
let address = nym_client_core::init::get_client_address_from_stored_ondisk_keys(
&config.paths.common_paths.keys_paths,
&config.storage_paths.common_paths.keys_paths,
&config.base.client.gateway_endpoint,
)?;
@@ -64,7 +64,7 @@ pub struct Config {
// alias due to backwards compatibility
#[serde(alias = "network_requester")]
pub paths: NetworkRequesterPaths,
pub storage_paths: NetworkRequesterPaths,
#[serde(default)]
pub network_requester_debug: Debug,
@@ -81,7 +81,7 @@ impl Config {
Config {
base: BaseClientConfig::new(id.as_ref()),
network_requester_config: Default::default(),
paths: NetworkRequesterPaths::new_default(default_data_directory(id.as_ref())),
storage_paths: NetworkRequesterPaths::new_default(default_data_directory(id.as_ref())),
network_requester_debug: Default::default(),
}
}
@@ -164,8 +164,8 @@ impl NRServiceProviderBuilder {
) -> NRServiceProviderBuilder {
let standard_list = StandardList::new();
let allowed_hosts = StoredAllowedHosts::new(&config.paths.allowed_list_location);
let unknown_hosts = allowed_hosts::HostsStore::new(&config.paths.unknown_list_location);
let allowed_hosts = StoredAllowedHosts::new(&config.storage_paths.allowed_list_location);
let unknown_hosts = allowed_hosts::HostsStore::new(&config.storage_paths.unknown_list_location);
let outbound_request_filter =
OutboundRequestFilter::new(allowed_hosts.clone(), standard_list.clone(), unknown_hosts);
@@ -185,7 +185,7 @@ impl NRServiceProviderBuilder {
pub async fn run_service_provider(self) -> Result<(), NetworkRequesterError> {
// Connect to the mixnet
let mixnet_client =
create_mixnet_client(&self.config.base, &self.config.paths.common_paths).await?;
create_mixnet_client(&self.config.base, &self.config.storage_paths.common_paths).await?;
// channels responsible for managing messages that are to be sent to the mix network. The receiver is
// going to be used by `mixnet_response_listener`