chore: LP registration adjustments (#6845)
* remove mixnet fallback for LP registration * change LP registration timeouts and introduce exchange timeout * remove fallback client construction and disable mixnet via LP registration
This commit is contained in:
committed by
GitHub
parent
de9fa97129
commit
7324bb23b6
@@ -143,7 +143,6 @@ impl RegistrationClientBuilder {
|
|||||||
config,
|
config,
|
||||||
bandwidth_controller,
|
bandwidth_controller,
|
||||||
cancel_token: self.config.cancel_token.clone(),
|
cancel_token: self.config.cancel_token.clone(),
|
||||||
fallback_client_builder: Some(self),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,13 +18,12 @@ use rand09::{CryptoRng, RngCore, SeedableRng};
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::net::TcpStream;
|
use tokio::net::TcpStream;
|
||||||
use tokio_util::sync::CancellationToken;
|
use tokio_util::sync::CancellationToken;
|
||||||
|
use tracing::warn;
|
||||||
|
|
||||||
pub struct LpBasedRegistrationClient {
|
pub struct LpBasedRegistrationClient {
|
||||||
pub(crate) config: RegistrationClientConfig,
|
pub(crate) config: RegistrationClientConfig,
|
||||||
pub(crate) bandwidth_controller: Box<dyn BandwidthTicketProvider>,
|
pub(crate) bandwidth_controller: Box<dyn BandwidthTicketProvider>,
|
||||||
pub(crate) cancel_token: CancellationToken,
|
pub(crate) cancel_token: CancellationToken,
|
||||||
// While we allow a fallback, we need to be able to build it
|
|
||||||
pub(crate) fallback_client_builder: Option<RegistrationClientBuilder>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LpBasedRegistrationClient {
|
impl LpBasedRegistrationClient {
|
||||||
@@ -162,15 +161,11 @@ impl LpBasedRegistrationClient {
|
|||||||
self.register_wg_with_rng(&mut rng).await
|
self.register_wg_with_rng(&mut rng).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn register(mut self) -> Result<RegistrationResult, RegistrationClientError> {
|
async fn register_inner(mut self) -> Result<RegistrationResult, RegistrationClientError> {
|
||||||
let fallback = self.fallback_client_builder.take();
|
|
||||||
match &self.config.mode {
|
match &self.config.mode {
|
||||||
RegistrationMode::Mixnet => {
|
RegistrationMode::Mixnet => {
|
||||||
if let Some(fallback) = fallback {
|
// mixnet registration is not supported for LP
|
||||||
register_with_fallback(fallback).await
|
Err(RegistrationClientError::UnsupportedMode)
|
||||||
} else {
|
|
||||||
Err(RegistrationClientError::UnsupportedMode)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
RegistrationMode::Wireguard => {
|
RegistrationMode::Wireguard => {
|
||||||
let lp_registration_result = self
|
let lp_registration_result = self
|
||||||
@@ -182,15 +177,9 @@ impl LpBasedRegistrationClient {
|
|||||||
// Everything went fine
|
// Everything went fine
|
||||||
Some(Ok(res)) => Ok(res),
|
Some(Ok(res)) => Ok(res),
|
||||||
|
|
||||||
// LP reg failed, try fallback if we have one
|
|
||||||
Some(Err(e)) => {
|
Some(Err(e)) => {
|
||||||
tracing::error!("LP registration failed : {e}");
|
tracing::error!("LP registration failed : {e}");
|
||||||
if let Some(fallback) = fallback {
|
Err(e)
|
||||||
tracing::info!("Registering with fallback");
|
|
||||||
register_with_fallback(fallback).await
|
|
||||||
} else {
|
|
||||||
Err(e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cancelled registration
|
// Cancelled registration
|
||||||
@@ -199,12 +188,14 @@ impl LpBasedRegistrationClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
async fn register_with_fallback(
|
pub(crate) async fn register(mut self) -> Result<RegistrationResult, RegistrationClientError> {
|
||||||
client_builder: RegistrationClientBuilder,
|
let timeout = self.config.lp_registration_config.exchange_timeout;
|
||||||
) -> Result<RegistrationResult, RegistrationClientError> {
|
tokio::time::timeout(timeout, self.register_inner())
|
||||||
// This is forcefully building a mixnet based client
|
.await
|
||||||
let fallback_client = client_builder.build_mixnet().await?;
|
.unwrap_or_else(|timeout| {
|
||||||
fallback_client.register().await
|
warn!("timed out while attempting to complete LP registration");
|
||||||
|
Err(RegistrationClientError::Timeout(timeout))
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,40 +28,43 @@ use std::time::Duration;
|
|||||||
/// - Optimize for latency over throughput (small messages)
|
/// - Optimize for latency over throughput (small messages)
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
pub struct LpRegistrationConfig {
|
pub struct LpRegistrationConfig {
|
||||||
/// TCP connection timeout (nym-102).
|
/// TCP connection timeout.
|
||||||
///
|
///
|
||||||
/// Maximum time to wait for TCP connection establishment.
|
/// Maximum time to wait for TCP connection establishment.
|
||||||
/// Default: 10 seconds.
|
/// Default: 5 seconds.
|
||||||
pub connect_timeout: Duration,
|
pub connect_timeout: Duration,
|
||||||
|
|
||||||
/// Noise protocol handshake timeout (nym-102).
|
/// KKT/PSQ protocol handshake timeout.
|
||||||
///
|
///
|
||||||
/// Maximum time to wait for Noise handshake completion (all round-trips).
|
/// Maximum time to wait for KKT/PSQ handshake completion with the entry (all round-trips).
|
||||||
/// Default: 15 seconds.
|
/// Default: 8 seconds.
|
||||||
pub handshake_timeout: Duration,
|
pub handshake_timeout: Duration,
|
||||||
|
|
||||||
/// Registration request/response timeout (nym-102).
|
/// Registration request/response timeout.
|
||||||
///
|
///
|
||||||
/// Maximum time to wait for registration request send + response receive.
|
/// Maximum time to wait for registration request send + response receive.
|
||||||
/// Includes credential verification on gateway side.
|
/// Includes credential verification on gateway side.
|
||||||
/// Default: 30 seconds.
|
/// Default: 8 seconds.
|
||||||
pub registration_timeout: Duration,
|
pub registration_timeout: Duration,
|
||||||
|
|
||||||
|
/// Maximum time for the whole exchange (handshake + registration).
|
||||||
|
/// Default: 20 seconds.
|
||||||
|
pub exchange_timeout: Duration,
|
||||||
|
|
||||||
/// Forward packet send/receive timeout.
|
/// Forward packet send/receive timeout.
|
||||||
///
|
///
|
||||||
/// Maximum time to wait for forward packet send + response receive via entry gateway.
|
/// Maximum time to wait for forward packet to get sent via entry gateway.
|
||||||
/// Covers the entire round-trip through entry to exit gateway and back.
|
/// Default: 3 seconds.
|
||||||
/// Default: 30 seconds.
|
|
||||||
pub forward_timeout: Duration,
|
pub forward_timeout: Duration,
|
||||||
|
|
||||||
/// Enable TCP_NODELAY (disable Nagle's algorithm) (nym-104).
|
/// Enable TCP_NODELAY (disable Nagle's algorithm).
|
||||||
///
|
///
|
||||||
/// When true, disables Nagle's algorithm for lower latency.
|
/// When true, disables Nagle's algorithm for lower latency.
|
||||||
/// Recommended for registration messages which are small and latency-sensitive.
|
/// Recommended for registration messages which are small and latency-sensitive.
|
||||||
/// Default: true.
|
/// Default: true.
|
||||||
pub tcp_nodelay: bool,
|
pub tcp_nodelay: bool,
|
||||||
|
|
||||||
/// TCP keepalive duration (nym-104).
|
/// TCP keepalive duration.
|
||||||
///
|
///
|
||||||
/// When Some, enables TCP keepalive with specified interval.
|
/// When Some, enables TCP keepalive with specified interval.
|
||||||
/// Since LP is registration-only with short-lived connections, keepalive is not needed.
|
/// Since LP is registration-only with short-lived connections, keepalive is not needed.
|
||||||
@@ -72,15 +75,14 @@ pub struct LpRegistrationConfig {
|
|||||||
impl Default for LpRegistrationConfig {
|
impl Default for LpRegistrationConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
// nym-102: Sane timeout defaults for real network conditions
|
connect_timeout: Duration::from_secs(5),
|
||||||
connect_timeout: Duration::from_secs(10),
|
handshake_timeout: Duration::from_secs(8),
|
||||||
handshake_timeout: Duration::from_secs(15),
|
registration_timeout: Duration::from_secs(8),
|
||||||
registration_timeout: Duration::from_secs(30),
|
exchange_timeout: Duration::from_secs(20),
|
||||||
forward_timeout: Duration::from_secs(30),
|
forward_timeout: Duration::from_secs(3),
|
||||||
|
|
||||||
// nym-104: Optimized for registration-only protocol
|
tcp_nodelay: true,
|
||||||
tcp_nodelay: true, // Lower latency for small messages
|
tcp_keepalive: None,
|
||||||
tcp_keepalive: None, // Not needed for ephemeral connections
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,10 +95,11 @@ mod tests {
|
|||||||
fn test_default_config() {
|
fn test_default_config() {
|
||||||
let config = LpRegistrationConfig::default();
|
let config = LpRegistrationConfig::default();
|
||||||
|
|
||||||
assert_eq!(config.connect_timeout, Duration::from_secs(10));
|
assert_eq!(config.connect_timeout, Duration::from_secs(5));
|
||||||
assert_eq!(config.handshake_timeout, Duration::from_secs(15));
|
assert_eq!(config.handshake_timeout, Duration::from_secs(8));
|
||||||
assert_eq!(config.registration_timeout, Duration::from_secs(30));
|
assert_eq!(config.registration_timeout, Duration::from_secs(8));
|
||||||
assert_eq!(config.forward_timeout, Duration::from_secs(30));
|
assert_eq!(config.forward_timeout, Duration::from_secs(3));
|
||||||
|
assert_eq!(config.exchange_timeout, Duration::from_secs(20));
|
||||||
assert!(config.tcp_nodelay);
|
assert!(config.tcp_nodelay);
|
||||||
assert_eq!(config.tcp_keepalive, None);
|
assert_eq!(config.tcp_keepalive, None);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user