mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 22:05:21 +00:00
Restore BLE broadcasts when notify buffer is saturated
This commit is contained in:
@@ -916,13 +916,7 @@ final class BLEService: NSObject {
|
|||||||
for central in centrals where mapping[central.identifier.uuidString] == recipientPeerID {
|
for central in centrals where mapping[central.identifier.uuidString] == recipientPeerID {
|
||||||
let success = peripheralManager?.updateValue(data, for: characteristic, onSubscribedCentrals: [central]) ?? false
|
let success = peripheralManager?.updateValue(data, for: characteristic, onSubscribedCentrals: [central]) ?? false
|
||||||
if success { sentEncrypted = true; break }
|
if success { sentEncrypted = true; break }
|
||||||
collectionsQueue.async(flags: .barrier) { [weak self] in
|
enqueuePendingNotification(data: data, centrals: [central], context: "encrypted")
|
||||||
guard let self = self else { return }
|
|
||||||
if self.pendingNotifications.count < TransportConfig.blePendingNotificationsCapCount {
|
|
||||||
self.pendingNotifications.append((data: data, centrals: [central]))
|
|
||||||
SecureLogger.debug("📋 Queued encrypted packet for retry (notification queue full)", category: .session)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -936,6 +930,28 @@ final class BLEService: NSObject {
|
|||||||
sendOnAllLinks(packet: packet, data: data, pad: pad, directedOnlyPeer: nil)
|
sendOnAllLinks(packet: packet, data: data, pad: pad, directedOnlyPeer: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func enqueuePendingNotification(data: Data, centrals: [CBCentral]?, context: String, attempt: Int = 0) {
|
||||||
|
collectionsQueue.async(flags: .barrier) { [weak self] in
|
||||||
|
guard let self = self else { return }
|
||||||
|
if self.pendingNotifications.count < TransportConfig.blePendingNotificationsCapCount {
|
||||||
|
self.pendingNotifications.append((data: data, centrals: centrals))
|
||||||
|
SecureLogger.debug("📋 Queued \(context) packet for retry (pending=\(self.pendingNotifications.count))", category: .session)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if attempt >= TransportConfig.bleNotificationRetryMaxAttempts {
|
||||||
|
SecureLogger.error("❌ Dropping \(context) packet after exhausting retry window (pending=\(self.pendingNotifications.count))", category: .session)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let backoff = TransportConfig.bleNotificationRetryDelayMs * max(1, attempt + 1)
|
||||||
|
let deadline = DispatchTime.now() + .milliseconds(backoff)
|
||||||
|
self.messageQueue.asyncAfter(deadline: deadline) { [weak self] in
|
||||||
|
self?.enqueuePendingNotification(data: data, centrals: centrals, context: context, attempt: attempt + 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private func sendOnAllLinks(packet: BitchatPacket, data: Data, pad: Bool, directedOnlyPeer: String?) {
|
private func sendOnAllLinks(packet: BitchatPacket, data: Data, pad: Bool, directedOnlyPeer: String?) {
|
||||||
// Determine last-hop link for this message to avoid echoing back
|
// Determine last-hop link for this message to avoid echoing back
|
||||||
let messageID = makeMessageID(for: packet)
|
let messageID = makeMessageID(for: packet)
|
||||||
|
|||||||
@@ -31,7 +31,9 @@ enum TransportConfig {
|
|||||||
static let bleConnectionCandidatesMax: Int = 100
|
static let bleConnectionCandidatesMax: Int = 100
|
||||||
static let blePendingWriteBufferCapBytes: Int = 1_000_000
|
static let blePendingWriteBufferCapBytes: Int = 1_000_000
|
||||||
static let bleNotificationAssemblerHardCapBytes: Int = 8 * 1024 * 1024
|
static let bleNotificationAssemblerHardCapBytes: Int = 8 * 1024 * 1024
|
||||||
static let blePendingNotificationsCapCount: Int = 20
|
static let blePendingNotificationsCapCount: Int = 128
|
||||||
|
static let bleNotificationRetryDelayMs: Int = 25
|
||||||
|
static let bleNotificationRetryMaxAttempts: Int = 80
|
||||||
|
|
||||||
// Nostr
|
// Nostr
|
||||||
static let nostrReadAckInterval: TimeInterval = 0.35 // ~3 per second
|
static let nostrReadAckInterval: TimeInterval = 0.35 // ~3 per second
|
||||||
|
|||||||
Reference in New Issue
Block a user