Skip to content

Commit 3773800

Browse files
authored
Feature/start local network improvements (#228)
* Moved directory_server from Debug section of configs * Using correct variable path * Updated start_local_network script * Actually killing gateways on startup * Removed redundant stop_local_network.sh * The Canadian appeasement accord
1 parent ff2e24a commit 3773800

File tree

12 files changed

+66
-139
lines changed

12 files changed

+66
-139
lines changed

clients/desktop/Cargo.toml

+1-5
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,4 @@ topology = {path = "../../common/topology" }
4343
built = "0.3.2"
4444

4545
[dev-dependencies]
46-
tempfile = "3.1.0"
47-
48-
[features]
49-
qa = []
50-
local = []
46+
tempfile = "3.1.0"

clients/desktop/src/config/mod.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ mod template;
2323

2424
// 'CLIENT'
2525
const DEFAULT_LISTENING_PORT: u16 = 1977;
26-
26+
const DEFAULT_DIRECTORY_SERVER: &str = "https://directory.nymtech.net";
2727
// 'DEBUG'
2828
// where applicable, the below are defined in milliseconds
2929
const DEFAULT_LOOP_COVER_STREAM_AVERAGE_DELAY: u64 = 1000; // 1s
@@ -249,7 +249,7 @@ impl Default for Client {
249249
// there must be explicit checks for whether id is not empty later
250250
Client {
251251
id: "".to_string(),
252-
directory_server: Self::default_directory_server(),
252+
directory_server: DEFAULT_DIRECTORY_SERVER.to_string(),
253253
private_identity_key_file: Default::default(),
254254
public_identity_key_file: Default::default(),
255255
gateway_id: "".to_string(),
@@ -260,16 +260,6 @@ impl Default for Client {
260260
}
261261

262262
impl Client {
263-
fn default_directory_server() -> String {
264-
if cfg!(feature = "qa") {
265-
"https://qa-directory.nymtech.net".to_string()
266-
} else if cfg!(feature = "local") {
267-
"http://localhost:8080".to_string()
268-
} else {
269-
"https://directory.nymtech.net".to_string()
270-
}
271-
}
272-
273263
fn default_private_identity_key_file(id: &str) -> PathBuf {
274264
Config::default_data_directory(Some(id)).join("private_identity.pem")
275265
}

gateway/Cargo.toml

+1-5
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,4 @@ default-features = false
3939
built = "0.3.2"
4040

4141
[dev-dependencies]
42-
tempfile = "3.1.0"
43-
44-
[features]
45-
qa = []
46-
local = []
42+
tempfile = "3.1.0"

gateway/src/config/mod.rs

+8-18
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ mod template;
2727
// 'GATEWAY'
2828
const DEFAULT_MIX_LISTENING_PORT: u16 = 1789;
2929
const DEFAULT_CLIENT_LISTENING_PORT: u16 = 9000;
30+
const DEFAULT_DIRECTORY_SERVER: &str = "https://directory.nymtech.net";
31+
3032
// 'DEBUG'
3133
// where applicable, the below are defined in milliseconds
3234
const DEFAULT_PRESENCE_SENDING_DELAY: u64 = 1500; // 1.5s
@@ -121,7 +123,7 @@ impl Config {
121123
}
122124

123125
pub fn with_custom_directory<S: Into<String>>(mut self, directory_server: S) -> Self {
124-
self.debug.presence_directory_server = directory_server.into();
126+
self.gateway.presence_directory_server = directory_server.into();
125127
self
126128
}
127129

@@ -324,7 +326,7 @@ impl Config {
324326
}
325327

326328
pub fn get_presence_directory_server(&self) -> String {
327-
self.debug.presence_directory_server.clone()
329+
self.gateway.presence_directory_server.clone()
328330
}
329331

330332
pub fn get_presence_sending_delay(&self) -> time::Duration {
@@ -394,6 +396,9 @@ pub struct Gateway {
394396
/// Path to file containing public sphinx key.
395397
public_sphinx_key_file: PathBuf,
396398

399+
/// Directory server to which the server will be reporting their presence data.
400+
presence_directory_server: String,
401+
397402
/// nym_home_directory specifies absolute path to the home nym gateways directory.
398403
/// It is expected to use default value and hence .toml file should not redefine this field.
399404
nym_root_directory: PathBuf,
@@ -420,6 +425,7 @@ impl Default for Gateway {
420425
location: Self::default_location(),
421426
private_sphinx_key_file: Default::default(),
422427
public_sphinx_key_file: Default::default(),
428+
presence_directory_server: DEFAULT_DIRECTORY_SERVER.to_string(),
423429
nym_root_directory: Config::default_root_directory(),
424430
}
425431
}
@@ -511,9 +517,6 @@ impl Default for Logging {
511517
#[derive(Debug, Deserialize, PartialEq, Serialize)]
512518
#[serde(default, deny_unknown_fields)]
513519
pub struct Debug {
514-
/// Directory server to which the server will be reporting their presence data.
515-
presence_directory_server: String,
516-
517520
/// Initial value of an exponential backoff to reconnect to dropped TCP connection when
518521
/// forwarding sphinx packets.
519522
/// The provided value is interpreted as milliseconds.
@@ -540,22 +543,9 @@ pub struct Debug {
540543
message_retrieval_limit: u16,
541544
}
542545

543-
impl Debug {
544-
fn default_directory_server() -> String {
545-
if cfg!(feature = "qa") {
546-
"https://qa-directory.nymtech.net".to_string()
547-
} else if cfg!(feature = "local") {
548-
"http://localhost:8080".to_string()
549-
} else {
550-
"https://directory.nymtech.net".to_string()
551-
}
552-
}
553-
}
554-
555546
impl Default for Debug {
556547
fn default() -> Self {
557548
Debug {
558-
presence_directory_server: Self::default_directory_server(),
559549
packet_forwarding_initial_backoff: DEFAULT_PACKET_FORWARDING_INITIAL_BACKOFF,
560550
packet_forwarding_maximum_backoff: DEFAULT_PACKET_FORWARDING_MAXIMUM_BACKOFF,
561551
initial_connection_timeout: DEFAULT_INITIAL_CONNECTION_TIMEOUT,

gateway/src/config/template.rs

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ private_sphinx_key_file = '{{ gateway.private_sphinx_key_file }}'
3939
# Path to file containing public sphinx key.
4040
public_sphinx_key_file = '{{ gateway.public_sphinx_key_file }}'
4141
42+
# Directory server to which the server will be reporting their presence data.
43+
presence_directory_server = '{{ gateway.presence_directory_server }}'
44+
4245
# nym_home_directory specifies absolute path to the home nym gateway directory.
4346
# It is expected to use default value and hence .toml file should not redefine this field.
4447
nym_root_directory = '{{ gateway.nym_root_directory }}'

mixnode/Cargo.toml

+1-5
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,4 @@ topology = {path = "../common/topology"}
3232
built = "0.3.2"
3333

3434
[dev-dependencies]
35-
tempfile = "3.1.0"
36-
37-
[features]
38-
qa = []
39-
local = []
35+
tempfile = "3.1.0"

mixnode/src/config/mod.rs

+15-26
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ mod template;
2626

2727
// 'MIXNODE'
2828
const DEFAULT_LISTENING_PORT: u16 = 1789;
29+
const DEFAULT_DIRECTORY_SERVER: &str = "https://directory.nymtech.net";
2930

3031
// 'DEBUG'
3132
// where applicable, the below are defined in milliseconds
@@ -116,8 +117,8 @@ impl Config {
116117
// you need to do so in the config.toml file.
117118
pub fn with_custom_directory<S: Into<String>>(mut self, directory_server: S) -> Self {
118119
let directory_server_string = directory_server.into();
119-
self.debug.presence_directory_server = directory_server_string.clone();
120-
self.debug.metrics_directory_server = directory_server_string;
120+
self.mixnode.presence_directory_server = directory_server_string.clone();
121+
self.mixnode.metrics_directory_server = directory_server_string;
121122
self
122123
}
123124

@@ -214,15 +215,15 @@ impl Config {
214215
}
215216

216217
pub fn get_presence_directory_server(&self) -> String {
217-
self.debug.presence_directory_server.clone()
218+
self.mixnode.presence_directory_server.clone()
218219
}
219220

220221
pub fn get_presence_sending_delay(&self) -> time::Duration {
221222
time::Duration::from_millis(self.debug.presence_sending_delay)
222223
}
223224

224225
pub fn get_metrics_directory_server(&self) -> String {
225-
self.debug.metrics_directory_server.clone()
226+
self.mixnode.metrics_directory_server.clone()
226227
}
227228

228229
pub fn get_metrics_sending_delay(&self) -> time::Duration {
@@ -290,6 +291,14 @@ pub struct MixNode {
290291
/// Path to file containing public sphinx key.
291292
public_sphinx_key_file: PathBuf,
292293

294+
// The idea of additional 'directory servers' is to let mixes report their presence
295+
// and metrics to separate places
296+
/// Directory server to which the server will be reporting their presence data.
297+
presence_directory_server: String,
298+
299+
/// Directory server to which the server will be reporting their metrics data.
300+
metrics_directory_server: String,
301+
293302
/// nym_home_directory specifies absolute path to the home nym MixNodes directory.
294303
/// It is expected to use default value and hence .toml file should not redefine this field.
295304
nym_root_directory: PathBuf,
@@ -321,6 +330,8 @@ impl Default for MixNode {
321330
announce_address: format!("127.0.0.1:{}", DEFAULT_LISTENING_PORT),
322331
private_sphinx_key_file: Default::default(),
323332
public_sphinx_key_file: Default::default(),
333+
presence_directory_server: DEFAULT_DIRECTORY_SERVER.to_string(),
334+
metrics_directory_server: DEFAULT_DIRECTORY_SERVER.to_string(),
324335
nym_root_directory: Config::default_root_directory(),
325336
}
326337
}
@@ -339,18 +350,10 @@ impl Default for Logging {
339350
#[derive(Debug, Deserialize, PartialEq, Serialize)]
340351
#[serde(default, deny_unknown_fields)]
341352
pub struct Debug {
342-
// The idea of additional 'directory servers' is to let mixes report their presence
343-
// and metrics to separate places
344-
/// Directory server to which the server will be reporting their presence data.
345-
presence_directory_server: String,
346-
347353
/// Delay between each subsequent presence data being sent.
348354
/// The provided value is interpreted as milliseconds.
349355
presence_sending_delay: u64,
350356

351-
/// Directory server to which the server will be reporting their metrics data.
352-
metrics_directory_server: String,
353-
354357
/// Delay between each subsequent metrics data being sent.
355358
/// The provided value is interpreted as milliseconds.
356359
metrics_sending_delay: u64,
@@ -374,24 +377,10 @@ pub struct Debug {
374377
initial_connection_timeout: u64,
375378
}
376379

377-
impl Debug {
378-
fn default_directory_server() -> String {
379-
if cfg!(feature = "qa") {
380-
"https://qa-directory.nymtech.net".to_string()
381-
} else if cfg!(feature = "local") {
382-
"http://localhost:8080".to_string()
383-
} else {
384-
"https://directory.nymtech.net".to_string()
385-
}
386-
}
387-
}
388-
389380
impl Default for Debug {
390381
fn default() -> Self {
391382
Debug {
392-
presence_directory_server: Self::default_directory_server(),
393383
presence_sending_delay: DEFAULT_PRESENCE_SENDING_DELAY,
394-
metrics_directory_server: Self::default_directory_server(),
395384
metrics_sending_delay: DEFAULT_METRICS_SENDING_DELAY,
396385
metrics_running_stats_logging_delay: DEFAULT_METRICS_RUNNING_STATS_LOGGING_DELAY,
397386
packet_forwarding_initial_backoff: DEFAULT_PACKET_FORWARDING_INITIAL_BACKOFF,

mixnode/src/config/template.rs

+6
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ public_sphinx_key_file = '{{ mixnode.public_sphinx_key_file }}'
5555
# `listening_address`.
5656
announce_address = '{{ mixnode.announce_address }}'
5757
58+
# Directory server to which the server will be reporting their presence data.
59+
presence_directory_server = '{{ mixnode.presence_directory_server }}'
60+
61+
# Directory server to which the server will be reporting their metrics data.
62+
metrics_directory_server = '{{ mixnode.metrics_directory_server }}'
63+
5864
##### advanced configuration options #####
5965
6066
# Absolute path to the home Nym Clients directory.

scripts/start_local_network.sh

+25-34
Original file line numberDiff line numberDiff line change
@@ -14,53 +14,44 @@
1414
#// See the License for the specific language governing permissions and
1515
#// limitations under the License.
1616

17+
MAX_LAYERS=3
18+
NUMMIXES=3
1719

18-
echo "Killing old testnet processes..."
20+
function kill_old() {
21+
echo "Killing old testnet processes..."
22+
killall nym-mixnode
23+
killall nym-gateway
24+
killall nym-client
25+
}
1926

20-
killall nym-mixnode
21-
killall nym-sfw-provider
27+
if [ $# -ne 1 ]; then
28+
echo "Expected a single argument to be passed - the directory server (that you should have independently started locally!)"
29+
exit 1
30+
fi
2231

23-
echo "Press CTRL-C to stop."
24-
echo "Make sure you have started nym-directory !"
32+
DIR=$1
2533

26-
cargo build --manifest-path nym-client/Cargo.toml --features=local
27-
cargo build --manifest-path mixnode/Cargo.toml --features=local
28-
cargo build --manifest-path sfw-provider/Cargo.toml --features=local
29-
30-
MAX_LAYERS=3
31-
NUMMIXES=${1:-3} # Set $NUMMIXES to default of 3, but allow the user to set other values if desired
34+
echo "Press CTRL-C to stop."
3235

33-
export RUST_LOG=error
36+
kill_old
37+
export RUST_LOG=warning
38+
# NOTE: If we wanted to suppress stdout and stderr, replace `&` with `> /dev/null 2>&1 &` in the `run`
3439

35-
$PWD/target/debug/nym-sfw-provider init --id provider-local --clients-host 127.0.0.1 --mix-host 127.0.0.1 --mix-port 4000 --mix-announce-port 4000
36-
$PWD/target/debug/nym-sfw-provider run --id provider-local &
40+
cargo run --bin nym-gateway -- init --id gateway-local --mix-host 127.0.0.1:10000 --clients-host 127.0.0.1:10001 --directory $DIR
41+
cargo run --bin nym-gateway -- run --id gateway-local &
3742

3843
sleep 1
3944

40-
for (( j=0; j<$NUMMIXES; j++ ))
41-
4245
# Note: to disable logging (or direct it to another output) modify the constant on top of mixnode or provider;
4346
# Will make it later either configurable by flags or config file.
44-
do
47+
for (( j=0; j<$NUMMIXES; j++ )); do
4548
let layer=j%MAX_LAYERS+1
46-
$PWD/target/debug/nym-mixnode init --id mix-local$j --host 127.0.0.1 --port $((9980+$j)) --layer $layer --announce-host 127.0.0.1:$((9980+$j))
47-
$PWD/target/debug/nym-mixnode run --id mix-local$j &
49+
cargo run --bin nym-mixnode -- init --id mix-local$j --host 127.0.0.1 --port $((9980+$j)) --layer $layer --directory $DIR
50+
cargo run --bin nym-mixnode -- run --id mix-local$j &
4851
sleep 1
4952
done
5053

5154

52-
# trap call ctrl_c()
53-
trap ctrl_c SIGINT SIGTERM SIGTSTP
54-
function ctrl_c() {
55-
echo "** Trapped SIGINT, SIGTERM and SIGTSTP"
56-
for (( j=0; j<$NUMMIXES; j++ ));
57-
do
58-
kill_port $((9980+$j))
59-
done
60-
}
61-
62-
function kill_port() {
63-
PID=$(lsof -t -i:$1)
64-
echo "$PID"
65-
kill -TERM $PID || kill -KILL $PID
66-
}
55+
# just run forever (so we'd get all network warnings in this window and you wouldn't get confused when you started another process here)
56+
# also it seems that SIGINT is nicely passed to all processes so they kill themselves
57+
tail -f /dev/null

scripts/stop_local_network.sh

-17
This file was deleted.

validator/Cargo.toml

+1-5
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,4 @@ topology = {path = "../common/topology"}
3636
built = "0.3.2"
3737

3838
[dev-dependencies]
39-
tempfile = "3.1.0"
40-
41-
[features]
42-
qa = []
43-
local = []
39+
tempfile = "3.1.0"

0 commit comments

Comments
 (0)