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), }) } }