update kcp-sys (#12419)

1. Update kcp-sys to send KCP in frames to avoid potential crashes.
2. Fix the issue when the controling side is closed, the kcp connection close is not immediately recognized by the controlled end.
  * Unless the controling side receives the close reason, force the sending of the close reason to the controlled end when using KCP, and delay for 30ms to ensure the message is sent successfully.
  * Move the CloseReason receiving forward, as this message needs to be received when unauthorized, especially for kcp.

Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
21pages
2025-07-25 13:22:52 +08:00
committed by GitHub
parent 2afd538cf1
commit 9409912344
3 changed files with 36 additions and 16 deletions

View File

@@ -1937,6 +1937,16 @@ impl Connection {
}
async fn on_message(&mut self, msg: Message) -> bool {
if let Some(message::Union::Misc(misc)) = &msg.union {
// Move the CloseReason forward, as this message needs to be received when unauthorized, especially for kcp.
if let Some(misc::Union::CloseReason(s)) = &misc.union {
log::info!("receive close reason: {}", s);
self.on_close("Peer close", true).await;
raii::AuthedConnID::check_remove_session(self.inner.id(), self.session_key());
return false;
}
}
// After handling CloseReason messages, proceed to process other message types
if let Some(message::Union::LoginRequest(lr)) = msg.union {
self.handle_login_request_without_validation(&lr).await;
if self.authorized {
@@ -2790,15 +2800,6 @@ impl Connection {
Some(Instant::now().into()),
);
}
Some(misc::Union::CloseReason(_)) => {
self.on_close("Peer close", true).await;
raii::AuthedConnID::check_remove_session(
self.inner.id(),
self.session_key(),
);
return false;
}
Some(misc::Union::RestartRemoteDevice(_)) => {
#[cfg(not(any(target_os = "android", target_os = "ios")))]
if self.restart {