From 7ebacde1fc900eb97c31a217404fa36847b0ced0 Mon Sep 17 00:00:00 2001 From: durch Date: Tue, 16 Dec 2025 21:06:16 +0100 Subject: [PATCH] Add negotiated_version field to LpSession Add AtomicU8 field to store the protocol version from handshake packet headers. Includes getter and setter methods for future version negotiation and compatibility checks. - negotiated_version() returns current version (defaults to 1) - set_negotiated_version() allows setting during handshake - Subsessions inherit version 1 (can be enhanced to inherit parent's) --- common/nym-lp/src/session.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/common/nym-lp/src/session.rs b/common/nym-lp/src/session.rs index 6ef3f91372..7399bb8e39 100644 --- a/common/nym-lp/src/session.rs +++ b/common/nym-lp/src/session.rs @@ -219,6 +219,11 @@ pub struct LpSession { /// ID of the successor session that replaced this one. /// Set when demote() is called. successor_session_id: Mutex>, + + /// Negotiated protocol version from handshake. + /// Set during handshake completion from the ClientHello/ServerHello packet header. + /// Used for future version negotiation and compatibility checks. + negotiated_version: std::sync::atomic::AtomicU8, } /// Generates a fresh salt for PSK derivation. @@ -263,6 +268,24 @@ impl LpSession { self.is_initiator } + /// Returns the negotiated protocol version from the handshake. + /// + /// Defaults to 1 (current LP version). Set during handshake via + /// `set_negotiated_version()` when ClientHello/ServerHello is processed. + pub fn negotiated_version(&self) -> u8 { + self.negotiated_version + .load(std::sync::atomic::Ordering::Acquire) + } + + /// Sets the negotiated protocol version from handshake packet header. + /// + /// Should be called during handshake when processing ClientHello (responder) + /// or ServerHello (initiator) to record the agreed protocol version. + pub fn set_negotiated_version(&self, version: u8) { + self.negotiated_version + .store(version, std::sync::atomic::Ordering::Release); + } + /// Returns the local X25519 public key derived from the private key. /// /// This is used for KKT protocol when the responder needs to send their @@ -409,6 +432,7 @@ impl LpSession { subsession_counter: AtomicU64::new(0), read_only: AtomicBool::new(false), successor_session_id: Mutex::new(None), + negotiated_version: std::sync::atomic::AtomicU8::new(1), // Default to version 1 }) } @@ -1329,6 +1353,8 @@ impl SubsessionHandshake { subsession_counter: AtomicU64::new(0), read_only: AtomicBool::new(false), successor_session_id: Mutex::new(None), + // Inherit parent's protocol version + negotiated_version: std::sync::atomic::AtomicU8::new(1), }) } }