mirror of
https://github.com/jmcorgan/fips.git
synced 2026-07-22 07:48:26 +00:00
BLE transport implementation using L2CAP Connection-Oriented Channels (SeqPacket mode) via the bluer crate, behind cfg(feature = "ble"). Core transport: - BleTransport<I> generic over BleIo trait (BluerIo prod, MockBleIo test) - Connection pool with priority eviction (static > discovered, max 7) - Connect-on-send via connect_inline() matching TCP behavior - Per-connection receive loops with pool cleanup on disconnect Discovery and probing: - Combined scan_probe_loop using select! over scanner events and a BinaryHeap delay queue with per-entry random jitter (0-5s) to prevent herd effects when multiple nodes see the same beacon simultaneously - Pre-handshake pubkey exchange ([0x00][pubkey:32]) for IK identity - Cross-probe tie-breaker: smaller NodeAddr's outbound wins (same convention as FMP/FSP rekey dual-initiation) - Probed peers reported to DiscoveryBuffer; pool fills through normal node-layer auto-connect -> send_async -> connect_inline path Beacon management: - Periodic advertising: 1s burst every 30s (configurable via beacon_interval_secs / beacon_duration_secs) - FIPS service UUID for scan filtering Configuration (all fields optional with defaults): - adapter, psm, mtu, max_connections, connect_timeout_ms - advertise, scan, auto_connect, accept_connections - beacon_interval_secs (30), beacon_duration_secs (1) Hardware validated with two BLE nodes: - 2048-byte MTU, ~60-160ms RTT, zero-config auto-connect - BLE spike tool at testing/ble/ for standalone adapter validation 42 unit tests + 4 node-level integration tests, all CI-compatible via MockBleIo (no hardware required). tokio test-util added for time-dependent scan/probe tests.
81 lines
2.5 KiB
Rust
81 lines
2.5 KiB
Rust
use super::*;
|
|
use crate::utils::index::SessionIndex;
|
|
use crate::transport::{packet_channel, LinkDirection, TransportAddr};
|
|
use crate::PeerIdentity;
|
|
use std::time::Duration;
|
|
|
|
mod bloom;
|
|
#[cfg(target_os = "linux")]
|
|
mod ble;
|
|
mod disconnect;
|
|
mod discovery;
|
|
#[cfg(target_os = "linux")]
|
|
mod ethernet;
|
|
mod forwarding;
|
|
mod handshake;
|
|
mod routing;
|
|
mod session;
|
|
mod spanning_tree;
|
|
mod tcp;
|
|
mod unit;
|
|
|
|
pub(super) fn make_node() -> Node {
|
|
let config = Config::new();
|
|
Node::new(config).unwrap()
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
pub(super) fn make_node_addr(val: u8) -> NodeAddr {
|
|
let mut bytes = [0u8; 16];
|
|
bytes[0] = val;
|
|
NodeAddr::from_bytes(bytes)
|
|
}
|
|
|
|
pub(super) fn make_peer_identity() -> PeerIdentity {
|
|
let identity = Identity::generate();
|
|
PeerIdentity::from_pubkey(identity.pubkey())
|
|
}
|
|
|
|
/// Create a PeerConnection with a completed Noise IK handshake.
|
|
///
|
|
/// Returns (connection, peer_identity) where the connection is outbound,
|
|
/// in Complete state, with session, indices, and transport info set.
|
|
pub(super) fn make_completed_connection(
|
|
node: &mut Node,
|
|
link_id: LinkId,
|
|
transport_id: TransportId,
|
|
current_time_ms: u64,
|
|
) -> (PeerConnection, PeerIdentity) {
|
|
let peer_identity_full = Identity::generate();
|
|
// Must use from_pubkey_full to preserve parity for ECDH
|
|
let peer_identity = PeerIdentity::from_pubkey_full(peer_identity_full.pubkey_full());
|
|
|
|
// Create outbound connection
|
|
let mut conn = PeerConnection::outbound(link_id, peer_identity, current_time_ms);
|
|
|
|
// Run initiator side of handshake
|
|
let our_keypair = node.identity.keypair();
|
|
let msg1 = conn.start_handshake(our_keypair, node.startup_epoch, current_time_ms).unwrap();
|
|
|
|
// Run responder side to generate msg2
|
|
let mut resp_conn = PeerConnection::inbound(LinkId::new(999), current_time_ms);
|
|
let peer_keypair = peer_identity_full.keypair();
|
|
let mut resp_epoch = [0u8; 8];
|
|
rand::Rng::fill_bytes(&mut rand::rng(), &mut resp_epoch);
|
|
let msg2 = resp_conn
|
|
.receive_handshake_init(peer_keypair, resp_epoch, &msg1, current_time_ms)
|
|
.unwrap();
|
|
|
|
// Complete initiator handshake
|
|
conn.complete_handshake(&msg2, current_time_ms).unwrap();
|
|
|
|
// Set indices and transport info
|
|
let our_index = node.index_allocator.allocate().unwrap();
|
|
conn.set_our_index(our_index);
|
|
conn.set_their_index(SessionIndex::new(42));
|
|
conn.set_transport_id(transport_id);
|
|
conn.set_source_addr(TransportAddr::from_string("127.0.0.1:5000"));
|
|
|
|
(conn, peer_identity)
|
|
}
|