mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 02:25:20 +00:00
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:
@@ -66,12 +66,13 @@ final class BLEServiceTests: XCTestCase {
|
||||
func testSendPublicMessage() {
|
||||
let expectation = XCTestExpectation(description: "Message sent")
|
||||
|
||||
service.delegate = MockBitchatDelegate { message in
|
||||
let delegate = MockBitchatDelegate { message in
|
||||
XCTAssertEqual(message.content, "Hello, world!")
|
||||
XCTAssertEqual(message.sender, "TestUser")
|
||||
XCTAssertFalse(message.isPrivate)
|
||||
expectation.fulfill()
|
||||
}
|
||||
service.delegate = delegate
|
||||
|
||||
service.sendMessage("Hello, world!")
|
||||
|
||||
@@ -82,13 +83,14 @@ final class BLEServiceTests: XCTestCase {
|
||||
func testSendPrivateMessage() {
|
||||
let expectation = XCTestExpectation(description: "Private message sent")
|
||||
|
||||
service.delegate = MockBitchatDelegate { message in
|
||||
let delegate = MockBitchatDelegate { message in
|
||||
XCTAssertEqual(message.content, "Secret message")
|
||||
XCTAssertEqual(message.sender, "TestUser")
|
||||
XCTAssertTrue(message.isPrivate)
|
||||
XCTAssertEqual(message.recipientNickname, "Bob")
|
||||
expectation.fulfill()
|
||||
}
|
||||
service.delegate = delegate
|
||||
|
||||
service.sendPrivateMessage("Secret message", to: "PEER5678", recipientNickname: "Bob", messageID: "MSG123")
|
||||
|
||||
@@ -99,11 +101,12 @@ final class BLEServiceTests: XCTestCase {
|
||||
func testSendMessageWithMentions() {
|
||||
let expectation = XCTestExpectation(description: "Message with mentions sent")
|
||||
|
||||
service.delegate = MockBitchatDelegate { message in
|
||||
let delegate = MockBitchatDelegate { message in
|
||||
XCTAssertEqual(message.content, "@alice @bob check this out")
|
||||
XCTAssertEqual(message.mentions, ["alice", "bob"])
|
||||
expectation.fulfill()
|
||||
}
|
||||
service.delegate = delegate
|
||||
|
||||
service.sendMessage("@alice @bob check this out", mentions: ["alice", "bob"])
|
||||
|
||||
@@ -115,11 +118,12 @@ final class BLEServiceTests: XCTestCase {
|
||||
func testSimulateIncomingMessage() {
|
||||
let expectation = XCTestExpectation(description: "Message received")
|
||||
|
||||
service.delegate = MockBitchatDelegate { message in
|
||||
let delegate = MockBitchatDelegate { message in
|
||||
XCTAssertEqual(message.content, "Incoming message")
|
||||
XCTAssertEqual(message.sender, "RemoteUser")
|
||||
expectation.fulfill()
|
||||
}
|
||||
service.delegate = delegate
|
||||
|
||||
let incomingMessage = BitchatMessage(
|
||||
id: "MSG456",
|
||||
@@ -142,10 +146,11 @@ final class BLEServiceTests: XCTestCase {
|
||||
func testSimulateIncomingPacket() {
|
||||
let expectation = XCTestExpectation(description: "Packet processed")
|
||||
|
||||
service.delegate = MockBitchatDelegate { message in
|
||||
let delegate = MockBitchatDelegate { message in
|
||||
XCTAssertEqual(message.content, "Packet message")
|
||||
expectation.fulfill()
|
||||
}
|
||||
service.delegate = delegate
|
||||
|
||||
let message = BitchatMessage(
|
||||
id: "MSG789",
|
||||
@@ -209,9 +214,11 @@ final class BLEServiceTests: XCTestCase {
|
||||
func testMessageDeliveryHandler() {
|
||||
let expectation = XCTestExpectation(description: "Delivery handler called")
|
||||
|
||||
service.messageDeliveryHandler = { message in
|
||||
XCTAssertEqual(message.content, "Test delivery")
|
||||
expectation.fulfill()
|
||||
service.packetDeliveryHandler = { packet in
|
||||
if let msg = BitchatMessage.fromBinaryPayload(packet.payload) {
|
||||
XCTAssertEqual(msg.content, "Test delivery")
|
||||
expectation.fulfill()
|
||||
}
|
||||
}
|
||||
|
||||
service.sendMessage("Test delivery")
|
||||
|
||||
Reference in New Issue
Block a user