Rust Actor Architecture & Concurrency
The Rust implementation (rustflexstack) is built upon the Actor Model of concurrent computation. Each protocol layer executes within its own dedicated operating system thread, communicating exclusively via message passing across asynchronous std::sync::mpsc (Multiple Producer, Single Consumer) channels.
Concurrency Model Overview
flowchart TD
FAC["<b>FACILITIES LAYER ACTORS</b><br/>LdmFacility / CaService / DenService<br/><i>std::thread with mpsc channels</i>"]
BTP["<b>BTP ROUTER ACTOR</b><br/>BTPRouter::spawn()<br/><i>mpsc::channel<BTPRouterInput></i>"]
GN["<b>GEONETWORKING ROUTER ACTOR</b><br/>Router::spawn()<br/><i>mpsc::channel<RouterInput></i>"]
LL["<b>LINK LAYER DRIVER ACTORS</b><br/>RawLinkLayer: rx_thread (pnet) & tx_thread (pnet)<br/><i>or Cv2xLinkLayer (Qualcomm PC5 C-FFI)</i>"]
FAC -->|"BTPDataRequest (mpsc)"| BTP
BTP -->|"BTPDataIndication (mpsc)"| FAC
BTP -->|"GNDataRequest (mpsc)"| GN
GN -->|"GNDataIndication (mpsc)"| BTP
GN -->|"raw payload tx (mpsc)"| LL
LL -->|"raw payload rx (mpsc)"| GN
style FAC fill:#dcfce7,stroke:#16a34a,stroke-width:2px,color:#14532d
style BTP fill:#dbeafe,stroke:#2563eb,stroke-width:2px,color:#1e3a8a
style GN fill:#fee2e2,stroke:#dc2626,stroke-width:2px,color:#7f1d1d
style LL fill:#fef3c7,stroke:#d97706,stroke-width:2px,color:#78350f
Key Architectural Advantages
Little Shared Mutable State: Layers communicate over channels, and each actor owns its protocol state. The few structures that several threads use (for example the security context and the channel busy ratio) sit behind
Mutexlocks, and safe Rust rules out data races at compile time.Move Semantics & Zero Reallocation: Packet byte buffers (
Vec<u8>) and parsed ASN.1 data structures are moved across channels rather than copied.Low Processing Latency: There are no garbage-collection pauses, and the code is compiled ahead of time. Measured processing latencies are reported on the Performance & Validation page.
Autonomous Beaconing: If the GeoNetworking MIB defines
itsGnBeaconServiceRetransmitTimer > 0, the GeoNetworking router automatically spawns a dedicated background beacon timer thread that injects periodic Beacon packets without application polling.
Router Handles & Channel Wrapping
Callers interact with running actors using lightweight, thread-safe handle structs that wrap a channel Sender:
Handle Type |
Role & Method Primitives |
|---|---|
|
Wraps GeoNetworking input channel. Methods: |
|
Wraps BTP input channel. Methods: |
|
Interfaces for LDM data providers (registration, additions) and consumers (queries, subscriptions). |
Thread Lifecycle & Graceful Teardown
The entire pipeline shuts down gracefully:
- When a handle or sender is dropped, the corresponding receiver’s rx.recv() returns Err(RecvError), causing the actor’s event loop to cleanly exit.
- Sockets and telematics flows are closed deterministically when their owner structs drop.