From ed9ee2734056e99ffa2c6cfffd26f2ec7e61c301 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Tue, 4 Feb 2020 13:18:00 +0000 Subject: [PATCH] Uncommited mixnode persitance module --- mixnode/src/config/persistance/mod.rs | 1 + mixnode/src/config/persistance/pathfinder.rs | 56 ++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 mixnode/src/config/persistance/mod.rs create mode 100644 mixnode/src/config/persistance/pathfinder.rs diff --git a/mixnode/src/config/persistance/mod.rs b/mixnode/src/config/persistance/mod.rs new file mode 100644 index 0000000000..5692e9bc8b --- /dev/null +++ b/mixnode/src/config/persistance/mod.rs @@ -0,0 +1 @@ +pub mod pathfinder; diff --git a/mixnode/src/config/persistance/pathfinder.rs b/mixnode/src/config/persistance/pathfinder.rs new file mode 100644 index 0000000000..d4bfe9da5e --- /dev/null +++ b/mixnode/src/config/persistance/pathfinder.rs @@ -0,0 +1,56 @@ +use crate::config::Config; +use pemstore::pathfinder::PathFinder; +use std::path::PathBuf; + +#[derive(Debug)] +pub struct MixNodePathfinder { + pub config_dir: PathBuf, + pub private_sphinx_key: PathBuf, + pub public_sphinx_key: PathBuf, +} + +impl MixNodePathfinder { + pub fn new(id: String) -> Self { + let os_config_dir = dirs::config_dir().unwrap(); // grabs the OS default config dir + let config_dir = os_config_dir.join("nym").join("mixnodes").join(id); + let private_sphinx_key = config_dir.join("private.pem"); + let public_sphinx_key = config_dir.join("public.pem"); + MixNodePathfinder { + config_dir, + private_sphinx_key, + public_sphinx_key, + } + } + + pub fn new_from_config(config: &Config) -> Self { + MixNodePathfinder { + config_dir: config.get_config_file_save_location(), + private_sphinx_key: config.get_private_sphinx_key_file(), + public_sphinx_key: config.get_public_sphinx_key_file(), + } + } +} + +impl PathFinder for MixNodePathfinder { + fn config_dir(&self) -> PathBuf { + self.config_dir.clone() + } + + fn private_identity_key(&self) -> PathBuf { + // TEMPORARILY USE SAME KEYS AS ENCRYPTION + self.private_sphinx_key.clone() + } + + fn public_identity_key(&self) -> PathBuf { + // TEMPORARILY USE SAME KEYS AS ENCRYPTION + self.public_sphinx_key.clone() + } + + fn private_encryption_key(&self) -> Option { + Some(self.private_sphinx_key.clone()) + } + + fn public_encryption_key(&self) -> Option { + Some(self.public_sphinx_key.clone()) + } +}