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)
This commit is contained in:
durch
2025-12-16 21:06:16 +01:00
committed by Jędrzej Stuczyński
parent 1386a49a99
commit 7ebacde1fc
+26
View File
@@ -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<Option<u32>>,
/// 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),
})
}
}