Feature/one binary to rule them all (#4500)
This commit is contained in:
committed by
GitHub
parent
fa1e9988b3
commit
4c5351ba60
@@ -3,7 +3,7 @@
|
||||
|
||||
use crate::node::node_description::NodeDescription;
|
||||
use axum::extract::Query;
|
||||
use nym_node::http::api::{FormattedResponse, OutputParams};
|
||||
use nym_http_api_common::{FormattedResponse, OutputParams};
|
||||
|
||||
/// Returns a description of the node and why someone might want to delegate stake to it.
|
||||
pub(crate) async fn description(
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
use axum::extract::Query;
|
||||
use cupid::TopologyType;
|
||||
use nym_node::http::api::{FormattedResponse, OutputParams};
|
||||
use nym_http_api_common::{FormattedResponse, OutputParams};
|
||||
use serde::Serialize;
|
||||
use sysinfo::{System, SystemExt};
|
||||
|
||||
|
||||
@@ -1,25 +1,24 @@
|
||||
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use crate::node::http::legacy::verloc::VerlocState;
|
||||
use crate::node::node_statistics::SharedNodeStats;
|
||||
use axum::extract::FromRef;
|
||||
use nym_node_http_api::state::metrics::{SharedMixingStats, SharedVerlocStats};
|
||||
|
||||
// this is a temporary thing for the transition period
|
||||
#[derive(Clone, Default)]
|
||||
pub(crate) struct MixnodeAppState {
|
||||
pub(crate) verloc: VerlocState,
|
||||
pub(crate) stats: SharedNodeStats,
|
||||
pub(crate) verloc: SharedVerlocStats,
|
||||
pub(crate) stats: SharedMixingStats,
|
||||
pub(crate) metrics_key: Option<String>,
|
||||
}
|
||||
|
||||
impl FromRef<MixnodeAppState> for VerlocState {
|
||||
impl FromRef<MixnodeAppState> for SharedVerlocStats {
|
||||
fn from_ref(app_state: &MixnodeAppState) -> Self {
|
||||
app_state.verloc.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl FromRef<MixnodeAppState> for SharedNodeStats {
|
||||
impl FromRef<MixnodeAppState> for SharedMixingStats {
|
||||
fn from_ref(app_state: &MixnodeAppState) -> Self {
|
||||
app_state.stats.clone()
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use crate::node::node_statistics::{NodeStatsSimple, SharedNodeStats};
|
||||
|
||||
use axum::{
|
||||
extract::{Query, State},
|
||||
http::HeaderMap,
|
||||
};
|
||||
use nym_http_api_common::{FormattedResponse, Output};
|
||||
use nym_metrics::metrics;
|
||||
use nym_node::http::api::{FormattedResponse, Output};
|
||||
use nym_node_http_api::api::api_requests::v1::metrics::models::MixingStats;
|
||||
use nym_node_http_api::state::metrics::SharedMixingStats;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::state::MixnodeAppState;
|
||||
@@ -17,7 +17,7 @@ use super::state::MixnodeAppState;
|
||||
#[serde(untagged)]
|
||||
pub enum NodeStatsResponse {
|
||||
Full(String),
|
||||
Simple(NodeStatsSimple),
|
||||
Simple(MixingStats),
|
||||
}
|
||||
|
||||
pub(crate) async fn metrics(State(state): State<MixnodeAppState>, headers: HeaderMap) -> String {
|
||||
@@ -38,7 +38,7 @@ pub(crate) async fn metrics(State(state): State<MixnodeAppState>, headers: Heade
|
||||
|
||||
pub(crate) async fn stats(
|
||||
Query(params): Query<StatsQueryParams>,
|
||||
State(stats): State<SharedNodeStats>,
|
||||
State(stats): State<SharedMixingStats>,
|
||||
) -> MixnodeStatsResponse {
|
||||
let output = params.output.unwrap_or_default();
|
||||
|
||||
@@ -47,12 +47,11 @@ pub(crate) async fn stats(
|
||||
output.to_response(response)
|
||||
}
|
||||
|
||||
async fn generate_stats(full: bool, stats: SharedNodeStats) -> NodeStatsResponse {
|
||||
let snapshot_data = stats.clone_data().await;
|
||||
async fn generate_stats(full: bool, stats: SharedMixingStats) -> NodeStatsResponse {
|
||||
if full {
|
||||
NodeStatsResponse::Full(metrics!())
|
||||
} else {
|
||||
NodeStatsResponse::Simple(snapshot_data.simplify())
|
||||
NodeStatsResponse::Simple(stats.read().await.as_response())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,30 +2,18 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use axum::extract::{Query, State};
|
||||
use nym_mixnode_common::verloc::{AtomicVerlocResult, VerlocResult};
|
||||
use nym_node::http::api::{FormattedResponse, OutputParams};
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub(crate) struct VerlocState {
|
||||
shared: AtomicVerlocResult,
|
||||
}
|
||||
|
||||
impl VerlocState {
|
||||
pub fn new(atomic_verloc_result: AtomicVerlocResult) -> Self {
|
||||
VerlocState {
|
||||
shared: atomic_verloc_result,
|
||||
}
|
||||
}
|
||||
}
|
||||
use nym_http_api_common::{FormattedResponse, OutputParams};
|
||||
use nym_node_http_api::api::api_requests::v1::metrics::models::VerlocResultData;
|
||||
use nym_node_http_api::state::metrics::SharedVerlocStats;
|
||||
|
||||
/// Provides verifiable location (verloc) measurements for this mixnode - a list of the
|
||||
/// round-trip times, in milliseconds, for all other mixnodes that this node knows about.
|
||||
pub(crate) async fn verloc(
|
||||
State(verloc): State<VerlocState>,
|
||||
State(verloc): State<SharedVerlocStats>,
|
||||
Query(output): Query<OutputParams>,
|
||||
) -> MixnodeVerlocResponse {
|
||||
let output = output.output.unwrap_or_default();
|
||||
output.to_response(verloc.shared.clone_data().await)
|
||||
output.to_response(verloc.read().await.current_run_data.clone())
|
||||
}
|
||||
|
||||
pub type MixnodeVerlocResponse = FormattedResponse<VerlocResult>;
|
||||
pub type MixnodeVerlocResponse = FormattedResponse<VerlocResultData>;
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
|
||||
// Copyright 2023-2024 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use crate::config::Config;
|
||||
use crate::error::MixnodeError;
|
||||
use crate::node::http::legacy::verloc::VerlocState;
|
||||
use crate::node::node_description::NodeDescription;
|
||||
use crate::node::node_statistics::SharedNodeStats;
|
||||
use log::info;
|
||||
use nym_bin_common::bin_info_owned;
|
||||
use nym_crypto::asymmetric::{encryption, identity};
|
||||
use nym_node::error::NymNodeError;
|
||||
use nym_node::http::api::api_requests;
|
||||
use nym_node::http::api::api_requests::SignedHostInformation;
|
||||
use nym_node_http_api::api::api_requests;
|
||||
use nym_node_http_api::api::api_requests::SignedHostInformation;
|
||||
use nym_node_http_api::state::metrics::{SharedMixingStats, SharedVerlocStats};
|
||||
use nym_node_http_api::NymNodeHttpError;
|
||||
use nym_task::TaskClient;
|
||||
|
||||
pub(crate) mod legacy;
|
||||
@@ -25,13 +24,14 @@ fn load_host_details(
|
||||
ip_address: config.host.public_ips.clone(),
|
||||
hostname: config.host.hostname.clone(),
|
||||
keys: api_requests::v1::node::models::HostKeys {
|
||||
ed25519: identity_keypair.public_key().to_base58_string(),
|
||||
x25519: sphinx_key.to_base58_string(),
|
||||
ed25519_identity: identity_keypair.public_key().to_base58_string(),
|
||||
x25519_sphinx: sphinx_key.to_base58_string(),
|
||||
x25519_noise: "".to_string(),
|
||||
},
|
||||
};
|
||||
|
||||
let signed_info = SignedHostInformation::new(host_info, identity_keypair.private_key())
|
||||
.map_err(NymNodeError::from)?;
|
||||
.map_err(NymNodeHttpError::from)?;
|
||||
Ok(signed_info)
|
||||
}
|
||||
|
||||
@@ -71,13 +71,13 @@ impl<'a> HttpApiBuilder<'a> {
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn with_verloc(mut self, verloc: VerlocState) -> Self {
|
||||
pub(crate) fn with_verloc(mut self, verloc: SharedVerlocStats) -> Self {
|
||||
self.legacy_mixnode.verloc = verloc;
|
||||
self
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn with_mixing_stats(mut self, stats: SharedNodeStats) -> Self {
|
||||
pub(crate) fn with_mixing_stats(mut self, stats: SharedMixingStats) -> Self {
|
||||
self.legacy_mixnode.stats = stats;
|
||||
self
|
||||
}
|
||||
@@ -92,7 +92,7 @@ impl<'a> HttpApiBuilder<'a> {
|
||||
let bind_address = self.mixnode_config.http.bind_address;
|
||||
info!("Starting HTTP API on http://{bind_address}",);
|
||||
|
||||
let config = nym_node::http::Config::new(
|
||||
let config = nym_node_http_api::Config::new(
|
||||
bin_info_owned!(),
|
||||
load_host_details(
|
||||
self.mixnode_config,
|
||||
@@ -103,7 +103,7 @@ impl<'a> HttpApiBuilder<'a> {
|
||||
.with_mixnode(load_mixnode_details(self.mixnode_config)?)
|
||||
.with_landing_page_assets(self.mixnode_config.http.landing_page_assets_path.as_ref());
|
||||
|
||||
let router = nym_node::http::NymNodeRouter::new(config, None);
|
||||
let router = nym_node_http_api::NymNodeRouter::new(config, None, None);
|
||||
let server = router
|
||||
.with_merged(legacy::routes(self.legacy_mixnode, self.legacy_descriptor))
|
||||
.build_server(&bind_address)?
|
||||
|
||||
Reference in New Issue
Block a user