diff --git a/common/client-core/config-types/src/lib.rs b/common/client-core/config-types/src/lib.rs index 81c47b42198..af6943738e8 100644 --- a/common/client-core/config-types/src/lib.rs +++ b/common/client-core/config-types/src/lib.rs @@ -418,6 +418,9 @@ pub struct Traffic { /// will be routed as usual, to the entry gateway, through three mix nodes, egressing /// through the exit gateway. If mix hops are disabled, traffic will be routed directly /// from the entry gateway to the exit gateway, bypassing the mix nodes. + /// + /// This overrides the `use_legacy_sphinx_format` setting as reduced mix hops + /// requires use of the updated SURB packet format. pub disable_mix_hops: bool, } diff --git a/common/client-core/src/client/real_messages_control/message_handler.rs b/common/client-core/src/client/real_messages_control/message_handler.rs index c88a6257ce6..aa921d60dc4 100644 --- a/common/client-core/src/client/real_messages_control/message_handler.rs +++ b/common/client-core/src/client/real_messages_control/message_handler.rs @@ -105,6 +105,9 @@ pub(crate) struct Config { /// will be routed as usual, to the entry gateway, through three mix nodes, egressing /// through the exit gateway. If mix hops are disabled, traffic will be routed directly /// from the entry gateway to the exit gateway, bypassing the mix nodes. + /// + /// This overrides the `use_legacy_sphinx_format` setting as reduced mix hops + /// requires use of the updated SURB packet format. disable_mix_hops: bool, /// Average delay a data packet is going to get delay at a single mixnode. @@ -159,8 +162,12 @@ impl Config { } /// Configure whether messages senders using this config should use mix hops or not when sending messages. + /// + /// This overrides the `use_legacy_sphinx_format` setting as disabled mix hops + /// requires use of the updated SURB packet format. pub fn disable_mix_hops(mut self, disable_mix_hops: bool) -> Self { self.disable_mix_hops = disable_mix_hops; + self.use_legacy_sphinx_format = false; self } } diff --git a/common/nymsphinx/anonymous-replies/src/reply_surb.rs b/common/nymsphinx/anonymous-replies/src/reply_surb.rs index 7926c976edd..6f3dd9137e0 100644 --- a/common/nymsphinx/anonymous-replies/src/reply_surb.rs +++ b/common/nymsphinx/anonymous-replies/src/reply_surb.rs @@ -56,6 +56,13 @@ impl ReplySurb { packet_size.plaintext_size() - ack_overhead - ReplySurbKeyDigestAlgorithm::output_size() - 1 } + /// Construct a ResplySurb object. Selects mix hops for the surb unique to this + /// individual construction. + /// + /// If mix hops are disabled, the route will consistency of the recipient + /// (i.e. the ingress hop) only. When `disable_mix_hops` is enabled + /// `use_legacy_surb_format` is ignored as disabled mix hops requires use of + /// the updated SURB format. // TODO: should this return `ReplySURBError` for consistency sake // or keep `NymTopologyError` because it's the only error it can actually return? pub fn construct( @@ -64,17 +71,21 @@ impl ReplySurb { average_delay: Duration, use_legacy_surb_format: bool, topology: &NymRouteProvider, - _disable_mix_hops: bool, // TODO: support SURBs with no mix hops after changes to surb format / construction + disable_mix_hops: bool, ) -> Result where R: RngCore + CryptoRng, { - let route = topology.random_route_to_egress(rng, recipient.gateway())?; + let route = if disable_mix_hops { + topology.empty_route_to_egress(recipient.gateway())? + } else { + topology.random_route_to_egress(rng, recipient.gateway())? + }; let delays = nym_sphinx_routing::generate_hop_delays(average_delay, route.len()); let destination = recipient.as_sphinx_destination(); let mut surb_material = SURBMaterial::new(route, delays, destination); - if use_legacy_surb_format { + if use_legacy_surb_format && !disable_mix_hops { surb_material = surb_material.with_version(X25519_WITH_EXPLICIT_PAYLOAD_KEYS_VERSION) } diff --git a/common/nymsphinx/src/preparer/mod.rs b/common/nymsphinx/src/preparer/mod.rs index 9466ebe716e..038f1c4b7a4 100644 --- a/common/nymsphinx/src/preparer/mod.rs +++ b/common/nymsphinx/src/preparer/mod.rs @@ -335,6 +335,9 @@ pub struct MessagePreparer { /// will be routed as usual, to the entry gateway, through three mix nodes, egressing /// through the exit gateway. If mix hops are disabled, traffic will be routed directly /// from the entry gateway to the exit gateway, bypassing the mix nodes. + /// + /// This overrides the `use_legacy_sphinx_format` setting as reduced/disabled mix hops + /// requires use of the updated SURB packet format. pub disable_mix_hops: bool, } @@ -388,7 +391,7 @@ where self.average_packet_delay, use_legacy_reply_surb_format, topology, - disabled_mix_hops, // TODO: support SURBs with no mix hops after changes to surb format / construction + disabled_mix_hops, )? .with_key_rotation(key_rotation); reply_surbs.push(reply_surb) diff --git a/common/wasm/client-core/src/config/mod.rs b/common/wasm/client-core/src/config/mod.rs index 2378b20ba41..b5b3caca521 100644 --- a/common/wasm/client-core/src/config/mod.rs +++ b/common/wasm/client-core/src/config/mod.rs @@ -201,6 +201,9 @@ pub struct TrafficWasm { /// will be routed as usual, to the entry gateway, through three mix nodes, egressing /// through the exit gateway. If mix hops are disabled, traffic will be routed directly /// from the entry gateway to the exit gateway, bypassing the mix nodes. + /// + /// This overrides the `use_legacy_sphinx_format` setting as reduced/disabeld mix hops + /// requires use of the updated SURB packet format. pub disable_mix_hops: bool, }