API Reference
Configuration
ProtocolConfig
TransportsConfig
DorsConfig
Controls transport switching behavior.NetworkConfig
ReliabilityConfig
PathConfig
FileTransferConfig
API Methods
Constructor
Lifecycle Methods
| Method | Returns | Description |
|---|---|---|
start() | Promise<void> | Start the protocol and all enabled transports |
stop() | Promise<void> | Stop the protocol and disconnect all peers |
pause() | Promise<void> | Pause for background mode |
resume() | Promise<void> | Resume from paused state |
destroy() | Promise<void> | Clean up all resources |
getState() | Promise<ProtocolState> | Get current state (Stopped, Running, Paused) |
Messaging
| Method | Returns | Description |
|---|---|---|
sendMessage(params: SendMessageParams) | Promise<string> | Send message, returns message ID |
receiveMessage() | Promise<MessageReceivedEvent | null> | Poll for next received message |
Transport Management
| Method | Returns | Description |
|---|---|---|
getActiveTransports() | Promise<TransportType[]> | Get list of active transports |
enableTransport(type, config?) | Promise<void> | Enable a transport |
disableTransport(type) | Promise<void> | Disable a transport |
forceTransport(type) | Promise<void> | Force specific transport (override DORS) |
releaseTransportLock() | Promise<void> | Release forced transport, let DORS decide |
getTransportMetrics(type) | Promise<TransportMetrics | null> | Get transport statistics |
Bluetooth
| Method | Returns | Description |
|---|---|---|
isBluetoothEnabled() | Promise<boolean> | Check if Bluetooth is enabled |
requestEnableBluetooth() | Promise<boolean> | Request to enable Bluetooth (Android only) |
getBLePeerCount() | Promise<number> | Get number of discovered BLE peers |
Network Topology
| Method | Returns | Description |
|---|---|---|
getTopology() | Promise<NetworkTopology> | Get network topology snapshot |
getMessageStats() | Promise<MessageDeliveryStats[]> | Get message delivery statistics |
getDeliverySuccessRate() | Promise<number> | Get delivery success rate (0-1) |
getMedianLatency() | Promise<number | null> | Get median latency in ms |
getMedianHops() | Promise<number | null> | Get median hop count |
Battery
| Method | Returns | Description |
|---|---|---|
setBatteryLevel(level) | Promise<void> | Set battery level (0-100) for mesh decisions |
getBatteryLevel() | Promise<number | null> | Get current battery level |
DORS Configuration
| Method | Returns | Description |
|---|---|---|
updateDorsConfig(config) | Promise<void> | Update DORS settings at runtime |
getDorsConfig() | Promise<DorsConfig> | Get current DORS configuration |
shouldEscalateToWifi() | Promise<boolean> | Check if DORS recommends WiFi escalation |
Reliability Configuration
| Method | Returns | Description |
|---|---|---|
updateAckConfig(config) | Promise<void> | Update ACK settings |
updateRetryConfig(config) | Promise<void> | Update retry settings |
updateDedupConfig(config) | Promise<void> | Update deduplication settings |
getDedupStats() | Promise<DedupStats> | Get deduplication statistics |
getPendingAckCount() | Promise<number> | Get pending ACK count |
getRetryQueueSize() | Promise<number> | Get retry queue size |
Gradient Routing
| Method | Returns | Description |
|---|---|---|
learnRoute(destination, nextHop, hopCount, quality) | Promise<void> | Learn a route from incoming message |
getBestRoute(destination) | Promise<RouteEntry | null> | Get best route to destination |
getAllRoutes(destination) | Promise<RouteEntry[]> | Get all routes to destination |
hasRoute(destination) | Promise<boolean> | Check if route exists |
removeNeighborRoutes(neighborId) | Promise<void> | Remove routes through neighbor |
cleanupExpiredRoutes() | Promise<void> | Clean up expired routes |
getRoutingStats() | Promise<RoutingStats> | Get routing table statistics |
updateRoutingConfig(config) | Promise<void> | Update routing configuration |
Event Listeners
| Method | Returns | Description |
|---|---|---|
on(eventType, listener) | this | Register event listener |
off(eventType, listener) | this | Remove event listener |
once(eventType, listener) | this | Register one-time listener |
removeAllListeners(eventType?) | this | Remove all listeners |
Events
Message Events
message_sent
message_received
message_delivered
message_failed
Network Events
transport_switched
neighbor_discovered
neighbor_lost
network_metrics
File Events
file_progress
file_received
Diagnostic Events
Types
NetworkTopology
MessageDeliveryStats
RouteEntry
RoutingStats
DedupStats
FileProgress
ProtocolState
DORS (Dynamic Offline Relay Switch)
DORS automatically selects the optimal transport based on real-time conditions.Scoring Factors
| Factor | Description |
|---|---|
| Signal Strength | RSSI for BLE/WiFi (-50 to -100 dBm) |
| Proximity | Hop count to destination |
| Bandwidth | Transport throughput capability |
| Congestion | Queue depth and backlog |
| Energy | Battery impact of transport |
| Reliability | Historical delivery success rate |
| Load | Current processing capacity |
Transport Weights
BLE: Optimized for energy efficiency and mesh scenarios- Signal: 30%, Energy: 30%, Congestion: 15%, Proximity: 15%
- Bandwidth: 35%, Proximity: 20%, Congestion: 20%, Reliability: 15%
- Bandwidth: 35%, Reliability: 30%, Congestion: 15%, Energy: 10%
Switching Safeguards
| Safeguard | Default | Description |
|---|---|---|
| Hysteresis | 15 points | Minimum score improvement to switch |
| Cooldown | 20 seconds | Wait time between switches |
| Stability Window | 8 seconds | Transport must be stable before switching |
Mesh Networking
Cluster Architecture
Devices organize into clusters (groups of nearby connected peers). Connections between clusters are handled by bridge connections. Connection Roles:MEMBER- Intra-cluster connection (devices in same neighborhood)BRIDGE- Inter-cluster connection (bridges different neighborhoods)
How It Works
- Discovery: Devices broadcast BLE advertisements with mesh metadata (degree, free slots, battery, uptime)
- Cluster Detection: Each device computes a cluster signature from connected peer hashes
- Connection Decisions: MeshController evaluates candidates - prioritizes bridging different clusters
- Rebalancing: Periodically swaps lower-quality peers for better candidates or bridge opportunities
- Delivery: Messages sent to connected peers
Connection Budget
- Default: 4 connections per device
- Minimum: 1 connection maintained
- Connections are scored and rebalanced every ~15 seconds
- Bridge candidates get priority when clusters need unifying
Peer Scoring
| Factor | Weight | Description |
|---|---|---|
| RSSI | 35% | Signal strength to peer |
| Availability | 20% | Free connection slots |
| Uptime | 15% | How long peer has been active |
| Battery | 15% | Peer’s battery level |
| Stability | 10% | Connection reliability history |
| Load | 5% | Current processing load |
bridgeFavor: 0.1) to encourage network unification.
Message TTL
- Default: 8 hops
- Messages are dropped when TTL reaches 0
- Prevents infinite message circulation
Reliability Layer
Acknowledgments
- Messages require ACK for delivery confirmation
- Default timeout: 5 seconds
message_deliveredevent fires on ACK receipt
Retry Queue
- Failed messages are retried with exponential backoff
- Initial delay: 1 second
- Maximum delay: 30 seconds
- Maximum retries: 5
Deduplication
Prevents duplicate message processing:- Bloom Filter Mode: Space-efficient, ~1% false positive rate
- HashMap Mode: Exact tracking, configurable capacity
File Transfer
Sending Files
Managing Transfers
Troubleshooting
Messages Not Delivering
- Verify both devices have protocol started
- Check they’re within BLE range (~10-30m)
- Ensure TTL is sufficient for network size
- Monitor
message_failedevents for retry information
No Peers Discovered
- Verify Bluetooth is enabled:
await protocol.isBluetoothEnabled() - Check permissions are granted
- Ensure background modes enabled (iOS)
- Verify devices are within range
Frequent Disconnections
- Check signal strength via
neighbor_discoveredRSSI - Increase
stabilityWindowSecsin DORS config - Reduce
rebalanceIntervalfrequency - Check for BLE interference
High Battery Drain
- Reduce connection count (native mesh config)
- Verify DORS is selecting BLE over WiFi Direct
- Check for excessive retry activity
- Use
setBatteryLevel()to inform mesh decisions
Transport Not Switching
- Verify transport is enabled in config
- Check hysteresis threshold isn’t too high
- Ensure cooldown period has elapsed
- Use
forceTransport()to test manually
Linking Error
If you see the linking error message:- Run
pod install(iOS) - Rebuild the app after installing
- Verify not using Expo Go (native modules required)