Optimize BLE mesh network for robustness and range (#314)

- Fixed relay probability calculation for 2-node networks (0% relay needed)
- Added protocol ACKs to prevent unnecessary retransmissions
- Implemented MessageState for enhanced duplicate detection
- Added exponential backoff for collision avoidance
- Fixed duplicate sends for bidirectional connections
- Resolved packet ID generation issues using immutable fields only
- Implemented smart rate limiting with progressive throttling
- Removed unnecessary debug logging and fixed build warnings
- Optimized message routing to prevent flooding in small networks

Co-authored-by: jack <jackjackbits@users.noreply.github.com>
This commit is contained in:
jack
2025-07-24 19:49:37 +02:00
committed by GitHub
co-authored by jack
parent 498bb30d82
commit 492f90edd5
8 changed files with 831 additions and 172 deletions
+5 -2
View File
@@ -139,8 +139,9 @@ struct BitchatPacket: Codable {
let payload: Data
let signature: Data?
var ttl: UInt8
let sequenceNumber: UInt32 // New field for duplicate detection
init(type: UInt8, senderID: Data, recipientID: Data?, timestamp: UInt64, payload: Data, signature: Data?, ttl: UInt8) {
init(type: UInt8, senderID: Data, recipientID: Data?, timestamp: UInt64, payload: Data, signature: Data?, ttl: UInt8, sequenceNumber: UInt32 = 0) {
self.version = 1
self.type = type
self.senderID = senderID
@@ -149,10 +150,11 @@ struct BitchatPacket: Codable {
self.payload = payload
self.signature = signature
self.ttl = ttl
self.sequenceNumber = sequenceNumber
}
// Convenience initializer for new binary format
init(type: UInt8, ttl: UInt8, senderID: String, payload: Data) {
init(type: UInt8, ttl: UInt8, senderID: String, payload: Data, sequenceNumber: UInt32 = 0) {
self.version = 1
self.type = type
// Convert hex string peer ID to binary data (8 bytes)
@@ -171,6 +173,7 @@ struct BitchatPacket: Codable {
self.payload = payload
self.signature = nil
self.ttl = ttl
self.sequenceNumber = sequenceNumber
}
var data: Data? {