Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/start local network improvements #228

Merged
merged 6 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions clients/desktop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,4 @@ topology = {path = "../../common/topology" }
built = "0.3.2"

[dev-dependencies]
tempfile = "3.1.0"

[features]
qa = []
local = []
tempfile = "3.1.0"
14 changes: 2 additions & 12 deletions clients/desktop/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mod template;

// 'CLIENT'
const DEFAULT_LISTENING_PORT: u16 = 1977;

const DEFAULT_DIRECTORY_SERVER: &str = "https://directory.nymtech.net";
// 'DEBUG'
// where applicable, the below are defined in milliseconds
const DEFAULT_LOOP_COVER_STREAM_AVERAGE_DELAY: u64 = 1000; // 1s
Expand Down Expand Up @@ -249,7 +249,7 @@ impl Default for Client {
// there must be explicit checks for whether id is not empty later
Client {
id: "".to_string(),
directory_server: Self::default_directory_server(),
directory_server: DEFAULT_DIRECTORY_SERVER.to_string(),
private_identity_key_file: Default::default(),
public_identity_key_file: Default::default(),
gateway_id: "".to_string(),
Expand All @@ -260,16 +260,6 @@ impl Default for Client {
}

impl Client {
fn default_directory_server() -> String {
if cfg!(feature = "qa") {
"https://qa-directory.nymtech.net".to_string()
} else if cfg!(feature = "local") {
"http://localhost:8080".to_string()
} else {
"https://directory.nymtech.net".to_string()
}
}

fn default_private_identity_key_file(id: &str) -> PathBuf {
Config::default_data_directory(Some(id)).join("private_identity.pem")
}
Expand Down
6 changes: 1 addition & 5 deletions gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,4 @@ default-features = false
built = "0.3.2"

[dev-dependencies]
tempfile = "3.1.0"

[features]
qa = []
local = []
tempfile = "3.1.0"
26 changes: 8 additions & 18 deletions gateway/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ mod template;
// 'GATEWAY'
const DEFAULT_MIX_LISTENING_PORT: u16 = 1789;
const DEFAULT_CLIENT_LISTENING_PORT: u16 = 9000;
const DEFAULT_DIRECTORY_SERVER: &str = "https://directory.nymtech.net";

// 'DEBUG'
// where applicable, the below are defined in milliseconds
const DEFAULT_PRESENCE_SENDING_DELAY: u64 = 1500; // 1.5s
Expand Down Expand Up @@ -121,7 +123,7 @@ impl Config {
}

pub fn with_custom_directory<S: Into<String>>(mut self, directory_server: S) -> Self {
self.debug.presence_directory_server = directory_server.into();
self.gateway.presence_directory_server = directory_server.into();
self
}

Expand Down Expand Up @@ -324,7 +326,7 @@ impl Config {
}

pub fn get_presence_directory_server(&self) -> String {
self.debug.presence_directory_server.clone()
self.gateway.presence_directory_server.clone()
}

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

/// Directory server to which the server will be reporting their presence data.
presence_directory_server: String,

/// nym_home_directory specifies absolute path to the home nym gateways directory.
/// It is expected to use default value and hence .toml file should not redefine this field.
nym_root_directory: PathBuf,
Expand All @@ -420,6 +425,7 @@ impl Default for Gateway {
location: Self::default_location(),
private_sphinx_key_file: Default::default(),
public_sphinx_key_file: Default::default(),
presence_directory_server: DEFAULT_DIRECTORY_SERVER.to_string(),
nym_root_directory: Config::default_root_directory(),
}
}
Expand Down Expand Up @@ -511,9 +517,6 @@ impl Default for Logging {
#[derive(Debug, Deserialize, PartialEq, Serialize)]
#[serde(default, deny_unknown_fields)]
pub struct Debug {
/// Directory server to which the server will be reporting their presence data.
presence_directory_server: String,

/// Initial value of an exponential backoff to reconnect to dropped TCP connection when
/// forwarding sphinx packets.
/// The provided value is interpreted as milliseconds.
Expand All @@ -540,22 +543,9 @@ pub struct Debug {
message_retrieval_limit: u16,
}

impl Debug {
fn default_directory_server() -> String {
if cfg!(feature = "qa") {
"https://qa-directory.nymtech.net".to_string()
} else if cfg!(feature = "local") {
"http://localhost:8080".to_string()
} else {
"https://directory.nymtech.net".to_string()
}
}
}

impl Default for Debug {
fn default() -> Self {
Debug {
presence_directory_server: Self::default_directory_server(),
packet_forwarding_initial_backoff: DEFAULT_PACKET_FORWARDING_INITIAL_BACKOFF,
packet_forwarding_maximum_backoff: DEFAULT_PACKET_FORWARDING_MAXIMUM_BACKOFF,
initial_connection_timeout: DEFAULT_INITIAL_CONNECTION_TIMEOUT,
Expand Down
3 changes: 3 additions & 0 deletions gateway/src/config/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ private_sphinx_key_file = '{{ gateway.private_sphinx_key_file }}'
# Path to file containing public sphinx key.
public_sphinx_key_file = '{{ gateway.public_sphinx_key_file }}'

# Directory server to which the server will be reporting their presence data.
presence_directory_server = '{{ gateway.presence_directory_server }}'

# nym_home_directory specifies absolute path to the home nym gateway directory.
# It is expected to use default value and hence .toml file should not redefine this field.
nym_root_directory = '{{ gateway.nym_root_directory }}'
Expand Down
6 changes: 1 addition & 5 deletions mixnode/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,4 @@ topology = {path = "../common/topology"}
built = "0.3.2"

[dev-dependencies]
tempfile = "3.1.0"

[features]
qa = []
local = []
tempfile = "3.1.0"
41 changes: 15 additions & 26 deletions mixnode/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ mod template;

// 'MIXNODE'
const DEFAULT_LISTENING_PORT: u16 = 1789;
const DEFAULT_DIRECTORY_SERVER: &str = "https://directory.nymtech.net";

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

Expand Down Expand Up @@ -214,15 +215,15 @@ impl Config {
}

pub fn get_presence_directory_server(&self) -> String {
self.debug.presence_directory_server.clone()
self.mixnode.presence_directory_server.clone()
}

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

pub fn get_metrics_directory_server(&self) -> String {
self.debug.metrics_directory_server.clone()
self.mixnode.metrics_directory_server.clone()
}

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

// The idea of additional 'directory servers' is to let mixes report their presence
// and metrics to separate places
/// Directory server to which the server will be reporting their presence data.
presence_directory_server: String,

/// Directory server to which the server will be reporting their metrics data.
metrics_directory_server: String,

/// nym_home_directory specifies absolute path to the home nym MixNodes directory.
/// It is expected to use default value and hence .toml file should not redefine this field.
nym_root_directory: PathBuf,
Expand Down Expand Up @@ -321,6 +330,8 @@ impl Default for MixNode {
announce_address: format!("127.0.0.1:{}", DEFAULT_LISTENING_PORT),
private_sphinx_key_file: Default::default(),
public_sphinx_key_file: Default::default(),
presence_directory_server: DEFAULT_DIRECTORY_SERVER.to_string(),
metrics_directory_server: DEFAULT_DIRECTORY_SERVER.to_string(),
nym_root_directory: Config::default_root_directory(),
}
}
Expand All @@ -339,18 +350,10 @@ impl Default for Logging {
#[derive(Debug, Deserialize, PartialEq, Serialize)]
#[serde(default, deny_unknown_fields)]
pub struct Debug {
// The idea of additional 'directory servers' is to let mixes report their presence
// and metrics to separate places
/// Directory server to which the server will be reporting their presence data.
presence_directory_server: String,

/// Delay between each subsequent presence data being sent.
/// The provided value is interpreted as milliseconds.
presence_sending_delay: u64,

/// Directory server to which the server will be reporting their metrics data.
metrics_directory_server: String,

/// Delay between each subsequent metrics data being sent.
/// The provided value is interpreted as milliseconds.
metrics_sending_delay: u64,
Expand All @@ -374,24 +377,10 @@ pub struct Debug {
initial_connection_timeout: u64,
}

impl Debug {
fn default_directory_server() -> String {
if cfg!(feature = "qa") {
"https://qa-directory.nymtech.net".to_string()
} else if cfg!(feature = "local") {
"http://localhost:8080".to_string()
} else {
"https://directory.nymtech.net".to_string()
}
}
}

impl Default for Debug {
fn default() -> Self {
Debug {
presence_directory_server: Self::default_directory_server(),
presence_sending_delay: DEFAULT_PRESENCE_SENDING_DELAY,
metrics_directory_server: Self::default_directory_server(),
metrics_sending_delay: DEFAULT_METRICS_SENDING_DELAY,
metrics_running_stats_logging_delay: DEFAULT_METRICS_RUNNING_STATS_LOGGING_DELAY,
packet_forwarding_initial_backoff: DEFAULT_PACKET_FORWARDING_INITIAL_BACKOFF,
Expand Down
6 changes: 6 additions & 0 deletions mixnode/src/config/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ public_sphinx_key_file = '{{ mixnode.public_sphinx_key_file }}'
# `listening_address`.
announce_address = '{{ mixnode.announce_address }}'

# Directory server to which the server will be reporting their presence data.
presence_directory_server = '{{ mixnode.presence_directory_server }}'

# Directory server to which the server will be reporting their metrics data.
metrics_directory_server = '{{ mixnode.metrics_directory_server }}'

##### advanced configuration options #####

# Absolute path to the home Nym Clients directory.
Expand Down
59 changes: 25 additions & 34 deletions scripts/start_local_network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,53 +14,44 @@
#// See the License for the specific language governing permissions and
#// limitations under the License.

MAX_LAYERS=3
NUMMIXES=3

echo "Killing old testnet processes..."
function kill_old() {
echo "Killing old testnet processes..."
killall nym-mixnode
killall nym-gateway
killall nym-client
}

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

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

cargo build --manifest-path nym-client/Cargo.toml --features=local
cargo build --manifest-path mixnode/Cargo.toml --features=local
cargo build --manifest-path sfw-provider/Cargo.toml --features=local

MAX_LAYERS=3
NUMMIXES=${1:-3} # Set $NUMMIXES to default of 3, but allow the user to set other values if desired
echo "Press CTRL-C to stop."

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

$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
$PWD/target/debug/nym-sfw-provider run --id provider-local &
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
cargo run --bin nym-gateway -- run --id gateway-local &

sleep 1

for (( j=0; j<$NUMMIXES; j++ ))

# Note: to disable logging (or direct it to another output) modify the constant on top of mixnode or provider;
# Will make it later either configurable by flags or config file.
do
for (( j=0; j<$NUMMIXES; j++ )); do
let layer=j%MAX_LAYERS+1
$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))
$PWD/target/debug/nym-mixnode run --id mix-local$j &
cargo run --bin nym-mixnode -- init --id mix-local$j --host 127.0.0.1 --port $((9980+$j)) --layer $layer --directory $DIR
cargo run --bin nym-mixnode -- run --id mix-local$j &
sleep 1
done


# trap call ctrl_c()
trap ctrl_c SIGINT SIGTERM SIGTSTP
function ctrl_c() {
echo "** Trapped SIGINT, SIGTERM and SIGTSTP"
for (( j=0; j<$NUMMIXES; j++ ));
do
kill_port $((9980+$j))
done
}

function kill_port() {
PID=$(lsof -t -i:$1)
echo "$PID"
kill -TERM $PID || kill -KILL $PID
}
# 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)
# also it seems that SIGINT is nicely passed to all processes so they kill themselves
tail -f /dev/null
17 changes: 0 additions & 17 deletions scripts/stop_local_network.sh

This file was deleted.

6 changes: 1 addition & 5 deletions validator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,4 @@ topology = {path = "../common/topology"}
built = "0.3.2"

[dev-dependencies]
tempfile = "3.1.0"

[features]
qa = []
local = []
tempfile = "3.1.0"
Loading