mirror of
https://github.com/jmcorgan/fips.git
synced 2026-07-30 19:46:15 +00:00
transport/ethernet: rename discovery module to neighbor
Rename the ethernet link-local neighbor-beacon subsystem from the overloaded "discovery" vocabulary to a neighbor umbrella. The beacon frame vocabulary is retained (build_beacon/parse_beacon/BEACON_SIZE/ FRAME_TYPE_BEACON/FRAME_TYPE_DATA); only the subsystem and buffer identifiers change: DiscoveryBuffer becomes NeighborBuffer, discovery_buffer becomes neighbor_buffer, and DISCOVERY_VERSION becomes BEACON_VERSION (wire value 0x01 unchanged). Config toggles are left for a follow-up commit. Behavior-neutral.
This commit is contained in:
@@ -6,8 +6,8 @@
|
||||
//! 802.11 transparently on Linux).
|
||||
|
||||
pub mod addr;
|
||||
pub mod discovery;
|
||||
pub mod io;
|
||||
pub mod neighbor;
|
||||
pub mod stats;
|
||||
|
||||
pub use addr::parse_mac_string;
|
||||
@@ -17,8 +17,8 @@ use super::{
|
||||
TransportId, TransportState, TransportType,
|
||||
};
|
||||
use crate::config::EthernetConfig;
|
||||
use discovery::{DiscoveryBuffer, FRAME_TYPE_BEACON, FRAME_TYPE_DATA, build_beacon, parse_beacon};
|
||||
use io::{AsyncPacketSocket, ETHERNET_BROADCAST, PacketSocket};
|
||||
use neighbor::{FRAME_TYPE_BEACON, FRAME_TYPE_DATA, NeighborBuffer, build_beacon, parse_beacon};
|
||||
use stats::EthernetStats;
|
||||
|
||||
use secp256k1::XOnlyPublicKey;
|
||||
@@ -56,8 +56,8 @@ pub struct EthernetTransport {
|
||||
/// (`[type:1][length:2 LE][payload]`). The 2-byte length field is required
|
||||
/// to trim NIC minimum-frame padding before AEAD verification.
|
||||
effective_mtu: u16,
|
||||
/// Discovery buffer for discovered peers.
|
||||
discovery_buffer: Arc<DiscoveryBuffer>,
|
||||
/// Neighbor buffer for discovered peers.
|
||||
neighbor_buffer: Arc<NeighborBuffer>,
|
||||
/// Transport-level statistics.
|
||||
stats: Arc<EthernetStats>,
|
||||
/// Node's public key for beacon construction.
|
||||
@@ -73,7 +73,7 @@ impl EthernetTransport {
|
||||
packet_tx: PacketTx,
|
||||
) -> Self {
|
||||
let interface = config.interface.clone();
|
||||
let discovery_buffer = Arc::new(DiscoveryBuffer::new(transport_id));
|
||||
let neighbor_buffer = Arc::new(NeighborBuffer::new(transport_id));
|
||||
let stats = Arc::new(EthernetStats::new());
|
||||
|
||||
Self {
|
||||
@@ -88,7 +88,7 @@ impl EthernetTransport {
|
||||
local_mac: None,
|
||||
interface,
|
||||
effective_mtu: 1499, // default, updated on start
|
||||
discovery_buffer,
|
||||
neighbor_buffer,
|
||||
stats,
|
||||
local_pubkey: None,
|
||||
}
|
||||
@@ -164,7 +164,7 @@ impl EthernetTransport {
|
||||
let packet_tx = self.packet_tx.clone();
|
||||
let mtu = self.effective_mtu;
|
||||
let discovery_enabled = self.config.discovery();
|
||||
let discovery_buffer = self.discovery_buffer.clone();
|
||||
let neighbor_buffer = self.neighbor_buffer.clone();
|
||||
let stats = self.stats.clone();
|
||||
let recv_socket = socket.clone();
|
||||
|
||||
@@ -175,7 +175,7 @@ impl EthernetTransport {
|
||||
packet_tx,
|
||||
mtu,
|
||||
discovery_enabled,
|
||||
discovery_buffer,
|
||||
neighbor_buffer,
|
||||
stats,
|
||||
)
|
||||
.await;
|
||||
@@ -368,7 +368,7 @@ impl Transport for EthernetTransport {
|
||||
}
|
||||
|
||||
fn discover(&self) -> Result<Vec<DiscoveredPeer>, TransportError> {
|
||||
Ok(self.discovery_buffer.take())
|
||||
Ok(self.neighbor_buffer.take())
|
||||
}
|
||||
|
||||
fn auto_connect(&self) -> bool {
|
||||
@@ -391,7 +391,7 @@ async fn ethernet_receive_loop(
|
||||
packet_tx: PacketTx,
|
||||
mtu: u16,
|
||||
discovery_enabled: bool,
|
||||
discovery_buffer: Arc<DiscoveryBuffer>,
|
||||
neighbor_buffer: Arc<NeighborBuffer>,
|
||||
stats: Arc<EthernetStats>,
|
||||
) {
|
||||
// Buffer with headroom: frame type prefix + MTU + some extra
|
||||
@@ -449,11 +449,11 @@ async fn ethernet_receive_loop(
|
||||
stats.record_beacon_recv();
|
||||
|
||||
if discovery_enabled && let Some(pubkey) = parse_beacon(&buf[..len]) {
|
||||
discovery_buffer.add_peer(src_mac, pubkey);
|
||||
neighbor_buffer.add_peer(src_mac, pubkey);
|
||||
trace!(
|
||||
transport_id = %transport_id,
|
||||
remote_mac = %format_mac(&src_mac),
|
||||
"Discovery beacon received"
|
||||
"Neighbor beacon received"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -735,6 +735,6 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_beacon_size() {
|
||||
assert_eq!(discovery::BEACON_SIZE, 34);
|
||||
assert_eq!(neighbor::BEACON_SIZE, 34);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
//! Ethernet LAN discovery via broadcast beacons.
|
||||
//! Ethernet LAN neighbor detection via broadcast beacons.
|
||||
//!
|
||||
//! Beacon format (34 bytes total):
|
||||
//! - `0x01` (1 byte): frame type = discovery announcement
|
||||
//! - `0x01` (1 byte): discovery protocol version
|
||||
//! - `0x01` (1 byte): frame type = neighbor beacon
|
||||
//! - `0x01` (1 byte): beacon protocol version
|
||||
//! - x-only public key (32 bytes): node's Nostr identity
|
||||
|
||||
use crate::transport::{DiscoveredPeer, TransportAddr, TransportId};
|
||||
use secp256k1::XOnlyPublicKey;
|
||||
use std::sync::Mutex;
|
||||
|
||||
/// Discovery protocol version.
|
||||
pub const DISCOVERY_VERSION: u8 = 0x01;
|
||||
/// Beacon protocol version.
|
||||
pub const BEACON_VERSION: u8 = 0x01;
|
||||
|
||||
/// Frame type prefix for discovery announcement beacons.
|
||||
/// Frame type prefix for neighbor beacon frames.
|
||||
pub const FRAME_TYPE_BEACON: u8 = 0x01;
|
||||
|
||||
/// Frame type prefix for FIPS data frames.
|
||||
@@ -21,16 +21,16 @@ pub const FRAME_TYPE_DATA: u8 = 0x00;
|
||||
/// Total beacon payload size: type(1) + version(1) + pubkey(32).
|
||||
pub const BEACON_SIZE: usize = 34;
|
||||
|
||||
/// Build a discovery announcement beacon payload.
|
||||
/// Build a neighbor beacon payload.
|
||||
pub fn build_beacon(pubkey: &XOnlyPublicKey) -> [u8; BEACON_SIZE] {
|
||||
let mut buf = [0u8; BEACON_SIZE];
|
||||
buf[0] = FRAME_TYPE_BEACON;
|
||||
buf[1] = DISCOVERY_VERSION;
|
||||
buf[1] = BEACON_VERSION;
|
||||
buf[2..BEACON_SIZE].copy_from_slice(&pubkey.serialize());
|
||||
buf
|
||||
}
|
||||
|
||||
/// Parse a discovery announcement beacon payload.
|
||||
/// Parse a neighbor beacon payload.
|
||||
///
|
||||
/// Returns the sender's public key, or None if the payload is invalid.
|
||||
pub fn parse_beacon(data: &[u8]) -> Option<XOnlyPublicKey> {
|
||||
@@ -40,20 +40,20 @@ pub fn parse_beacon(data: &[u8]) -> Option<XOnlyPublicKey> {
|
||||
if data[0] != FRAME_TYPE_BEACON {
|
||||
return None;
|
||||
}
|
||||
if data[1] != DISCOVERY_VERSION {
|
||||
if data[1] != BEACON_VERSION {
|
||||
return None;
|
||||
}
|
||||
XOnlyPublicKey::from_slice(&data[2..34]).ok()
|
||||
}
|
||||
|
||||
/// Buffer for discovered peers, drained by `discover()`.
|
||||
pub struct DiscoveryBuffer {
|
||||
pub struct NeighborBuffer {
|
||||
transport_id: TransportId,
|
||||
peers: Mutex<Vec<DiscoveredPeer>>,
|
||||
}
|
||||
|
||||
impl DiscoveryBuffer {
|
||||
/// Create a new empty discovery buffer.
|
||||
impl NeighborBuffer {
|
||||
/// Create a new empty neighbor buffer.
|
||||
pub fn new(transport_id: TransportId) -> Self {
|
||||
Self {
|
||||
transport_id,
|
||||
@@ -101,7 +101,7 @@ mod tests {
|
||||
|
||||
assert_eq!(beacon.len(), BEACON_SIZE);
|
||||
assert_eq!(beacon[0], FRAME_TYPE_BEACON);
|
||||
assert_eq!(beacon[1], DISCOVERY_VERSION);
|
||||
assert_eq!(beacon[1], BEACON_VERSION);
|
||||
|
||||
let parsed = parse_beacon(&beacon).unwrap();
|
||||
assert_eq!(parsed, pubkey);
|
||||
@@ -134,8 +134,8 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_discovery_buffer() {
|
||||
let buffer = DiscoveryBuffer::new(TransportId::new(1));
|
||||
fn test_neighbor_buffer() {
|
||||
let buffer = NeighborBuffer::new(TransportId::new(1));
|
||||
let pubkey = test_pubkey();
|
||||
let mac = [0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff];
|
||||
|
||||
@@ -152,8 +152,8 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_discovery_buffer_dedup() {
|
||||
let buffer = DiscoveryBuffer::new(TransportId::new(1));
|
||||
fn test_neighbor_buffer_dedup() {
|
||||
let buffer = NeighborBuffer::new(TransportId::new(1));
|
||||
let pubkey = test_pubkey();
|
||||
let mac = [0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff];
|
||||
|
||||
Reference in New Issue
Block a user