Skip to content

Commit c3e18ce

Browse files
authored
Feature/load keys on run (#220)
* Mixnode keys loaded in run command * Client keys loaded in run command * Removed unused imports
1 parent fe17bda commit c3e18ce

File tree

4 files changed

+35
-36
lines changed

4 files changed

+35
-36
lines changed

clients/desktop/src/client/mod.rs

+1-16
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use crate::client::received_buffer::{
2020
use crate::client::topology_control::{
2121
TopologyAccessor, TopologyRefresher, TopologyRefresherConfig,
2222
};
23-
use crate::config::persistence::pathfinder::ClientPathfinder;
2423
use crate::config::{Config, SocketType};
2524
use crate::websocket;
2625
use crypto::identity::MixIdentityKeyPair;
@@ -31,7 +30,6 @@ use gateway_requests::auth_token::AuthToken;
3130
use log::*;
3231
use nymsphinx::chunking::split_and_prepare_payloads;
3332
use nymsphinx::{Destination, DestinationAddressBytes};
34-
use pemstore::pemstore::PemStore;
3533
use received_buffer::{ReceivedBufferMessage, ReconstructeredMessagesReceiver};
3634
use tokio::runtime::Runtime;
3735
use topology::NymTopology;
@@ -63,20 +61,7 @@ pub struct NymClient {
6361
pub(crate) struct InputMessage(pub Destination, pub Vec<u8>);
6462

6563
impl NymClient {
66-
fn load_identity_keys(config_file: &Config) -> MixIdentityKeyPair {
67-
let identity_keypair = PemStore::new(ClientPathfinder::new_from_config(&config_file))
68-
.read_identity()
69-
.expect("Failed to read stored identity key files");
70-
println!(
71-
"Public identity key: {}\n",
72-
identity_keypair.public_key.to_base58_string()
73-
);
74-
identity_keypair
75-
}
76-
77-
pub fn new(config: Config) -> Self {
78-
let identity_keypair = Self::load_identity_keys(&config);
79-
64+
pub fn new(config: Config, identity_keypair: MixIdentityKeyPair) -> Self {
8065
NymClient {
8166
runtime: Runtime::new().unwrap(),
8267
config,

clients/desktop/src/commands/run.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414

1515
use crate::client::NymClient;
1616
use crate::commands::override_config;
17-
use crate::config::Config;
17+
use crate::config::{persistence::pathfinder::ClientPathfinder, Config};
1818
use clap::{App, Arg, ArgMatches};
1919
use config::NymConfig;
20+
use crypto::identity::MixIdentityKeyPair;
21+
use pemstore::pemstore::PemStore;
2022

2123
pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> {
2224
App::new("run")
@@ -55,6 +57,17 @@ pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> {
5557
)
5658
}
5759

60+
fn load_identity_keys(config_file: &Config) -> MixIdentityKeyPair {
61+
let identity_keypair = PemStore::new(ClientPathfinder::new_from_config(&config_file))
62+
.read_identity()
63+
.expect("Failed to read stored identity key files");
64+
println!(
65+
"Public identity key: {}\n",
66+
identity_keypair.public_key.to_base58_string()
67+
);
68+
identity_keypair
69+
}
70+
5871
pub fn execute(matches: &ArgMatches) {
5972
let id = matches.value_of("id").unwrap();
6073

@@ -63,5 +76,6 @@ pub fn execute(matches: &ArgMatches) {
6376
.expect("Failed to load config file");
6477

6578
config = override_config(config, matches);
66-
NymClient::new(config).run_forever();
79+
let identity_keypair = load_identity_keys(&config);
80+
NymClient::new(config, identity_keypair).run_forever();
6781
}

mixnode/src/commands/run.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
// limitations under the License.
1414

1515
use crate::commands::override_config;
16-
use crate::config::Config;
16+
use crate::config::{persistence::pathfinder::MixNodePathfinder, Config};
1717
use crate::node::MixNode;
1818
use clap::{App, Arg, ArgMatches};
1919
use config::NymConfig;
20+
use crypto::encryption;
21+
use pemstore::pemstore::PemStore;
2022

2123
pub fn command_args<'a, 'b>() -> App<'a, 'b> {
2224
App::new("run")
@@ -94,6 +96,17 @@ fn special_addresses() -> Vec<&'static str> {
9496
vec!["localhost", "127.0.0.1", "0.0.0.0", "::1", "[::1]"]
9597
}
9698

99+
fn load_sphinx_keys(config_file: &Config) -> encryption::KeyPair {
100+
let sphinx_keypair = PemStore::new(MixNodePathfinder::new_from_config(&config_file))
101+
.read_encryption()
102+
.expect("Failed to read stored sphinx key files");
103+
println!(
104+
"Public key: {}\n",
105+
sphinx_keypair.public_key().to_base58_string()
106+
);
107+
sphinx_keypair
108+
}
109+
97110
pub fn execute(matches: &ArgMatches) {
98111
let id = matches.value_of("id").unwrap();
99112

@@ -105,6 +118,8 @@ pub fn execute(matches: &ArgMatches) {
105118

106119
config = override_config(config, matches);
107120

121+
let sphinx_keypair = load_sphinx_keys(&config);
122+
108123
let listening_ip_string = config.get_listening_address().ip().to_string();
109124
if special_addresses().contains(&listening_ip_string.as_ref()) {
110125
show_binding_warning(listening_ip_string);
@@ -128,5 +143,5 @@ pub fn execute(matches: &ArgMatches) {
128143
config.get_announce_address()
129144
);
130145

131-
MixNode::new(config).run();
146+
MixNode::new(config, sphinx_keypair).run();
132147
}

mixnode/src/node/mod.rs

+1-16
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use crate::config::persistence::pathfinder::MixNodePathfinder;
1615
use crate::config::Config;
1716
use crate::node::packet_processing::PacketProcessor;
1817
use crypto::encryption;
1918
use directory_client::presence::Topology;
2019
use futures::channel::mpsc;
2120
use log::*;
22-
use pemstore::pemstore::PemStore;
2321
use std::net::SocketAddr;
2422
use tokio::runtime::Runtime;
2523
use topology::NymTopology;
@@ -38,20 +36,7 @@ pub struct MixNode {
3836
}
3937

4038
impl MixNode {
41-
fn load_sphinx_keys(config_file: &Config) -> encryption::KeyPair {
42-
let sphinx_keypair = PemStore::new(MixNodePathfinder::new_from_config(&config_file))
43-
.read_encryption()
44-
.expect("Failed to read stored sphinx key files");
45-
println!(
46-
"Public key: {}\n",
47-
sphinx_keypair.public_key().to_base58_string()
48-
);
49-
sphinx_keypair
50-
}
51-
52-
pub fn new(config: Config) -> Self {
53-
let sphinx_keypair = Self::load_sphinx_keys(&config);
54-
39+
pub fn new(config: Config, sphinx_keypair: encryption::KeyPair) -> Self {
5540
MixNode {
5641
runtime: Runtime::new().unwrap(),
5742
config,

0 commit comments

Comments
 (0)