Skip to content

Commit 124712a

Browse files
Feature/network monitor (#369)
* WIP commit * Further into errors (WIP) * WIP commit, more stuff compiling, but now we switch to sneaky Jedrzej trick * Websocket connections starting to work * WIP * Constructing the socket stream in one go * Nicer connections. Getting topology now works. * Fixing startup message * Injecting directory uri * Injecting good mixndodes * Deleting old healthcheck * Starting to wrap gateway client * Splitting out good topology contstruction * Starting to breathe finally * Fixed layer assignment error * Starting gateway client in a better spot * Cleanup * Renamed construct() to new() * Injected channels, removed websockets * Added a MixnetListener to deal with returned packet traffic * Simplification * Renaming and commenting a few things * Renamed temp variables * Fixed variable names * Made errors a bit more explicit on message reconstruction * Added the mixmining route / object to the directory server client * Recipient is always "me", a bit easier to understand what's going on * Subbing in test nodes works * Using QA directory * Noting which directory server we're using at monitor start * Adding Debug to MixStatus so we can print it more easily * Prettification of startup messages * Notifying directory of successful packet receipt * All nodes now being tested * Now able to do timer-based test runs and detect the last node tested * Renamed mixnet_listener to notifier * Moved message chunking into its own home * Starting to pull out packet sends * Basic functionality working! * Enabled timer runs forever * License notices * Depdendency cleanup * Import cleanup * Moved to implicit tokio runtime * Removed some unnecessary data clones * Fixed monitor doing two runs at startup rather than one * dalek version updates * This should have been split but got carried away * Initial ipv6 support * Don't test outdated nodes * Added network monitor to default workspace members * Actually sending reports * Batch-sending mix status * Cargo fmt * Minor cleanup * Malformed Cargo.lock * Post-merge fixes * Defined constant in main.rs for enabling detailed reporting * Updated package versions of the system * Checking version compatibility on startup Co-authored-by: Dave Hrycyszyn <futurechimp@users.noreply.github.com>
1 parent 4f6b2ae commit 124712a

File tree

31 files changed

+1934
-24
lines changed

31 files changed

+1934
-24
lines changed

Cargo.lock

+28-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ members = [
4141
"gateway/gateway-requests",
4242
"service-providers/sphinx-socks",
4343
"mixnode",
44+
"network-monitor",
4445
"validator",
4546
]
4647

@@ -51,4 +52,5 @@ default-members = [
5152
"gateway",
5253
"mixnode",
5354
"validator",
55+
"network-monitor",
5456
]

clients/native/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
build = "build.rs"
33
name = "nym-client"
4-
version = "0.8.1"
4+
version = "0.9.0-dev"
55
authors = ["Dave Hrycyszyn <futurechimp@users.noreply.github.com>", "Jędrzej Stuczyński <andrew@nymtech.net>"]
66
edition = "2018"
77

clients/socks5/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
build = "build.rs"
33
name = "nym-socks5-client"
4-
version = "0.8.1"
4+
version = "0.9.0-dev"
55
authors = ["Dave Hrycyszyn <futurechimp@users.noreply.github.com>"]
66
edition = "2018"
77

clients/webassembly/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
build = "build.rs"
33
name = "nym-client-wasm"
44
authors = ["Dave Hrycyszyn <futurechimp@users.noreply.github.com>", "Jedrzej Stuczynski <andrew@nymtech.net>"]
5-
version = "0.8.1"
5+
version = "0.9.0-dev"
66
edition = "2018"
77
keywords = ["nym", "sphinx", "wasm", "webassembly", "privacy", "client"]
88
license = "Apache-2.0"

common/client-libs/directory-client/models/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
// limitations under the License.
1414

1515
pub mod metrics;
16+
pub mod mixmining;
1617
pub mod presence;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
#[derive(Debug, Deserialize, Serialize)]
4+
#[serde(rename_all = "camelCase")]
5+
/// A notification sent to the validators to let them know whether a given mix is
6+
/// currently up or down (based on whether it's mixing packets)
7+
pub struct MixStatus {
8+
pub pub_key: String,
9+
pub ip_version: String,
10+
pub up: bool,
11+
}
12+
13+
#[derive(Debug, Deserialize, Serialize)]
14+
#[serde(rename_all = "camelCase")]
15+
/// A notification sent to the validators to let them know whether a given set of mixes is
16+
/// currently up or down (based on whether it's mixing packets)
17+
pub struct BatchMixStatus {
18+
pub status: Vec<MixStatus>,
19+
}

common/client-libs/directory-client/models/src/presence/mixnodes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl From<io::Error> for ConversionError {
3636
}
3737
}
3838

39-
#[derive(Clone, Debug, Deserialize, Serialize)]
39+
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
4040
#[serde(rename_all = "camelCase")]
4141
pub struct MixNodePresence {
4242
pub location: String,

common/client-libs/directory-client/src/lib.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use crate::requests::health_check_get::Request as HealthCheckRequest;
1616
use crate::requests::metrics_mixes_get::Request as MetricsMixRequest;
1717
use crate::requests::metrics_mixes_post::Request as MetricsMixPost;
18+
use crate::requests::mix_mining_batch_status_post::Request as MixMiningBatchStatusPost;
19+
use crate::requests::mix_mining_status_post::Request as MixMiningStatusPost;
1820
use crate::requests::presence_coconodes_post::Request as PresenceCocoNodesPost;
1921
use crate::requests::presence_gateways_post::Request as PresenceGatewayPost;
2022
use crate::requests::presence_mixnodes_post::Request as PresenceMixNodesPost;
@@ -25,10 +27,12 @@ use directory_client_models::presence::{
2527
coconodes::CocoPresence, gateways::GatewayPresence, mixnodes::MixNodePresence,
2628
providers::MixProviderPresence,
2729
};
30+
use mixmining::MixStatus;
2831
use requests::{health_check_get::HealthCheckResponse, DirectoryGetRequest, DirectoryPostRequest};
2932

33+
use directory_client_models::mixmining::BatchMixStatus;
3034
pub use directory_client_models::{
31-
metrics,
35+
metrics, mixmining,
3236
presence::{self, Topology},
3337
};
3438

@@ -123,6 +127,22 @@ impl Client {
123127
self.post(req).await
124128
}
125129

130+
pub async fn post_mixmining_status(
131+
&self,
132+
status: MixStatus,
133+
) -> reqwest::Result<reqwest::Response> {
134+
let req = MixMiningStatusPost::new(&self.base_url, status);
135+
self.post(req).await
136+
}
137+
138+
pub async fn post_batch_mixmining_status(
139+
&self,
140+
batch_status: BatchMixStatus,
141+
) -> reqwest::Result<reqwest::Response> {
142+
let req = MixMiningBatchStatusPost::new(&self.base_url, batch_status);
143+
self.post(req).await
144+
}
145+
126146
// this should be soft-deprecated as the whole concept of provider will
127147
// be removed in the next topology rework
128148
pub async fn post_provider_presence(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
use super::{DirectoryPostRequest, DirectoryRequest};
2+
use crate::mixmining::BatchMixStatus;
3+
4+
const PATH: &str = "/api/mixmining/batch";
5+
6+
pub struct Request {
7+
base_url: String,
8+
path: String,
9+
payload: BatchMixStatus,
10+
}
11+
12+
impl DirectoryRequest for Request {
13+
fn url(&self) -> String {
14+
format!("{}{}", self.base_url, self.path)
15+
}
16+
}
17+
18+
impl DirectoryPostRequest for Request {
19+
type Payload = BatchMixStatus;
20+
fn new(base_url: &str, payload: Self::Payload) -> Self {
21+
Request {
22+
base_url: base_url.to_string(),
23+
path: PATH.to_string(),
24+
payload,
25+
}
26+
}
27+
28+
fn json_payload(&self) -> &BatchMixStatus {
29+
&self.payload
30+
}
31+
}
32+
33+
#[cfg(test)]
34+
mod batch_mix_status_post_request {
35+
use super::*;
36+
use crate::client_test_fixture;
37+
use mockito::mock;
38+
39+
#[cfg(test)]
40+
mod on_a_400_status {
41+
use super::*;
42+
43+
#[tokio::test]
44+
async fn it_returns_an_error() {
45+
let _m = mock("POST", PATH).with_status(400).create();
46+
let client = client_test_fixture(&mockito::server_url());
47+
let result = client
48+
.post_batch_mixmining_status(fixtures::new_status())
49+
.await;
50+
assert_eq!(400, result.unwrap().status());
51+
_m.assert();
52+
}
53+
}
54+
55+
#[cfg(test)]
56+
mod on_a_201 {
57+
use super::*;
58+
59+
#[tokio::test]
60+
async fn it_returns_a_response_with_201() {
61+
let json = r#"{
62+
"ok": true
63+
}"#;
64+
let _m = mock("POST", "/api/mixmining/batch")
65+
.with_status(201)
66+
.with_body(json)
67+
.create();
68+
let client = client_test_fixture(&mockito::server_url());
69+
let result = client
70+
.post_batch_mixmining_status(fixtures::new_status())
71+
.await;
72+
assert!(result.is_ok());
73+
_m.assert();
74+
}
75+
}
76+
77+
#[cfg(test)]
78+
mod fixtures {
79+
use crate::mixmining::{BatchMixStatus, MixStatus};
80+
81+
pub fn new_status() -> BatchMixStatus {
82+
BatchMixStatus {
83+
status: vec![MixStatus {
84+
pub_key: "abc".to_string(),
85+
ip_version: "4".to_string(),
86+
up: true,
87+
}],
88+
}
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)