diff --git a/common/client-core/src/cli_helpers/client_add_gateway.rs b/common/client-core/src/cli_helpers/client_add_gateway.rs index a7f9f85d10..e87f73ff0f 100644 --- a/common/client-core/src/cli_helpers/client_add_gateway.rs +++ b/common/client-core/src/cli_helpers/client_add_gateway.rs @@ -139,6 +139,8 @@ where let gateway_setup = GatewaySetup::New { specification: selection_spec, available_gateways, + #[cfg(unix)] + connection_fd_callback: None, }; let init_details = diff --git a/common/client-core/src/cli_helpers/client_init.rs b/common/client-core/src/cli_helpers/client_init.rs index ef7da1ddf1..40ad1caa28 100644 --- a/common/client-core/src/cli_helpers/client_init.rs +++ b/common/client-core/src/cli_helpers/client_init.rs @@ -187,6 +187,8 @@ where let gateway_setup = GatewaySetup::New { specification: selection_spec, available_gateways, + #[cfg(unix)] + connection_fd_callback: None, }; let init_details = diff --git a/common/client-core/src/init/helpers.rs b/common/client-core/src/init/helpers.rs index f29983bbf7..9d8d669bc1 100644 --- a/common/client-core/src/init/helpers.rs +++ b/common/client-core/src/init/helpers.rs @@ -11,6 +11,8 @@ use nym_topology::node::RoutingNode; use nym_validator_client::client::IdentityKeyRef; use nym_validator_client::UserAgent; use rand::{seq::SliceRandom, Rng}; +#[cfg(unix)] +use std::os::fd::RawFd; use std::{sync::Arc, time::Duration}; use tungstenite::Message; use url::Url; @@ -313,9 +315,15 @@ pub(super) async fn register_with_gateway( gateway_id: identity::PublicKey, gateway_listener: Url, our_identity: Arc, + #[cfg(unix)] connection_fd_callback: Option>, ) -> Result { - let mut gateway_client = - GatewayClient::new_init(gateway_listener, gateway_id, our_identity.clone()); + let mut gateway_client = GatewayClient::new_init( + gateway_listener, + gateway_id, + our_identity.clone(), + #[cfg(unix)] + connection_fd_callback, + ); gateway_client.establish_connection().await.map_err(|err| { log::warn!("Failed to establish connection with gateway!"); diff --git a/common/client-core/src/init/mod.rs b/common/client-core/src/init/mod.rs index bbe27769ee..105fd0a457 100644 --- a/common/client-core/src/init/mod.rs +++ b/common/client-core/src/init/mod.rs @@ -23,6 +23,8 @@ use nym_topology::node::RoutingNode; use rand::rngs::OsRng; use rand::{CryptoRng, RngCore}; use serde::Serialize; +#[cfg(unix)] +use std::{os::fd::RawFd, sync::Arc}; pub mod helpers; pub mod types; @@ -53,6 +55,7 @@ async fn setup_new_gateway( details_store: &D, selection_specification: GatewaySelectionSpecification, available_gateways: Vec, + #[cfg(unix)] connection_fd_callback: Option>, ) -> Result where K: KeyStore, @@ -108,9 +111,14 @@ where // if we're using a 'normal' gateway setup, do register let our_identity = client_keys.identity_keypair(); - let registration = - helpers::register_with_gateway(gateway_id, gateway_listener.clone(), our_identity) - .await?; + let registration = helpers::register_with_gateway( + gateway_id, + gateway_listener.clone(), + our_identity, + #[cfg(unix)] + connection_fd_callback, + ) + .await?; ( GatewayDetails::new_remote( gateway_id, @@ -203,9 +211,19 @@ where GatewaySetup::New { specification, available_gateways, + #[cfg(unix)] + connection_fd_callback, } => { log::debug!("GatewaySetup::New with spec: {specification:?}"); - setup_new_gateway(key_store, details_store, specification, available_gateways).await + setup_new_gateway( + key_store, + details_store, + specification, + available_gateways, + #[cfg(unix)] + connection_fd_callback, + ) + .await } GatewaySetup::ReuseConnection { authenticated_ephemeral_client, diff --git a/common/client-core/src/init/types.rs b/common/client-core/src/init/types.rs index 1383022561..7b163f5478 100644 --- a/common/client-core/src/init/types.rs +++ b/common/client-core/src/init/types.rs @@ -18,6 +18,8 @@ use nym_validator_client::client::IdentityKey; use nym_validator_client::nyxd::AccountId; use serde::Serialize; use std::fmt::{Debug, Display}; +#[cfg(unix)] +use std::os::fd::RawFd; use std::sync::Arc; use time::OffsetDateTime; use url::Url; @@ -208,6 +210,10 @@ pub enum GatewaySetup { // TODO: seems to be a bit inefficient to pass them by value available_gateways: Vec, + + /// Callback useful for allowing initial connection to gateway + #[cfg(unix)] + connection_fd_callback: Option>, }, ReuseConnection { @@ -231,6 +237,8 @@ impl Debug for GatewaySetup { GatewaySetup::New { specification, available_gateways, + #[cfg(unix)] + connection_fd_callback: _, } => f .debug_struct("GatewaySetup::New") .field("specification", specification) @@ -270,6 +278,8 @@ impl GatewaySetup { additional_data: None, }, available_gateways: vec![], + #[cfg(unix)] + connection_fd_callback: None, } } diff --git a/common/client-libs/gateway-client/src/client/mod.rs b/common/client-libs/gateway-client/src/client/mod.rs index 88a55dd850..59473142fd 100644 --- a/common/client-libs/gateway-client/src/client/mod.rs +++ b/common/client-libs/gateway-client/src/client/mod.rs @@ -1065,6 +1065,7 @@ impl GatewayClient { gateway_listener: Url, gateway_identity: identity::PublicKey, local_identity: Arc, + #[cfg(unix)] connection_fd_callback: Option>, ) -> Self { log::trace!("Initialising gateway client"); use futures::channel::mpsc; @@ -1090,7 +1091,7 @@ impl GatewayClient { stats_reporter: ClientStatsSender::new(None, task_client.clone()), negotiated_protocol: None, #[cfg(unix)] - connection_fd_callback: None, + connection_fd_callback, task_client, } } diff --git a/sdk/rust/nym-sdk/src/mixnet/client.rs b/sdk/rust/nym-sdk/src/mixnet/client.rs index 6b5076d647..5905b6429e 100644 --- a/sdk/rust/nym-sdk/src/mixnet/client.rs +++ b/sdk/rust/nym-sdk/src/mixnet/client.rs @@ -543,6 +543,8 @@ where Ok(GatewaySetup::New { specification: selection_spec, available_gateways, + #[cfg(unix)] + connection_fd_callback: self.connection_fd_callback.clone(), }) }