Actually commit the recommended changes

This commit is contained in:
Tommy Verrall
2025-10-21 18:12:38 +02:00
committed by Jędrzej Stuczyński
parent c96b73172a
commit 910c24e7da
2 changed files with 34 additions and 20 deletions
@@ -217,8 +217,8 @@ pub struct BaseClientBuilder<C, S: MixnetClientStorage> {
client_store: S,
dkg_query_client: Option<C>,
// Optional network details for domain fronting support
network_details: Option<NymNetworkDetails>,
// Optional API URLs for domain fronting support
nym_api_urls: Option<Vec<nym_network_defaults::ApiUrl>>,
wait_for_gateway: bool,
custom_topology_provider: Option<Box<dyn TopologyProvider + Send + Sync>>,
@@ -249,7 +249,7 @@ where
config: base_config,
client_store,
dkg_query_client,
network_details: None,
nym_api_urls: None,
wait_for_gateway: false,
custom_topology_provider: None,
custom_gateway_transceiver: None,
@@ -272,16 +272,26 @@ where
self
}
/// Set network details for domain fronting support.
/// Set Nym API URLs for domain fronting support.
///
/// When provided, the client will use network details (which include front_hosts)
/// When provided, the client will use these API URLs (which include front_hosts)
/// to construct HTTP clients with domain fronting enabled.
#[must_use]
pub fn with_network_details(mut self, network_details: NymNetworkDetails) -> Self {
self.network_details = Some(network_details);
pub fn with_nym_api_urls(mut self, nym_api_urls: Vec<nym_network_defaults::ApiUrl>) -> Self {
self.nym_api_urls = Some(nym_api_urls);
self
}
/// Set network details for domain fronting support (deprecated).
///
/// Use `with_nym_api_urls()` instead to explicitly pass the API URLs.
#[must_use]
#[deprecated(note = "use explicit Self::with_nym_api_urls instead")]
pub fn with_network_details(self, network_details: NymNetworkDetails) -> Self {
let nym_api_urls = network_details.nym_api_urls.unwrap_or_default();
self.with_nym_api_urls(nym_api_urls)
}
#[must_use]
pub fn with_forget_me(mut self, forget_me: &ForgetMe) -> Self {
self.config.debug.forget_me = *forget_me;
@@ -882,25 +892,25 @@ where
}
fn construct_nym_api_client(
network_details: Option<&NymNetworkDetails>,
nym_api_urls: Option<&Vec<nym_network_defaults::ApiUrl>>,
config: &Config,
user_agent: Option<UserAgent>,
) -> Result<nym_http_api_client::Client, ClientCoreError> {
tracing::debug!(
"construct_nym_api_client called with network_details: {}",
network_details.is_some()
"construct_nym_api_client called with nym_api_urls: {}",
nym_api_urls.is_some()
);
// If network details are provided, use new_with_fronted_urls() which handles domain fronting
if let Some(network_details) = network_details {
// If API URLs are provided, use new_with_fronted_urls() which handles domain fronting
if let Some(nym_api_urls) = nym_api_urls {
tracing::info!(
"Building nym-api client from network details (with domain fronting support)"
"Building nym-api client from provided URLs (with domain fronting support)"
);
let urls = network_details.nym_api_urls.clone().unwrap_or_default();
let mut builder = nym_http_api_client::ClientBuilder::new_with_fronted_urls(urls)
.map_err(ClientCoreError::from)?
.with_retries(DEFAULT_NYM_API_RETRIES);
let mut builder =
nym_http_api_client::ClientBuilder::new_with_fronted_urls(nym_api_urls.clone())
.map_err(ClientCoreError::from)?
.with_retries(DEFAULT_NYM_API_RETRIES);
if let Some(user_agent) = user_agent {
builder = builder.with_user_agent(user_agent);
@@ -1008,7 +1018,7 @@ where
.map(|client| BandwidthController::new(credential_store, client));
let nym_api_client = Self::construct_nym_api_client(
self.network_details.as_ref(),
self.nym_api_urls.as_ref(),
&self.config,
self.user_agent.clone(),
)?;
+6 -2
View File
@@ -707,7 +707,7 @@ where
.as_base_client_config(nyxd_endpoints, nym_api_endpoints.clone());
tracing::debug!(
"SDK: Passing network_details to BaseClientBuilder (has {} nym_api_urls)",
"SDK: Passing nym_api_urls to BaseClientBuilder (has {} nym_api_urls)",
self.config
.network_details
.nym_api_urls
@@ -718,12 +718,16 @@ where
let mut base_builder: BaseClientBuilder<_, _> =
BaseClientBuilder::new(base_config, self.storage, self.dkg_query_client)
.with_network_details(self.config.network_details.clone())
.with_wait_for_gateway(self.wait_for_gateway)
.with_forget_me(&self.forget_me)
.with_remember_me(&self.remember_me)
.with_derivation_material(self.derivation_material);
// Add nym_api_urls if available in network_details
if let Some(nym_api_urls) = self.config.network_details.nym_api_urls.clone() {
base_builder = base_builder.with_nym_api_urls(nym_api_urls);
}
if let Some(user_agent) = self.user_agent {
base_builder = base_builder.with_user_agent(user_agent);
}