Skip to content

Commit e7f8062

Browse files
authored
Move NS client to separate package under NS API (#5171)
* Move client code to NS API * Move client to separate package * Move things around * Adjust run scripts * rustfmt * Add client to workspace
1 parent edd3f91 commit e7f8062

File tree

85 files changed

+187
-174
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+187
-174
lines changed

Cargo.lock

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

Cargo.toml

+5-6
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ members = [
6161
"common/ip-packet-requests",
6262
"common/ledger",
6363
"common/mixnode-common",
64-
"common/models",
6564
"common/network-defaults",
6665
"common/node-tester-utils",
6766
"common/nonexhaustive-delayqueue",
@@ -126,8 +125,9 @@ members = [
126125
"nym-node",
127126
"nym-node/nym-node-http-api",
128127
"nym-node/nym-node-requests",
129-
"nym-node-status-api",
130-
"nym-node-status-agent",
128+
"nym-node-status-api/nym-node-status-agent",
129+
"nym-node-status-api/nym-node-status-api",
130+
"nym-node-status-api/nym-node-status-client",
131131
"nym-outfox",
132132
"nym-validator-rewarder",
133133
"tools/echo-server",
@@ -155,17 +155,16 @@ members = [
155155
default-members = [
156156
"clients/native",
157157
"clients/socks5",
158-
"common/models",
159158
"explorer-api",
160159
"gateway",
161160
"mixnode",
162161
"nym-api",
163162
"nym-credential-proxy/nym-credential-proxy",
164163
"nym-data-observatory",
165164
"nym-node",
166-
"nym-node-status-api",
165+
"nym-node-status-api/nym-node-status-agent",
166+
"nym-node-status-api/nym-node-status-api",
167167
"nym-validator-rewarder",
168-
"nym-node-status-api",
169168
"service-providers/authenticator",
170169
"service-providers/ip-packet-router",
171170
"service-providers/network-requester",

common/models/Cargo.toml

-17
This file was deleted.

common/models/src/lib.rs

-1
This file was deleted.

nym-node-status-agent/.gitignore

-2
This file was deleted.

nym-node-status-api/.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
nym-node-status-agent/nym-gateway-probe
2+
nym-node-status-agent/keys/
13
data/
24
enter_db.sh
35
nym-gateway-probe
4-
nym-node-status-api
56
*.sqlite
67
*.sqlite-journal

nym-node-status-api/nym-node-status-agent/.gitignore

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Copyright 2024 - Nym Technologies SA <[email protected]>
22
# SPDX-License-Identifier: Apache-2.0
33

4-
54
[package]
65
name = "nym-node-status-agent"
76
version = "1.0.0-rc.1"
@@ -16,20 +15,14 @@ readme.workspace = true
1615

1716
[dependencies]
1817
anyhow = { workspace = true}
19-
bincode = { workspace = true }
20-
chrono = { workspace = true }
2118
clap = { workspace = true, features = ["derive", "env"] }
22-
nym-bin-common = { path = "../common/bin-common", features = ["models"]}
23-
nym-common-models = { path = "../common/models" }
24-
nym-crypto = { path = "../common/crypto", features = ["asymmetric", "rand"] }
19+
nym-bin-common = { path = "../../common/bin-common", features = ["models"]}
20+
nym-node-status-client = { path = "../nym-node-status-client" }
21+
nym-crypto = { path = "../../common/crypto", features = ["asymmetric", "rand"] }
2522
rand = { workspace = true }
2623
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "process"] }
27-
tokio-util = { workspace = true }
2824
tracing = { workspace = true }
2925
tracing-subscriber = { workspace = true, features = ["env-filter"] }
30-
reqwest = { workspace = true, features = ["json"] }
31-
serde = { workspace = true }
32-
serde_json = { workspace = true }
3326

3427
[dev-dependencies]
3528
tempfile = { workspace = true }

nym-node-status-agent/run.sh renamed to nym-node-status-api/nym-node-status-agent/run.sh

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
set -eu
44
export ENVIRONMENT=${ENVIRONMENT:-"sandbox"}
55

6-
probe_git_ref="nym-vpn-core-v1.0.0-rc.6"
6+
probe_git_ref="nym-vpn-core-v1.0.0-rc.14"
77

88
crate_root=$(dirname $(realpath "$0"))
9-
monorepo_root=$(dirname "${crate_root}")
9+
monorepo_root=$(realpath "${crate_root}/../..")
10+
1011
echo "Expecting nym-vpn-client repo at a sibling level of nym monorepo dir"
1112
gateway_probe_src=$(dirname "${monorepo_root}")/nym-vpn-client/nym-vpn-core
1213
echo "gateway_probe_src=$gateway_probe_src"
13-
echo "crate_root=$crate_root"
1414

1515
set -a
1616
source "${monorepo_root}/envs/${ENVIRONMENT}.env"
@@ -30,9 +30,11 @@ function copy_gw_probe() {
3030
pushd $gateway_probe_src
3131
git fetch -a
3232
git checkout $probe_git_ref
33+
3334
cargo build --release --package nym-gateway-probe
3435
cp target/release/nym-gateway-probe "$crate_root"
3536
$crate_root/nym-gateway-probe --version
37+
3638
popd
3739
}
3840

@@ -44,7 +46,7 @@ function swarm() {
4446
local workers=$1
4547

4648
for ((i = 1; i <= workers; i++)); do
47-
../target/release/nym-node-status-agent run-probe &
49+
${monorepo_root}/target/release/nym-node-status-agent run-probe &
4850
done
4951

5052
wait
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use crate::cli::GwProbe;
2+
use anyhow::Context;
3+
use nym_crypto::asymmetric::ed25519::PrivateKey;
4+
5+
pub(crate) async fn run_probe(
6+
server_ip: &str,
7+
server_port: u16,
8+
ns_api_auth_key: &str,
9+
probe_path: &str,
10+
) -> anyhow::Result<()> {
11+
let auth_key = PrivateKey::from_base58_string(ns_api_auth_key)
12+
.context("Couldn't parse auth key, exiting")?;
13+
14+
let ns_api_client = nym_node_status_client::NsApiClient::new(server_ip, server_port, auth_key);
15+
16+
let probe = GwProbe::new(probe_path.to_string());
17+
18+
let version = probe.version().await;
19+
tracing::info!("Probe version:\n{}", version);
20+
21+
if let Some(testrun) = ns_api_client.request_testrun().await? {
22+
let log = probe.run_and_get_log(&Some(testrun.gateway_identity_key));
23+
24+
ns_api_client
25+
.submit_results(testrun.testrun_id, log, testrun.assigned_at_utc)
26+
.await?;
27+
} else {
28+
tracing::info!("No testruns available, exiting")
29+
}
30+
31+
Ok(())
32+
}

nym-node-status-api/Cargo.toml renamed to nym-node-status-api/nym-node-status-api/Cargo.toml

+8-9
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,20 @@ rust-version.workspace = true
1515
[dependencies]
1616
anyhow = { workspace = true }
1717
axum = { workspace = true, features = ["tokio", "macros"] }
18-
bincode = { workspace = true }
1918
chrono = { workspace = true }
2019
clap = { workspace = true, features = ["cargo", "derive", "env", "string"] }
2120
cosmwasm-std = { workspace = true }
2221
envy = { workspace = true }
2322
futures-util = { workspace = true }
2423
moka = { workspace = true, features = ["future"] }
25-
nym-bin-common = { path = "../common/bin-common", features = ["models"]}
26-
nym-common-models = { path = "../common/models" }
27-
nym-crypto = { path = "../common/crypto", features = ["asymmetric", "serde"] }
28-
nym-explorer-client = { path = "../explorer-api/explorer-client" }
29-
nym-network-defaults = { path = "../common/network-defaults" }
30-
nym-validator-client = { path = "../common/client-libs/validator-client" }
31-
nym-task = { path = "../common/task" }
32-
nym-node-requests = { path = "../nym-node/nym-node-requests", features = ["openapi"] }
24+
nym-bin-common = { path = "../../common/bin-common", features = ["models"]}
25+
nym-node-status-client = { path = "../nym-node-status-client" }
26+
nym-crypto = { path = "../../common/crypto", features = ["asymmetric", "serde"] }
27+
nym-explorer-client = { path = "../../explorer-api/explorer-client" }
28+
nym-network-defaults = { path = "../../common/network-defaults" }
29+
nym-validator-client = { path = "../../common/client-libs/validator-client" }
30+
nym-task = { path = "../../common/task" }
31+
nym-node-requests = { path = "../../nym-node/nym-node-requests", features = ["openapi"] }
3332
regex = { workspace = true }
3433
reqwest = { workspace = true }
3534
serde = { workspace = true, features = ["derive"] }

nym-node-status-api/launch_node_status_api.sh renamed to nym-node-status-api/nym-node-status-api/launch_node_status_api.sh

+8-14
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,23 @@
22

33
set -e
44

5-
export RUST_LOG=${RUST_LOG:-debug}
6-
75
export NYM_API_CLIENT_TIMEOUT=60
86
export EXPLORER_CLIENT_TIMEOUT=60
97
export NODE_STATUS_API_TESTRUN_REFRESH_INTERVAL=120
10-
# public keys corresponding to the agents NS API is expecting to be contacted from
11-
export NODE_STATUS_API_AGENT_KEY_LIST="H4z8kx5Kkf5JMQHhxaW1MwYndjKCDHC7HsVhHTFfBZ4J,
12-
5c2GW61135DEr73DxGrR4DR22BLEujvm1k8GYEjRB9at,
13-
3PSFDH2iSJ61KoDNyJpAiw42xS5smV5iBXWnRGTmk2du,
14-
2AH7pJL5PErbSFhZdu3uH8cKa1h1tyCUfSRUm6E5EBz8,
15-
6wQ9ifPFm2EB73BrwpGSd3Ek7GFA5kiAMQDP2ox6JKZw,
16-
G1tevJBnzaQ6zCUsFsxtGJf45BqCTDgzpEz6Sgxks8EH,
17-
FwjL2nGrtgQQ48fPqAUzUZ8UkQZtMtgehqTqj4PQopvh,
18-
Eujj4GmvwQBgHZaNSyqUbjMFSsnXWPSjEYUPgAsKmx1A,
19-
5ZnfSGxW6EKcFxB8jftb9V3f897VpwpZtf7kCPYzB595,
20-
H9kuRd8BGjEUD8Grh5U9YUPN5ZaQmSYz8U44R72AffKM"
8+
9+
# public counterpart of the agent's private key.
10+
# For TESTING only. NOT used in any other environment
11+
export NODE_STATUS_API_AGENT_KEY_LIST="H4z8kx5Kkf5JMQHhxaW1MwYndjKCDHC7HsVhHTFfBZ4J"
2112

2213
export ENVIRONMENT=${ENVIRONMENT:-"sandbox"}
2314

15+
script_dir=$(dirname $(realpath "$0"))
16+
monorepo_root=$(realpath "${script_dir}/../..")
17+
2418
function run_bare() {
2519
# export necessary env vars
2620
set -a
27-
source ../envs/${ENVIRONMENT}.env
21+
source "${monorepo_root}/envs/${ENVIRONMENT}.env"
2822
set +a
2923
export RUST_LOG=debug
3024

nym-node-status-api/src/http/api/testruns.rs renamed to nym-node-status-api/nym-node-status-api/src/http/api/testruns.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
use axum::extract::DefaultBodyLimit;
2-
use axum::Json;
3-
use axum::{
4-
extract::{Path, State},
5-
Router,
6-
};
7-
use nym_common_models::ns_api::{get_testrun, submit_results, VerifiableRequest};
8-
use reqwest::StatusCode;
9-
101
use crate::db::models::TestRunStatus;
112
use crate::db::queries;
123
use crate::testruns::now_utc;
@@ -18,6 +9,17 @@ use crate::{
189
state::AppState,
1910
},
2011
};
12+
use axum::extract::DefaultBodyLimit;
13+
use axum::Json;
14+
use axum::{
15+
extract::{Path, State},
16+
Router,
17+
};
18+
use nym_node_status_client::{
19+
auth::VerifiableRequest,
20+
models::{get_testrun, submit_results},
21+
};
22+
use reqwest::StatusCode;
2123

2224
// TODO dz consider adding endpoint to trigger testrun scan for a given gateway_id
2325
// like in H< src/http/testruns.rs

nym-node-status-api/src/http/api_docs.rs renamed to nym-node-status-api/nym-node-status-api/src/http/api_docs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use utoipauto::utoipauto;
55
// manually import external structs which are behind feature flags because they
66
// can't be automatically discovered
77
// https://github.com/ProbablyClem/utoipauto/issues/13#issuecomment-1974911829
8-
#[utoipauto(paths = "./nym-node-status-api/src")]
8+
#[utoipauto(paths = "./nym-node-status-api/nym-node-status-api/src")]
99
#[derive(OpenApi)]
1010
#[openapi(
1111
info(title = "Node Status API"),

nym-node-status-api/src/http/models.rs renamed to nym-node-status-api/nym-node-status-api/src/http/models.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use nym_node_requests::api::v1::node::models::NodeDescription;
22
use serde::{Deserialize, Serialize};
33
use utoipa::ToSchema;
44

5-
pub(crate) use nym_common_models::ns_api::TestrunAssignment;
5+
pub(crate) use nym_node_status_client::models::TestrunAssignment;
66

77
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
88
pub struct Gateway {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2024 - Nym Technologies SA <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
[package]
5+
name = "nym-node-status-client"
6+
version = "0.1.0"
7+
authors.workspace = true
8+
repository.workspace = true
9+
homepage.workspace = true
10+
documentation.workspace = true
11+
edition.workspace = true
12+
license.workspace = true
13+
rust-version.workspace = true
14+
readme.workspace = true
15+
16+
[dependencies]
17+
anyhow = { workspace = true }
18+
chrono = { workspace = true }
19+
bincode = { workspace = true }
20+
nym-crypto = { path = "../../common/crypto", features = ["asymmetric", "serde"] }
21+
nym-http-api-client = { path = "../../common/http-api-client" }
22+
reqwest = { workspace = true }
23+
serde = { workspace = true, features = ["derive"] }
24+
serde_json = { workspace = true }
25+
tracing = { workspace = true }

0 commit comments

Comments
 (0)