/ app / lib / services / ble / ble_constants.dart
ble_constants.dart
 1  import 'package:flutter_blue_plus/flutter_blue_plus.dart';
 2  
 3  /// BLE constants for Dead Drop proximity messaging
 4  abstract final class BleConstants {
 5    /// Dead Drop Service UUID (custom 128-bit UUID)
 6    /// Full string for ble_peripheral compatibility
 7    static const serviceUuidString = 'dddd0001-0000-1000-8000-00805f9b34fb';
 8    static final serviceUuid = Guid(serviceUuidString);
 9  
10    /// Characteristic for rotating ID (read)
11    /// Allows connected devices to read current rotating ID
12    static const rotatingIdCharUuidString = 'dddd0002-0000-1000-8000-00805f9b34fb';
13    static final rotatingIdCharUuid = Guid(rotatingIdCharUuidString);
14  
15    /// Characteristic for Noise handshake messages (writeWithoutResponse/read)
16    static const handshakeCharUuidString = 'dddd0003-0000-1000-8000-00805f9b34fb';
17    static final handshakeCharUuid = Guid(handshakeCharUuidString);
18  
19    /// Characteristic for encrypted message exchange (writeWithoutResponse/read)
20    static const exchangeCharUuidString = 'dddd0004-0000-1000-8000-00805f9b34fb';
21    static final exchangeCharUuid = Guid(exchangeCharUuidString);
22  
23    /// Manufacturer ID for advertisement data (custom)
24    static const manufacturerId = 0xDDDD;
25  
26    /// Rotating ID size in bytes
27    static const rotatingIdSize = 16;
28  
29    /// Scan duration before pausing
30    static const scanDuration = Duration(seconds: 10);
31  
32    /// Pause between scan cycles
33    static const scanPauseDuration = Duration(seconds: 5);
34  
35    /// Connection timeout
36    static const connectionTimeout = Duration(seconds: 30);
37  
38    /// Handshake timeout
39    static const handshakeTimeout = Duration(seconds: 60);
40  
41    /// Exchange timeout (per message)
42    static const exchangeMessageTimeout = Duration(seconds: 30);
43  
44    /// How long to keep a discovered contact before expiring
45    static const discoveryExpiration = Duration(minutes: 5);
46  
47    /// Rotating ID refresh interval (should match Rust core's rotation period)
48    static const rotatingIdRefreshInterval = Duration(minutes: 15);
49  
50    /// Minimum RSSI to consider a device "nearby"
51    static const minRssiThreshold = -95;
52  
53    /// Preferred MTU for BLE connections (for larger handshake messages)
54    static const preferredMtu = 512;
55  
56    /// Idle timeout for keepAlive connections before auto-disconnect
57    static const keepAliveIdleTimeout = Duration(minutes: 5);
58  
59    /// Interval between periodic gossip rounds during keepAlive
60    static const gossipInterval = Duration(seconds: 30);
61  
62    /// Timeout for a single periodic gossip round.
63    /// Must be long enough for large gossip responses (~32KB) to transfer
64    /// over BLE at ~500 bytes/150ms (~10s for 32KB).
65    static const gossipRoundTimeout = Duration(seconds: 30);
66  
67    /// Per-step timeout waiting for peer gossip data
68    static const gossipStepTimeout = Duration(seconds: 5);
69  }
70  
71  /// BLE exchange state
72  enum BleExchangeState {
73    /// Contact discovered via scan
74    discovered,
75  
76    /// BLE connection in progress
77    connecting,
78  
79    /// Noise handshake in progress
80    handshaking,
81  
82    /// Gossip sync in progress
83    syncing,
84  
85    /// Exchange completed successfully
86    completed,
87  
88    /// Exchange failed
89    failed,
90  }