Skip to main content

FipsEndpoint

Struct FipsEndpoint 

Source
pub struct FipsEndpoint { /* private fields */ }
Expand description

A running embedded FIPS endpoint.

Implementations§

Source§

impl FipsEndpoint

Source

pub fn builder() -> FipsEndpointBuilder

Create a builder for an embedded endpoint.

Source

pub fn npub(&self) -> &str

Local endpoint npub.

Source

pub fn node_addr(&self) -> &NodeAddr

Local FIPS node address.

Source

pub fn address(&self) -> FipsAddress

Local FIPS IPv6-compatible address.

Source

pub fn discovery_scope(&self) -> Option<&str>

Application-level discovery scope, if configured.

Source

pub async fn send( &self, remote_npub: impl Into<String>, data: impl Into<Vec<u8>>, ) -> Result<(), FipsEndpointError>

Send application-owned endpoint data to a remote npub.

Fire-and-forget: enqueues the Send command on the node task and returns once the command channel accepts it. The node task’s send result is discarded — TCP and the upper protocol handle loss recovery, and the per-packet oneshot round-trip the previous design used for error reporting added several hundred microseconds of queueing latency under load (measured: 456ms avg ping under iperf3 saturation → 1ms after this change, 430× lower).

PeerIdentity for remote_npub is cached after first resolution to avoid the secp256k1 EC point parse on every packet.

Source

pub async fn recv(&self) -> Option<FipsEndpointMessage>

Receive the next source-attributed endpoint data message.

Translation from the internal NodeEndpointEvent::Data shape to the public FipsEndpointMessage shape happens inline here — the rx_loop pushes directly onto this channel, no relay task in between, no extra cross-task hop per packet.

Source

pub fn blocking_send( &self, remote_npub: impl Into<String>, data: impl Into<Vec<u8>>, ) -> Result<(), FipsEndpointError>

Synchronous blocking send — parks the calling OS thread on the FIPS endpoint command channel until the runtime accepts the send. MUST be called only from a thread spawned via std::thread::spawn, not from inside a tokio runtime.

Companion to Self::blocking_recv for control-frame replies (e.g. responding to a Ping with a Pong) issued from the dedicated TUN-write thread. Failures are returned via FipsEndpointError::Closed if the runtime has stopped.

Source

pub fn blocking_recv(&self) -> Option<FipsEndpointMessage>

Synchronous blocking receive — parks the calling OS thread on the channel until an event arrives or the channel closes.

MUST NOT be called from inside a tokio runtime; use this only from a thread spawned via std::thread::spawn so the tokio scheduler doesn’t deadlock.

The motivation is the bench’s CLI receive task: when run as a regular tokio task each recv().await is a full task-wake on the runtime (~1–3 µs scheduler bookkeeping), and at 113 kpps that’s ~10–30% of one core spent in plumbing the wake-up rather than writing the packet to TUN. A dedicated OS thread blocked on the channel via blocking_recv parks on a futex directly — the wake is a single futex_wake() with no scheduler involvement, an order of magnitude cheaper.

Source

pub fn try_recv(&self) -> Option<FipsEndpointMessage>

Non-blocking receive — returns the next ready endpoint message if one is queued, otherwise None. Pair with recv() to drain follow-on packets without paying a scheduler wake per packet:

// wake on the first packet, then drain everything ready
while let Some(msg) = endpoint.recv().await { process(msg); }
while let Some(msg) = endpoint.try_recv() { process(msg); }

On the bench’s FIPS-tunnel receive path the kernel UDP socket delivers packets in recvmmsg-sized bursts, so after a .recv() await there are typically 5–30 packets queued waiting. Draining them inline with try_recv saves N-1 scheduler hops per burst at line rate, freeing the consumer task to spend its time on the TUN write syscall instead of cross-task plumbing.

Returns None if the channel is empty, closed, or briefly contested by another consumer.

Source

pub async fn peers(&self) -> Result<Vec<FipsEndpointPeer>, FipsEndpointError>

Snapshot authenticated peers known by the endpoint.

Source

pub async fn send_ip_packet( &self, packet: impl Into<Vec<u8>>, ) -> Result<(), FipsEndpointError>

Send an outbound IPv6 packet into the FIPS session pipeline.

Source

pub async fn recv_ip_packet(&self) -> Option<NodeDeliveredPacket>

Receive the next source-attributed IPv6 packet delivered by FIPS.

Source

pub async fn shutdown(self) -> Result<(), FipsEndpointError>

Shut down the endpoint and wait for the node task to stop.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more