rusty_esp_iroh_host/lib.rs
1#![forbid(unsafe_code)]
2//! `rusty_esp_iroh-host` — a Janus node and its client over iroh 1.x, in std.
3//!
4//! The same code runs on a laptop, a Pi and, as Track A, on ESP-IDF; only the
5//! key store and the radio bring-up differ (`rusty_esp_iroh-esp`). TLS is pure
6//! Rust throughout — rustls with the rustls-rustcrypto provider n0 proved on
7//! ESP32 — so there is no `ring` and no `aws-lc` anywhere in the graph.
8//!
9//! | module | what |
10//! |---|---|
11//! | [`identity`] | the device key (P-256, mID) and the endpoint key (ed25519, iroh) from the `Kv` seam, bound by a signed [`core::binding::Binding`] |
12//! | [`node`] | a Janus node: `janus/echo/1`, `janus/rpc/1`, `janus/media/1` and `mata-oem-sidecar/rpc/1` on one endpoint |
13//! | [`client`] | dial by ticket: echo, rpc with an mID assertion, sidecar JSON, media subscribe with a loss counter |
14//! | [`crypto`] | the QUIC-capable rustls-rustcrypto provider (AES-128-GCM + X25519), vendored from n0's ESP32 examples |
15
16pub use rusty_esp_iroh_core as core;
17
18pub mod client;
19pub mod crypto;
20pub mod error;
21pub mod identity;
22pub mod mjpeg;
23pub mod node;
24#[cfg(feature = "relay")]
25pub mod relay;
26
27pub use client::Client;
28pub use error::HostError;
29pub use identity::NodeIdentity;
30pub use node::{BootStats, Extras, MediaSource, NeighbourSource, Node, NodeConfig};
31
32/// Apply the reach tier to an endpoint builder: LAN-direct (relay disabled)
33/// or, with the `relay` feature, n0's relays + pkarr through [`relay::apply`].
34/// Asking for relay without the feature is an error, not a silent downgrade.
35pub fn configure_reach(
36 builder: iroh::endpoint::Builder,
37 relay: bool,
38) -> error::Result<iroh::endpoint::Builder> {
39 if !relay {
40 return Ok(builder.relay_mode(iroh::RelayMode::Disabled));
41 }
42 #[cfg(feature = "relay")]
43 {
44 Ok(relay::apply(builder))
45 }
46 #[cfg(not(feature = "relay"))]
47 {
48 Err(HostError::Bind(String::from(
49 "relay requested but rusty_esp_iroh-host was built without the `relay` feature",
50 )))
51 }
52}
53
54/// Unix seconds now, when the clock looks set (after Sept 2020); `None`
55/// before SNTP on a chip, which the assertion and adoption checks accept.
56#[must_use]
57pub fn now_unix() -> Option<u64> {
58 let secs = std::time::SystemTime::now()
59 .duration_since(std::time::UNIX_EPOCH)
60 .ok()?
61 .as_secs();
62 (secs > 1_600_000_000).then_some(secs)
63}