Фикс: восстановлена загрузка собственного пузырька изображения и стабилизирован хвост / интервал
This commit is contained in:
@@ -95,12 +95,31 @@ final class ProtocolManager: @unchecked Sendable {
|
||||
|
||||
/// Connect to server and perform handshake.
|
||||
func connect(publicKey: String, privateKeyHash: String) {
|
||||
let switchingAccount = savedPublicKey != nil && savedPublicKey != publicKey
|
||||
if switchingAccount {
|
||||
Self.logger.info("Account switch detected — resetting protocol session before reconnect")
|
||||
disconnect()
|
||||
}
|
||||
|
||||
savedPublicKey = publicKey
|
||||
savedPrivateHash = privateKeyHash
|
||||
|
||||
if connectionState == .authenticated || connectionState == .handshaking {
|
||||
switch connectionState {
|
||||
case .authenticated, .handshaking, .deviceVerificationRequired:
|
||||
Self.logger.info("Already connected/handshaking, skipping")
|
||||
return
|
||||
case .connected:
|
||||
if client.isConnected {
|
||||
Self.logger.info("Socket already connected, skipping duplicate connect()")
|
||||
return
|
||||
}
|
||||
case .connecting:
|
||||
if client.isConnecting {
|
||||
Self.logger.info("Connect already in progress, skipping duplicate connect()")
|
||||
return
|
||||
}
|
||||
case .disconnected:
|
||||
break
|
||||
}
|
||||
|
||||
connectionState = .connecting
|
||||
@@ -110,11 +129,20 @@ final class ProtocolManager: @unchecked Sendable {
|
||||
func disconnect() {
|
||||
Self.logger.info("Disconnecting")
|
||||
heartbeatTask?.cancel()
|
||||
heartbeatTask = nil
|
||||
handshakeTimeoutTask?.cancel()
|
||||
handshakeTimeoutTask = nil
|
||||
pingTimeoutTask?.cancel()
|
||||
pingTimeoutTask = nil
|
||||
pingVerificationInProgress = false
|
||||
handshakeComplete = false
|
||||
clearPacketQueue()
|
||||
clearResultHandlers()
|
||||
syncBatchLock.lock()
|
||||
_syncBatchActive = false
|
||||
syncBatchLock.unlock()
|
||||
pendingDeviceVerification = nil
|
||||
devices = []
|
||||
client.disconnect()
|
||||
connectionState = .disconnected
|
||||
savedPublicKey = nil
|
||||
@@ -305,6 +333,9 @@ final class ProtocolManager: @unchecked Sendable {
|
||||
Self.logger.error("Disconnected: \(error.localizedDescription)")
|
||||
}
|
||||
heartbeatTask?.cancel()
|
||||
heartbeatTask = nil
|
||||
handshakeTimeoutTask?.cancel()
|
||||
handshakeTimeoutTask = nil
|
||||
handshakeComplete = false
|
||||
pingVerificationInProgress = false
|
||||
pingTimeoutTask?.cancel()
|
||||
@@ -650,6 +681,12 @@ final class ProtocolManager: @unchecked Sendable {
|
||||
packetQueueLock.unlock()
|
||||
}
|
||||
|
||||
private func clearResultHandlers() {
|
||||
resultHandlersLock.lock()
|
||||
resultHandlers.removeAll()
|
||||
resultHandlersLock.unlock()
|
||||
}
|
||||
|
||||
// MARK: - Device Verification
|
||||
|
||||
private func handleDeviceList(_ packet: PacketDeviceList) {
|
||||
|
||||
Reference in New Issue
Block a user