Files
nym/nym-registration-client/src/error.rs
T
Simon Wicky 88a4633bc4 [LP fix] Registration client with fallback (#6419)
* don't start mixnet client for lp reg, with fallback

* tweaks

* add logging
2026-02-05 10:51:37 +01:00

145 lines
5.1 KiB
Rust

// Copyright 2025 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: GPL-3.0-only
#[derive(thiserror::Error, Debug)]
pub enum RegistrationClientError {
#[error("trying to register in mixnet mode with LP and no fallback. This shouldn't happen")]
UnsupportedMode,
#[error("failed to build mixnet client")]
BuildMixnetClient(#[source] Box<nym_sdk::Error>),
#[error("failed to initialize storage")]
StorageInitialization(#[source] Box<nym_sdk::Error>),
#[error("failed to connect to mixnet")]
ConnectToMixnet(#[source] Box<nym_sdk::Error>),
#[error("failed to connect to ip packet router")]
ConnectToIpPacketRouter(#[source] nym_ip_packet_client::Error),
#[error("the selected node does not have an IP packet router : {node_id}")]
NoIpPacketRouterAddress { node_id: String },
#[error(
"wireguard authentication is not possible due to one of the gateways not running the authenticator process: {node_id} "
)]
AuthenticationNotPossible { node_id: String },
#[error("Failed to create nyxd client config")]
FailedToCreateNyxdClientConfig(nym_validator_client::nyxd::error::NyxdError),
#[error("failed to parse nyxd_url")]
InvalidNyxdUrl,
#[error("Failed to connect using nyxd client")]
FailedToConnectUsingNyxdClient(nym_validator_client::nyxd::error::NyxdError),
#[error("connection cancelled")]
Cancelled,
#[error("timeout connecting the mixnet client")]
Timeout(#[from] tokio::time::error::Elapsed),
#[error(
"failed to register wireguard with the gateway for {gateway_id}, no credential was sent"
)]
WireguardEntryRegistration {
gateway_id: String,
authenticator_address: Box<nym_sdk::mixnet::Recipient>,
#[source]
source: Box<nym_authenticator_client::AuthenticationClientError>,
},
#[error(
"failed to register wireguard with the gateway for {gateway_id}, no credential was sent"
)]
WireguardExitRegistration {
gateway_id: String,
authenticator_address: Box<nym_sdk::mixnet::Recipient>,
#[source]
source: Box<nym_authenticator_client::AuthenticationClientError>,
},
#[error(
"failed to register wireguard with the gateway for {gateway_id}, a credential was sent"
)]
WireguardEntryRegistrationCredentialSent {
gateway_id: String,
authenticator_address: Box<nym_sdk::mixnet::Recipient>,
#[source]
source: Box<nym_authenticator_client::AuthenticationClientError>,
},
#[error(
"failed to register wireguard with the gateway for {gateway_id}, a credential was sent"
)]
WireguardExitRegistrationCredentialSent {
gateway_id: String,
authenticator_address: Box<nym_sdk::mixnet::Recipient>,
#[source]
source: Box<nym_authenticator_client::AuthenticationClientError>,
},
#[error("LP registration not possible for gateway {node_id}: no LP address available")]
LpRegistrationNotPossible { node_id: String },
#[error("failed to register LP with entry gateway {gateway_id} at {lp_address}: {source}")]
EntryGatewayRegisterLp {
gateway_id: String,
lp_address: std::net::SocketAddr,
#[source]
source: Box<crate::lp_client::LpClientError>,
},
#[error("failed to register LP with exit gateway {gateway_id} at {lp_address}: {source}")]
ExitGatewayRegisterLp {
gateway_id: String,
lp_address: std::net::SocketAddr,
#[source]
source: Box<crate::lp_client::LpClientError>,
},
}
impl RegistrationClientError {
pub fn from_authenticator_error(
error: nym_authenticator_client::RegistrationError,
gateway_id: String,
authenticator_address: nym_sdk::mixnet::Recipient,
entry: bool,
) -> Self {
match error {
nym_authenticator_client::RegistrationError::NoCredentialSent(source) => {
if entry {
Self::WireguardEntryRegistration {
gateway_id,
authenticator_address: Box::new(authenticator_address),
source: Box::new(source),
}
} else {
Self::WireguardExitRegistration {
gateway_id,
authenticator_address: Box::new(authenticator_address),
source: Box::new(source),
}
}
}
nym_authenticator_client::RegistrationError::CredentialSent { source } => {
if entry {
Self::WireguardEntryRegistrationCredentialSent {
gateway_id,
authenticator_address: Box::new(authenticator_address),
source: Box::new(source),
}
} else {
Self::WireguardExitRegistrationCredentialSent {
gateway_id,
authenticator_address: Box::new(authenticator_address),
source: Box::new(source),
}
}
}
}
}
}