76 lines
2.4 KiB
Rust
76 lines
2.4 KiB
Rust
|
|
//! FIPS mesh transport (Free Internetworking Peering System).
|
||
|
|
//!
|
||
|
|
//! Delegates the actual wire protocol to the `fips` system daemon
|
||
|
|
//! (github.com/jmcorgan/fips), which archipelago supervises via the
|
||
|
|
//! `archipelago-fips.service` unit. This module is the in-process
|
||
|
|
//! `NodeTransport` adapter: it checks daemon liveness, maps a peer's
|
||
|
|
//! FIPS npub to a `fd00::/8` IPv6 TUN address, and POSTs the
|
||
|
|
//! `TransportMessage` payload over it.
|
||
|
|
//!
|
||
|
|
//! Sits at priority 3 between LAN and Tor — preferred over Tor for
|
||
|
|
//! federation and peer traffic but yielding to direct LAN.
|
||
|
|
//!
|
||
|
|
//! Currently a stub: `is_available()` returns false until the FIPS
|
||
|
|
//! daemon integration in `crate::fips` lands and the key at
|
||
|
|
//! `/data/identity/fips_key` is materialised via onboarding.
|
||
|
|
|
||
|
|
use super::{NodeTransport, TransportKind, TransportMessage};
|
||
|
|
use anyhow::Result;
|
||
|
|
use std::path::{Path, PathBuf};
|
||
|
|
|
||
|
|
pub struct FipsTransport {
|
||
|
|
identity_dir: PathBuf,
|
||
|
|
}
|
||
|
|
|
||
|
|
impl FipsTransport {
|
||
|
|
pub fn new(identity_dir: &Path) -> Self {
|
||
|
|
Self {
|
||
|
|
identity_dir: identity_dir.to_path_buf(),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
impl NodeTransport for FipsTransport {
|
||
|
|
fn kind(&self) -> TransportKind {
|
||
|
|
TransportKind::Fips
|
||
|
|
}
|
||
|
|
|
||
|
|
fn is_available(&self) -> bool {
|
||
|
|
// Readiness gate: key must be on disk AND daemon wiring must exist.
|
||
|
|
// The daemon-liveness check is added alongside `crate::fips` — until
|
||
|
|
// then we deliberately report unavailable so the router falls through
|
||
|
|
// to Tor and no traffic is misrouted onto a missing TUN.
|
||
|
|
let _key_present = crate::identity::fips_key_exists(&self.identity_dir);
|
||
|
|
false
|
||
|
|
}
|
||
|
|
|
||
|
|
fn send<'a>(
|
||
|
|
&'a self,
|
||
|
|
_address: &'a str,
|
||
|
|
_message: &'a TransportMessage,
|
||
|
|
) -> std::pin::Pin<Box<dyn std::future::Future<Output = Result<()>> + Send + 'a>> {
|
||
|
|
Box::pin(async move {
|
||
|
|
anyhow::bail!("FIPS transport not yet wired; daemon integration pending")
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#[cfg(test)]
|
||
|
|
mod tests {
|
||
|
|
use super::*;
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn test_kind_is_fips() {
|
||
|
|
let t = FipsTransport::new(std::path::Path::new("/tmp"));
|
||
|
|
assert_eq!(t.kind(), TransportKind::Fips);
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn test_reports_unavailable_pre_wiring() {
|
||
|
|
let dir = tempfile::tempdir().unwrap();
|
||
|
|
let t = FipsTransport::new(dir.path());
|
||
|
|
// Stub: always unavailable until daemon integration lands.
|
||
|
|
assert!(!t.is_available());
|
||
|
|
}
|
||
|
|
}
|