Feature/fragmentation fixes (#453)

* Fix fragmentation + BLE long-write + padding

- Accumulate CBATTRequest long writes by offset and decode once per central
- Decode original packet after fragment reassembly (preserve flags/compression)
- Switch MessagePadding to strict PKCS#7 and validate before unpadding
- Make BinaryProtocol.decode robust: try raw first, then unpad fallback
- Unpad frames before BLE notify; fragment when exceeding centrals' max update length
- Skip notify path when max update length < 21 bytes (protocol minimum)

Verified large PMs and announces route without decode errors and peers show reliably.

* Tests: fix weak delegate lifetime, legacy constants, and unused vars; fragment unpadded frames

- BLEServiceTests: hold strong reference to MockBitchatDelegate
- IntegrationTests: fix inline comment braces; replace removed types with test-safe values; use numeric 0x06 for legacy handshake resp checks
- BinaryProtocolTests: remove unused minResult variable
- BLEService: fragment the unpadded frame so fragments are efficient

* tests: add Noise rehandshake recovery test; document in-memory test bus and autoFlood; stabilize large-network broadcast

* tests: align suite with current behavior (compression, padding, routing, nonce); deflake and stabilize

---------

Co-authored-by: jack <jackjackbits@users.noreply.github.com>
This commit is contained in:
jack
2025-08-19 01:22:21 +02:00
committed by GitHub
co-authored by jack
parent 4c0bb5f93a
commit a30b73dd99
14 changed files with 741 additions and 517 deletions
+2 -2
View File
@@ -13,7 +13,7 @@ struct CompressionUtil {
// Compression threshold - don't compress if data is smaller than this
static let compressionThreshold = 100 // bytes
// Compress data using LZ4 algorithm (fast compression/decompression)
// Compress data using zlib algorithm (most compatible)
static func compress(_ data: Data) -> Data? {
// Skip compression for small data
guard data.count >= compressionThreshold else { return nil }
@@ -36,7 +36,7 @@ struct CompressionUtil {
return Data(bytes: destinationBuffer, count: compressedSize)
}
// Decompress LZ4 compressed data
// Decompress zlib compressed data
static func decompress(_ compressedData: Data, originalSize: Int) -> Data? {
let destinationBuffer = UnsafeMutablePointer<UInt8>.allocate(capacity: originalSize)
defer { destinationBuffer.deallocate() }