fix(client): clear gateway status from welcome identity
The client initialized gateway connectivity from ServerWelcome, but welcome only exposed a boolean. If a gateway disconnected before the client saw the catch-up PeerJoined event, the later unknown PeerLeft could not be tied to the gateway and the status could stay connected. Carry an optional gateway peer id in ServerWelcome. The relay fills it from the joining gateway or the existing room gateway, and the Windows client stores it so a matching unknown PeerLeft clears gateway connectivity. The boolean remains for wire compatibility with older welcomes that do not carry the id. Test Plan: - cargo fmt --check - cargo test -p lanparty-ctrl server_welcome - cargo test -p lanparty-relay accepts_gateway_and_client_into_room - cargo test -p lanparty-relay reports_missing_gateway_to_client_joining_first - cargo test -p lanparty-client-win relay_lifecycle - cargo test -p lanparty-client-win \ clears_gateway_status_when_welcome_gateway_leaves_before_join_event - cargo test -p lanparty-relay bridges_real_client_and_gateway_sessions - cargo test -p lanparty-client-core connects_to_relay_control_stream_as_client - cargo test --workspace - cargo clippy --workspace --all-targets -- -D warnings - cargo build --release -p lanparty-relay -p lanparty-gateway - git diff --check - git diff --cached --check Refs: MVP lifecycle cleanup
This commit is contained in:
@@ -216,6 +216,8 @@ pub struct ServerWelcome {
|
||||
mode: ConnectionMode,
|
||||
#[serde(default)]
|
||||
gateway_connected: bool,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
gateway_peer_id: Option<u32>,
|
||||
}
|
||||
|
||||
impl ServerWelcome {
|
||||
@@ -238,6 +240,7 @@ impl ServerWelcome {
|
||||
effective_tap_mtu,
|
||||
mode: ConnectionMode::Relay,
|
||||
gateway_connected: false,
|
||||
gateway_peer_id: None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -250,6 +253,18 @@ impl ServerWelcome {
|
||||
#[must_use]
|
||||
pub const fn with_gateway_connected(mut self, gateway_connected: bool) -> Self {
|
||||
self.gateway_connected = gateway_connected;
|
||||
if !gateway_connected {
|
||||
self.gateway_peer_id = None;
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub const fn with_gateway_peer_id(mut self, gateway_peer_id: Option<u32>) -> Self {
|
||||
self.gateway_peer_id = gateway_peer_id;
|
||||
if let Some(_peer_id) = gateway_peer_id {
|
||||
self.gateway_connected = true;
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
@@ -272,6 +287,10 @@ impl ServerWelcome {
|
||||
});
|
||||
}
|
||||
|
||||
if self.gateway_peer_id == Some(0) {
|
||||
return Err(ControlError::InvalidPeerId);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -304,6 +323,11 @@ impl ServerWelcome {
|
||||
pub const fn gateway_connected(&self) -> bool {
|
||||
self.gateway_connected
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub const fn gateway_peer_id(&self) -> Option<u32> {
|
||||
self.gateway_peer_id
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
|
||||
@@ -538,6 +562,14 @@ mod tests {
|
||||
ServerWelcome::new(1, 2, (MIN_USEFUL_TAP_MTU - 1) as u16).unwrap_err(),
|
||||
ControlError::EffectiveMtuTooSmall { .. }
|
||||
));
|
||||
assert_eq!(
|
||||
ServerWelcome::new(1, 2, MIN_USEFUL_TAP_MTU as u16)
|
||||
.unwrap()
|
||||
.with_gateway_peer_id(Some(0))
|
||||
.validate()
|
||||
.unwrap_err(),
|
||||
ControlError::InvalidPeerId
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -546,7 +578,15 @@ mod tests {
|
||||
|
||||
assert_eq!(welcome.mode(), ConnectionMode::Relay);
|
||||
assert!(!welcome.gateway_connected());
|
||||
assert!(welcome.with_gateway_connected(true).gateway_connected());
|
||||
assert_eq!(welcome.gateway_peer_id(), None);
|
||||
|
||||
let with_gateway = welcome.with_gateway_peer_id(Some(7));
|
||||
assert!(with_gateway.gateway_connected());
|
||||
assert_eq!(with_gateway.gateway_peer_id(), Some(7));
|
||||
|
||||
let without_gateway = with_gateway.with_gateway_connected(false);
|
||||
assert!(!without_gateway.gateway_connected());
|
||||
assert_eq!(without_gateway.gateway_peer_id(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -581,6 +621,7 @@ mod tests {
|
||||
let welcome: ServerWelcome = serde_json::from_str(&json).unwrap();
|
||||
|
||||
assert_eq!(welcome.mode(), ConnectionMode::Relay);
|
||||
assert_eq!(welcome.gateway_peer_id(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user