Domain fronting integration (#5974)
* feat: unify HTTP client creation and enable domain fronting Enhanced the base nym_http_api_client to reduce fragmentation and enable domain fronting: - Added SerializationFormat enum for explicit JSON/bincode choice (no auto-detection) - Added from_network() method to create clients from NymNetworkDetails with domain fronting - Added with_bincode() builder method for explicit serialization configuration - Set Accept header based on serialization preference - Added deprecation paths for NymApiClient wrapper and nym_api::Client re-export - Enabled domain fronting support via network defaults feature This is part of a broader effort to consolidate HTTP client implementations across the codebase, reducing ~500 lines of wrapper code and providing automatic domain fronting for censorship resistance. * feat: migrate NymApiClient usage to unified HTTP client - Wire up domain fronting configuration in NymNetworkDetails - Implement NymApiClientExt trait for base nym_http_api_client::Client - Migrate direct NymApiClient usage in multiple components: - nym-network-monitor - verloc measurements - connection tester - coconut/ecash client - validator rewarder - Add Copy derive to ApiUrlConst to enable iteration - Update error handling and Display implementations This enables automatic domain fronting for all Nym API calls via the configured CDN front hosts. * fix: resolve all compilation errors after NymApiClient migration - Add missing nym-http-api-client dependencies to multiple crates - Add NymApiClientExt trait imports where needed - Fix type mismatches from NymApiClient to unified Client - Add error conversions for NymAPIError in various error enums - Implement missing trait methods (get_current_rewarded_set, get_all_basic_nodes_with_metadata, get_all_described_nodes) - Fix type conversions for RewardedSetResponse in network monitor - Update all API client instantiation to use new unified HTTP client * feat: complete migration to unified HTTP client and fix all compilation errors - Added missing NymApiClientExt trait methods (get_all_expanded_nodes, change_base_urls) - Fixed all compilation errors across the workspace - Updated nym-node to use unified client instead of deprecated NymApiClient - Fixed type conversions for RewardedSetResponse → EpochRewardedSet - Added nym-http-api-client dependency where needed - Updated all examples and documentation to use new client API * fix: provide all API URLs for automatic failover in endpoint rotation Previously, when rotating API endpoints, only a single URL was provided to the HTTP client, defeating the purpose of having multiple URLs for resilience. Changes: - NymApiTopologyProvider now provides all URLs in rotated order when switching endpoints - NymApisClient similarly provides all URLs starting from the working endpoint - Added clarifying comments for broadcast/exhaustive query methods where single URLs are intentionally used - This enables the HTTP client's built-in failover mechanism while maintaining endpoint rotation behavior The fix ensures that if the primary endpoint fails, the client can automatically failover to alternative endpoints without manual intervention, improving overall network resilience. * Update common/client-core/src/client/base_client/mod.rs Co-authored-by: Jędrzej Stuczyński <jedrzej.stuczynski@gmail.com> * Remove error generics, address PR comments * Explicit warning on missing fronting configuration * Assorted CI fixes * Registry proc-macro * Rename macro * Syn workspace version * Where do we need to put inventory * Ergonomics and call sites, incept the builder * fix: Address critical issues in client configuration registry implementation - Fixed HeaderMapInit parsing bug that would cause compilation errors - Added comprehensive documentation with usage examples and DSL reference - Improved error handling with better error messages for invalid headers - Added test coverage for both macro and registry functionality - Added debug inspection capabilities for registered configurations - Fixed module name conflicts in tests by using separate modules All tests now passing: - 7 macro tests validating DSL parsing and code generation - 4 registry tests verifying configuration collection and application * Use default value for the ports until api is deployed * Feature/improved http error (#6025) * use display impl for urls * feat: attempt to add more details to reqwest errors * temporarily restored GenericRequestFailure variant * another restoration * cleanup * Some debug tooling, and default timeout fix * Fix user-agent override * Fix various wasm things --------- Co-authored-by: Jędrzej Stuczyński <jedrzej.stuczynski@gmail.com> Co-authored-by: Bogdan-Ștefan Neacşu <bogdan@nymtech.net>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
// Copyright 2024 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::vpn_api_client::NymVpnApiClientError;
|
||||
use nym_http_api_client::HttpClientError;
|
||||
use thiserror::Error;
|
||||
use wasm_utils::wasm_error;
|
||||
|
||||
@@ -16,7 +16,7 @@ pub enum ZkNymError {
|
||||
#[error("failed to contact the vpn api")]
|
||||
HttpClientFailure {
|
||||
#[from]
|
||||
source: NymVpnApiClientError,
|
||||
source: Box<HttpClientError>,
|
||||
},
|
||||
#[error("the provided shares and issuers are not from the same epoch! {shares} and {issuers}")]
|
||||
InconsistentEpochId { shares: u64, issuers: u64 },
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
// Copyright 2024 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use super::NymVpnApiClientError;
|
||||
use crate::error::ZkNymError;
|
||||
use crate::vpn_api_client::types::{
|
||||
AttributesResponse, MasterVerificationKeyResponse, PartialVerificationKeysResponse,
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
pub use nym_http_api_client::Client;
|
||||
use nym_http_api_client::{parse_response, ApiClient, IntoUrl, PathSegments, NO_PARAMS};
|
||||
use nym_http_api_client::{
|
||||
parse_response, ApiClient, HttpClientError, IntoUrl, PathSegments, NO_PARAMS,
|
||||
};
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
#[allow(dead_code)]
|
||||
@@ -23,9 +23,11 @@ pub fn new_client(
|
||||
bearer_token: impl Into<String>,
|
||||
) -> Result<VpnApiClient, ZkNymError> {
|
||||
Ok(VpnApiClient {
|
||||
inner: Client::builder(base_url)?
|
||||
inner: Client::builder(base_url)
|
||||
.map_err(Box::new)?
|
||||
.with_user_agent(format!("nym-wasm-znym-lib/{}", env!("CARGO_PKG_VERSION")))
|
||||
.build()?,
|
||||
.build()
|
||||
.map_err(Box::new)?,
|
||||
bearer_token: bearer_token.into(),
|
||||
})
|
||||
}
|
||||
@@ -34,13 +36,11 @@ pub fn new_client(
|
||||
#[allow(dead_code)]
|
||||
#[async_trait(?Send)]
|
||||
pub trait NymVpnApiClient {
|
||||
async fn simple_get<T>(&self, path: PathSegments<'_>) -> Result<T, NymVpnApiClientError>
|
||||
async fn simple_get<T>(&self, path: PathSegments<'_>) -> Result<T, HttpClientError>
|
||||
where
|
||||
T: DeserializeOwned;
|
||||
|
||||
async fn get_prehashed_public_attributes(
|
||||
&self,
|
||||
) -> Result<AttributesResponse, NymVpnApiClientError> {
|
||||
async fn get_prehashed_public_attributes(&self) -> Result<AttributesResponse, HttpClientError> {
|
||||
self.simple_get(&[
|
||||
"/api",
|
||||
"/v1",
|
||||
@@ -52,7 +52,7 @@ pub trait NymVpnApiClient {
|
||||
|
||||
async fn get_partial_verification_keys(
|
||||
&self,
|
||||
) -> Result<PartialVerificationKeysResponse, NymVpnApiClientError> {
|
||||
) -> Result<PartialVerificationKeysResponse, HttpClientError> {
|
||||
self.simple_get(&[
|
||||
"/api",
|
||||
"/v1",
|
||||
@@ -64,7 +64,7 @@ pub trait NymVpnApiClient {
|
||||
|
||||
async fn get_master_verification_key(
|
||||
&self,
|
||||
) -> Result<MasterVerificationKeyResponse, NymVpnApiClientError> {
|
||||
) -> Result<MasterVerificationKeyResponse, HttpClientError> {
|
||||
self.simple_get(&[
|
||||
"/api",
|
||||
"/v1",
|
||||
@@ -77,13 +77,13 @@ pub trait NymVpnApiClient {
|
||||
|
||||
#[async_trait(?Send)]
|
||||
impl NymVpnApiClient for VpnApiClient {
|
||||
async fn simple_get<T>(&self, path: PathSegments<'_>) -> Result<T, NymVpnApiClientError>
|
||||
async fn simple_get<T>(&self, path: PathSegments<'_>) -> Result<T, HttpClientError>
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
let req = self
|
||||
.inner
|
||||
.create_get_request(path, NO_PARAMS)
|
||||
.create_get_request(path, NO_PARAMS)?
|
||||
.bearer_auth(&self.bearer_token)
|
||||
.send();
|
||||
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
// Copyright 2024 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::vpn_api_client::types::ErrorResponse;
|
||||
use nym_http_api_client::HttpClientError;
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) mod client;
|
||||
|
||||
pub mod types;
|
||||
|
||||
pub type NymVpnApiClientError = HttpClientError<ErrorResponse>;
|
||||
|
||||
Reference in New Issue
Block a user