-
Notifications
You must be signed in to change notification settings - Fork 237
/
Copy pathinit.rs
172 lines (159 loc) · 6.08 KB
/
init.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Copyright 2020 Nym Technologies SA
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::commands::override_config;
use crate::config::persistence::pathfinder::GatewayPathfinder;
use crate::config::Config;
use clap::{App, Arg, ArgMatches};
use config::NymConfig;
use crypto::asymmetric::{encryption, identity};
pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> {
App::new("init")
.about("Initialise the gateway")
.arg(
Arg::with_name("id")
.long("id")
.help("Id of the gateway we want to create config for.")
.takes_value(true)
.required(true),
)
.arg(
Arg::with_name("location")
.long("location")
.help("Optional geographical location of this provider")
.takes_value(true),
)
.arg(
Arg::with_name("mix-host")
.long("mix-host")
.help("The custom host on which the gateway will be running for receiving sphinx packets")
.takes_value(true)
.required(true),
)
.arg(
Arg::with_name("mix-port")
.long("mix-port")
.help("The port on which the gateway will be listening for sphinx packets")
.takes_value(true)
)
.arg(
Arg::with_name("clients-host")
.long("clients-host")
.help("The custom host on which the gateway will be running for receiving clients gateway-requests")
.takes_value(true)
.required(true),
)
.arg(
Arg::with_name("clients-port")
.long("clients-port")
.help("The port on which the gateway will be listening for clients gateway-requests")
.takes_value(true)
)
.arg(
Arg::with_name("mix-announce-host")
.long("mix-announce-host")
.help("The host that will be reported to the directory server")
.takes_value(true),
)
.arg(
Arg::with_name("mix-announce-port")
.long("mix-announce-port")
.help("The port that will be reported to the directory server")
.takes_value(true),
)
.arg(
Arg::with_name("clients-announce-host")
.long("clients-announce-host")
.help("The host that will be reported to the directory server")
.takes_value(true),
)
.arg(
Arg::with_name("clients-announce-port")
.long("clients-announce-port")
.help("The port that will be reported to the directory server")
.takes_value(true),
)
.arg(
Arg::with_name("inboxes")
.long("inboxes")
.help("Directory with inboxes where all packets for the clients are stored")
.takes_value(true)
)
.arg(
Arg::with_name("clients-ledger")
.long("clients-ledger")
.help("Ledger directory containing registered clients")
.takes_value(true)
)
.arg(
Arg::with_name("validator")
.long("validator")
.help("REST endpoint of the validator the node is registering presence with")
.takes_value(true),
)
.arg(
Arg::with_name("incentives-address")
.long("incentives-address")
.help("Optional, if participating in the incentives program, payment address")
.takes_value(true),
)
}
fn show_incentives_url() {
println!("\n##### NOTE #####");
println!(
"\nIf you would like to join our testnet incentives program, please visit https://nymtech.net/incentives"
);
println!("\n\n");
}
pub fn execute(matches: &ArgMatches) {
let id = matches.value_of("id").unwrap();
println!("Initialising gateway {}...", id);
let already_init = if Config::default_config_file_path(id).exists() {
println!("Gateway \"{}\" was already initialised before! Config information will be overwritten (but keys will be kept)!", id);
true
} else {
false
};
let mut config = Config::new(id);
config = override_config(config, matches);
// if gateway was already initialised, don't generate new keys
if !already_init {
let identity_keys = identity::KeyPair::new();
let sphinx_keys = encryption::KeyPair::new();
let pathfinder = GatewayPathfinder::new_from_config(&config);
pemstore::store_keypair(
&sphinx_keys,
&pemstore::KeyPairPath::new(
pathfinder.private_encryption_key().to_owned(),
pathfinder.public_encryption_key().to_owned(),
),
)
.expect("Failed to save sphinx keys");
pemstore::store_keypair(
&identity_keys,
&pemstore::KeyPairPath::new(
pathfinder.private_identity_key().to_owned(),
pathfinder.public_identity_key().to_owned(),
),
)
.expect("Failed to save identity keys");
println!("Saved identity and mixnet sphinx keypairs");
}
let config_save_location = config.get_config_file_save_location();
config
.save_to_file(None)
.expect("Failed to save the config file");
println!("Saved configuration file to {:?}", config_save_location);
println!("Gateway configuration completed.\n\n\n");
show_incentives_url();
}