Skip to content
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
52 changes: 45 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ members = [
"common/wasm/storage",
"common/wasm/utils",
"common/wireguard",
"common/wireguard-private-metadata",
"common/wireguard-private-metadata/client",
"common/wireguard-private-metadata/server",
"common/wireguard-private-metadata/shared",
"common/wireguard-private-metadata/tests",
"common/wireguard-types",
"common/zulip-client",
"documentation/autodoc",
Expand Down
1 change: 1 addition & 0 deletions common/http-api-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
//! ```
#![warn(missing_docs)]

pub use reqwest::ClientBuilder as ReqwestClientBuilder;
pub use reqwest::StatusCode;

use crate::path::RequestPath;
Expand Down
18 changes: 18 additions & 0 deletions common/wireguard-private-metadata/client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "nym-wireguard-private-metadata-client"
version = "1.0.0"
authors.workspace = true
repository.workspace = true
homepage.workspace = true
documentation.workspace = true
edition.workspace = true
license.workspace = true

[dependencies]
async-trait = { workspace = true }
tracing = { workspace = true }
nym-http-api-client = { path = "../../http-api-client" }
nym-wireguard-private-metadata-shared = { path = "../shared" }

[lints]
workspace = true
58 changes: 58 additions & 0 deletions common/wireguard-private-metadata/client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2025 - Nym Technologies SA <[email protected]>
// SPDX-License-Identifier: Apache-2.0

use async_trait::async_trait;
use tracing::instrument;

use nym_http_api_client::{ApiClient, Client, HttpClientError, NO_PARAMS};

use nym_wireguard_private_metadata_shared::{
routes, Version, {ErrorResponse, Request, Response},
};

pub type WireguardMetadataApiClientError = HttpClientError<ErrorResponse>;

#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
pub trait WireguardMetadataApiClient: ApiClient {
#[instrument(level = "debug", skip(self))]
async fn version(&self) -> Result<Version, WireguardMetadataApiClientError> {
let version: u64 = self
.get_json(
&[routes::V1_API_VERSION, routes::BANDWIDTH, routes::VERSION],
NO_PARAMS,
)
.await?;
Ok(version.into())
}

#[instrument(level = "debug", skip(self))]
async fn available_bandwidth(
&self,
request_body: &Request,
) -> Result<Response, WireguardMetadataApiClientError> {
self.post_json(
&[routes::V1_API_VERSION, routes::BANDWIDTH, routes::AVAILABLE],
NO_PARAMS,
request_body,
)
.await
}

#[instrument(level = "debug", skip(self, request_body))]
async fn topup_bandwidth(
&self,
request_body: &Request,
) -> Result<Response, WireguardMetadataApiClientError> {
self.post_json(
&[routes::V1_API_VERSION, routes::BANDWIDTH, routes::TOPUP],
NO_PARAMS,
request_body,
)
.await
}
}

#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
impl WireguardMetadataApiClient for Client {}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nym-wireguard-private-metadata"
version = "0.1.0"
name = "nym-wireguard-private-metadata-server"
version = "1.0.0"
authors.workspace = true
repository.workspace = true
homepage.workspace = true
Expand All @@ -11,11 +11,7 @@ license.workspace = true
[dependencies]
anyhow = { workspace = true }
axum = { workspace = true, features = ["tokio", "macros"] }
bincode = { workspace = true }
futures = { workspace = true }
schemars = { workspace = true, features = ["preserve_order"] }
serde = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["rt-multi-thread", "net", "io-util"] }
tokio-util = { workspace = true }
tower-http = { workspace = true, features = [
Expand All @@ -27,17 +23,21 @@ tower-http = { workspace = true, features = [
"compression-zstd",
] }
utoipa = { workspace = true, features = ["axum_extras", "time"] }
utoipauto = { workspace = true }
utoipa-swagger-ui = { workspace = true, features = ["axum"] }

nym-credentials-interface = { path = "../credentials-interface" }
nym-credential-verification = { path = "../credential-verification" }
nym-http-api-common = { path = "../http-api-common", features = [
nym-credentials-interface = { path = "../../credentials-interface" }
nym-credential-verification = { path = "../../credential-verification" }
nym-http-api-common = { path = "../../http-api-common", features = [
"middleware",
"utoipa",
"output",
] }
nym-wireguard = { path = "../wireguard" }
nym-wireguard = { path = "../../wireguard" }
nym-wireguard-private-metadata-shared = { path = "../shared" }

[dev-dependencies]
async-trait = { workspace = true }


[lints]
workspace = true
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

use utoipa::OpenApi;

use crate::models::{AvailableBandwidthResponse, TopUpRequest};
use nym_wireguard_private_metadata_shared::{Request, Response};

#[derive(OpenApi)]
#[openapi(
info(title = "Nym Wireguard Private Metadata"),
tags(),
components(schemas(AvailableBandwidthResponse, TopUpRequest))
components(schemas(Request, Response))
)]
pub(crate) struct ApiDoc;
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn setup_cors() -> CorsLayer {
}

pub struct RouterWithState {
router: Router,
pub router: Router,
}

impl RouterWithState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ use std::net::IpAddr;

use nym_credentials_interface::CredentialSpendingData;

use crate::{
error::MetadataError,
models::{latest, AvailableBandwidthResponse},
transceiver::PeerControllerTransceiver,
};
use crate::transceiver::PeerControllerTransceiver;
use nym_wireguard_private_metadata_shared::error::MetadataError;

#[derive(Clone, axum::extract::FromRef)]
pub struct AppState {
Expand All @@ -21,23 +18,18 @@ impl AppState {
Self { transceiver }
}

pub(crate) async fn available_bandwidth(
&self,
ip: IpAddr,
) -> Result<AvailableBandwidthResponse, MetadataError> {
let value = self.transceiver.query_bandwidth(ip).await?;
let res = latest::InnerAvailableBandwidthResponse::new(value).try_into()?;
Ok(res)
pub async fn available_bandwidth(&self, ip: IpAddr) -> Result<i64, MetadataError> {
self.transceiver.query_bandwidth(ip).await
}

pub(crate) async fn topup_bandwidth(
// Top up with a credential and return the afterwards available bandwidth
pub async fn topup_bandwidth(
&self,
ip: IpAddr,
credential: CredentialSpendingData,
) -> Result<(), MetadataError> {
) -> Result<i64, MetadataError> {
self.transceiver
.topup_bandwidth(ip, Box::new(credential))
.await?;
Ok(())
.await
}
}
13 changes: 13 additions & 0 deletions common/wireguard-private-metadata/server/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2025 - Nym Technologies SA <[email protected]>
// SPDX-License-Identifier: Apache-2.0

mod http;
mod network;
mod transceiver;

pub use http::{
router::{ApiHttpServer, RouterBuilder, RouterWithState},
state::AppState,
ShutdownHandles,
};
pub use transceiver::PeerControllerTransceiver;
Loading
Loading