Skip to content

Commit

Permalink
forward dns resolution errors for downstream handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jmwample committed Jan 27, 2025
1 parent 91a8687 commit 81fced6
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 18 deletions.
3 changes: 3 additions & 0 deletions common/client-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ pub enum ClientCoreError {
#[error("Invalid URL: {0}")]
InvalidUrl(String),

#[error("resolution failed: {0}")]
ResolutionFailed(#[from] nym_http_api_client::HickoryDnsError),

#[error("no gateways on network")]
NoGatewaysOnNetwork,

Expand Down
10 changes: 2 additions & 8 deletions common/client-core/src/init/websockets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::error::ClientCoreError;
use nym_http_api_client::HickoryDnsResolver;
use tokio::net::TcpStream;
use tokio_tungstenite::{MaybeTlsStream, WebSocketStream};
use tungstenite::{error::UrlError, handshake::client::Response};
use tungstenite::handshake::client::Response;
use url::{Host, Url};

use std::net::SocketAddr;
Expand All @@ -29,13 +29,7 @@ pub(crate) async fn connect_async(
// Do a DNS lookup for the domain using our custom DNS resolver
resolver
.resolve_str(domain)
.await
.map_err(|_| {
// failed to resolve
ClientCoreError::GatewayConnectionFailure {
source: UrlError::NoPathOrQuery.into(),
}
})?
.await?
.into_iter()
.map(|a| SocketAddr::new(a, port))
.collect()
Expand Down
11 changes: 2 additions & 9 deletions common/client-libs/gateway-client/src/client/websockets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::error::GatewayClientError;
use nym_http_api_client::HickoryDnsResolver;
use tokio::net::TcpStream;
use tokio_tungstenite::{MaybeTlsStream, WebSocketStream};
use tungstenite::{error::UrlError, handshake::client::Response};
use tungstenite::handshake::client::Response;
use url::{Host, Url};

use std::net::SocketAddr;
Expand All @@ -30,14 +30,7 @@ pub(crate) async fn connect_async(
// Do a DNS lookup for the domain using our custom DNS resolver
resolver
.resolve_str(domain)
.await
.map_err(|_| {
// failed to resolve
GatewayClientError::NetworkConnectionFailed {
address: endpoint.to_owned(),
source: UrlError::NoPathOrQuery.into(),
}
})?
.await?
.into_iter()
.map(|a| SocketAddr::new(a, port))
.collect()
Expand Down
3 changes: 3 additions & 0 deletions common/client-libs/gateway-client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ pub enum GatewayClientError {
#[error("Invalid URL: {0}")]
InvalidUrl(String),

#[error("resolution failed: {0}")]
ResolutionFailed(#[from] nym_http_api_client::HickoryDnsError),

#[error("No shared key was provided or obtained")]
NoSharedKeyAvailable,

Expand Down
1 change: 1 addition & 0 deletions common/http-api-client/src/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct SocketAddrs {

#[derive(Debug, thiserror::Error)]
#[error("hickory-dns resolver error: {hickory_error}")]
/// Error occurring while resolving a hostname into an IP address.
pub struct HickoryDnsError {
#[from]
hickory_error: ResolveError,
Expand Down
2 changes: 1 addition & 1 deletion common/http-api-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub use user_agent::UserAgent;
#[cfg(not(target_arch = "wasm32"))]
mod dns;
#[cfg(not(target_arch = "wasm32"))]
pub use dns::HickoryDnsResolver;
pub use dns::{HickoryDnsResolver, HickoryDnsError};

// The timeout is relatively high as we are often making requests over the mixnet, where latency is
// high and chatty protocols take a while to complete.
Expand Down

0 comments on commit 81fced6

Please sign in to comment.