Фикс error parsing: 1 frame = 1 packet и safe handshake fallback
Some checks failed
Android Kernel Build / build (push) Has been cancelled

This commit is contained in:
2026-03-26 02:53:21 +05:00
parent de958e10a1
commit 3953d93207
2 changed files with 33 additions and 44 deletions

View File

@@ -6,7 +6,8 @@ enum class HandshakeState(val value: Int) {
companion object {
fun fromValue(value: Int): HandshakeState {
return entries.firstOrNull { it.value == value } ?: COMPLETED
// Fail-safe: unknown value must not auto-authenticate.
return entries.firstOrNull { it.value == value } ?: NEED_DEVICE_VERIFICATION
}
}
}

View File

@@ -535,18 +535,18 @@ class Protocol(
log("📥 Received ${data.size} bytes: $hexDump${if (data.size > 50) "..." else ""}")
val stream = Stream(data)
var parsedPackets = 0
while (stream.getRemainingBits() >= MIN_PACKET_ID_BITS) {
val packetStartBits = stream.getReadPointerBits()
if (stream.getRemainingBits() < MIN_PACKET_ID_BITS) {
log("⚠️ Frame too short to contain packet ID (${stream.getRemainingBits()} bits)")
return
}
// Desktop/server parity: one WebSocket frame contains one packet.
val packetId = stream.readInt16()
log("📥 Packet ID: $packetId")
val packetFactory = supportedPackets[packetId]
if (packetFactory == null) {
log("⚠️ Unknown packet ID: $packetId, stopping frame parse")
break
log("⚠️ Unknown packet ID: $packetId")
return
}
val packet = packetFactory()
@@ -555,7 +555,7 @@ class Protocol(
} catch (e: Exception) {
log("❌ Error parsing packet $packetId: ${e.message}")
e.printStackTrace()
break
return
}
// Notify waiters
@@ -570,18 +570,6 @@ class Protocol(
e.printStackTrace()
}
}
parsedPackets++
val consumedBits = stream.getReadPointerBits() - packetStartBits
if (consumedBits <= 0) {
log("⚠️ Packet parser made no progress for packet $packetId, stopping frame parse")
break
}
}
if (parsedPackets > 1) {
log("📦 Parsed $parsedPackets packets from single WebSocket frame")
}
} catch (e: Exception) {
log("❌ Error parsing packet: ${e.message}")
e.printStackTrace()