mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 02:25:20 +00:00
Fix BLE advertisement warnings and duplicate registrations
- Remove 'Is Connectable' and 'Manufacturer Data' keys from BLE ads - Only use allowed keys: service UUIDs and local name - Prevent duplicate fingerprint registrations in favorites - Comment out unused fragment type string variable The warnings about advertisement keys should no longer appear.
This commit is contained in:
@@ -395,18 +395,11 @@ class BluetoothMeshService: NSObject {
|
|||||||
// Use generic advertising to avoid identification
|
// Use generic advertising to avoid identification
|
||||||
// No identifying prefixes or app names for activist safety
|
// No identifying prefixes or app names for activist safety
|
||||||
|
|
||||||
// Include network size hint in manufacturer data for scaling decisions
|
// Only use allowed advertisement keys
|
||||||
var manufacturerData = Data()
|
|
||||||
manufacturerData.append(UInt8(estimatedNetworkSize)) // 1 byte network size
|
|
||||||
manufacturerData.append(UInt8(currentBatteryLevel * 100)) // 1 byte battery percentage
|
|
||||||
|
|
||||||
advertisementData = [
|
advertisementData = [
|
||||||
CBAdvertisementDataServiceUUIDsKey: [BluetoothMeshService.serviceUUID],
|
CBAdvertisementDataServiceUUIDsKey: [BluetoothMeshService.serviceUUID],
|
||||||
// Use only peer ID without any identifying prefix
|
// Use only peer ID without any identifying prefix
|
||||||
CBAdvertisementDataLocalNameKey: myPeerID,
|
CBAdvertisementDataLocalNameKey: myPeerID
|
||||||
CBAdvertisementDataIsConnectable: true,
|
|
||||||
// Custom manufacturer data (using Apple's ID to blend in)
|
|
||||||
CBAdvertisementDataManufacturerDataKey: manufacturerData
|
|
||||||
]
|
]
|
||||||
|
|
||||||
isAdvertising = true
|
isAdvertising = true
|
||||||
@@ -876,7 +869,7 @@ class BluetoothMeshService: NSObject {
|
|||||||
|
|
||||||
// Send to connected peripherals (as central)
|
// Send to connected peripherals (as central)
|
||||||
var sentToPeripherals = 0
|
var sentToPeripherals = 0
|
||||||
for (peerID, peripheral) in connectedPeripherals {
|
for (_, peripheral) in connectedPeripherals {
|
||||||
if let characteristic = peripheralCharacteristics[peripheral] {
|
if let characteristic = peripheralCharacteristics[peripheral] {
|
||||||
// Check if peripheral is connected before writing
|
// Check if peripheral is connected before writing
|
||||||
if peripheral.state == .connected {
|
if peripheral.state == .connected {
|
||||||
@@ -960,7 +953,7 @@ class BluetoothMeshService: NSObject {
|
|||||||
messageBloomFilter.reset()
|
messageBloomFilter.reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = String(data: packet.senderID.trimmingNullBytes(), encoding: .utf8) ?? "unknown"
|
// let _ = String(data: packet.senderID.trimmingNullBytes(), encoding: .utf8) ?? "unknown"
|
||||||
|
|
||||||
// Received packet type: \(packet.type) from \(peerID)
|
// Received packet type: \(packet.type) from \(peerID)
|
||||||
|
|
||||||
@@ -1284,8 +1277,8 @@ class BluetoothMeshService: NSObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case .fragmentStart, .fragmentContinue, .fragmentEnd:
|
case .fragmentStart, .fragmentContinue, .fragmentEnd:
|
||||||
let fragmentTypeStr = packet.type == MessageType.fragmentStart.rawValue ? "START" :
|
// let fragmentTypeStr = packet.type == MessageType.fragmentStart.rawValue ? "START" :
|
||||||
(packet.type == MessageType.fragmentContinue.rawValue ? "CONTINUE" : "END")
|
// (packet.type == MessageType.fragmentContinue.rawValue ? "CONTINUE" : "END")
|
||||||
// Handling fragment
|
// Handling fragment
|
||||||
|
|
||||||
// Validate fragment has minimum required size
|
// Validate fragment has minimum required size
|
||||||
@@ -1369,7 +1362,7 @@ class BluetoothMeshService: NSObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let totalTime = Double(fragments.count - 1) * delayBetweenFragments
|
let _ = Double(fragments.count - 1) * delayBetweenFragments
|
||||||
// Total fragment send time
|
// Total fragment send time
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1524,7 +1517,7 @@ extension BluetoothMeshService: CBCentralManagerDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Connection pooling with exponential backoff
|
// Connection pooling with exponential backoff
|
||||||
let peripheralID = peripheral.identifier.uuidString
|
// peripheralID already declared above
|
||||||
|
|
||||||
// Check if we should attempt connection (considering backoff)
|
// Check if we should attempt connection (considering backoff)
|
||||||
if let backoffTime = connectionBackoff[peripheralID],
|
if let backoffTime = connectionBackoff[peripheralID],
|
||||||
@@ -1536,7 +1529,7 @@ extension BluetoothMeshService: CBCentralManagerDelegate {
|
|||||||
// Check if we already have this peripheral in our pool
|
// Check if we already have this peripheral in our pool
|
||||||
if let pooledPeripheral = connectionPool[peripheralID] {
|
if let pooledPeripheral = connectionPool[peripheralID] {
|
||||||
// Reuse existing peripheral from pool
|
// Reuse existing peripheral from pool
|
||||||
if pooledPeripheral.state == .disconnected {
|
if pooledPeripheral.state == CBPeripheralState.disconnected {
|
||||||
// Reconnect if disconnected
|
// Reconnect if disconnected
|
||||||
central.connect(pooledPeripheral, options: [
|
central.connect(pooledPeripheral, options: [
|
||||||
CBConnectPeripheralOptionNotifyOnConnectionKey: true,
|
CBConnectPeripheralOptionNotifyOnConnectionKey: true,
|
||||||
@@ -1723,7 +1716,7 @@ extension BluetoothMeshService: CBPeripheralDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Use the sender ID from the packet, not our local mapping which might still be a temp ID
|
// Use the sender ID from the packet, not our local mapping which might still be a temp ID
|
||||||
let localPeerID = connectedPeripherals.first(where: { $0.value == peripheral })?.key ?? "unknown"
|
let _ = connectedPeripherals.first(where: { $0.value == peripheral })?.key ?? "unknown"
|
||||||
let packetSenderID = String(data: packet.senderID.trimmingNullBytes(), encoding: .utf8) ?? "unknown"
|
let packetSenderID = String(data: packet.senderID.trimmingNullBytes(), encoding: .utf8) ?? "unknown"
|
||||||
// Received data from peer
|
// Received data from peer
|
||||||
|
|
||||||
|
|||||||
@@ -110,8 +110,13 @@ class ChatViewModel: ObservableObject {
|
|||||||
.prefix(16) // Use first 16 chars for brevity
|
.prefix(16) // Use first 16 chars for brevity
|
||||||
.lowercased()
|
.lowercased()
|
||||||
|
|
||||||
peerIDToPublicKeyFingerprint[peerID] = String(fingerprint)
|
let fingerprintStr = String(fingerprint)
|
||||||
print("[FAVORITES] Registered fingerprint \(fingerprint) for peer \(peerID)")
|
|
||||||
|
// Only register if not already registered
|
||||||
|
if peerIDToPublicKeyFingerprint[peerID] != fingerprintStr {
|
||||||
|
peerIDToPublicKeyFingerprint[peerID] = fingerprintStr
|
||||||
|
print("[FAVORITES] Registered fingerprint \(fingerprint) for peer \(peerID)")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendMessage(_ content: String) {
|
func sendMessage(_ content: String) {
|
||||||
|
|||||||
Reference in New Issue
Block a user