Files
nym/nym-node/nym-node-requests/src/api/client.rs
T
Bogdan-Ștefan Neacşu ffb4457427 Feature/wg gateway data on handshake init (#4057)
* Return wg gateway data on handshake init

* Add wg register to gateway api client

* Remove socket addr and return just wg port
2023-10-27 13:40:42 +03:00

60 lines
2.1 KiB
Rust

// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use crate::api::v1::gateway::models::WebSockets;
use crate::api::v1::node::models::SignedHostInformation;
use crate::api::ErrorResponse;
use crate::routes;
use async_trait::async_trait;
use http_api_client::{ApiClient, HttpClientError};
use nym_bin_common::build_information::BinaryBuildInformationOwned;
use nym_wireguard_types::{ClientMessage, ClientRegistrationResponse};
use crate::api::v1::health::models::NodeHealth;
pub use http_api_client::Client;
pub type NymNodeApiClientError = HttpClientError<ErrorResponse>;
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
pub trait NymNodeApiClientExt: ApiClient {
async fn get_health(&self) -> Result<NodeHealth, NymNodeApiClientError> {
self.get_json_from(routes::api::v1::health_absolute()).await
}
async fn get_host_information(&self) -> Result<SignedHostInformation, NymNodeApiClientError> {
self.get_json_from(routes::api::v1::host_info_absolute())
.await
}
async fn get_build_information(
&self,
) -> Result<BinaryBuildInformationOwned, NymNodeApiClientError> {
self.get_json_from(routes::api::v1::build_info_absolute())
.await
}
// TODO: implement calls for other endpoints; for now I only care about the wss
async fn get_mixnet_websockets(&self) -> Result<WebSockets, NymNodeApiClientError> {
self.get_json_from(
routes::api::v1::gateway::client_interfaces::mixnet_websockets_absolute(),
)
.await
}
async fn post_gateway_register_client(
&self,
client_message: &ClientMessage,
) -> Result<ClientRegistrationResponse, NymNodeApiClientError> {
self.post_json_data_to(
routes::api::v1::gateway::client_interfaces::wireguard::client_absolute(),
client_message,
)
.await
}
}
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
impl NymNodeApiClientExt for Client {}