Skip to main content

TokenStateBackend

Trait TokenStateBackend 

Source
pub trait TokenStateBackend:
    Send
    + Sync
    + 'static {
    // Required methods
    fn register<'life0, 'async_trait>(
        &'life0 self,
        state: JoinTokenState,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn begin_inflight<'life0, 'life1, 'async_trait>(
        &'life0 self,
        token_hash: &'life1 [u8; 32],
        node_addr: SocketAddr,
    ) -> Pin<Box<dyn Future<Output = Result<(), TokenStateError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn mark_consumed<'life0, 'life1, 'async_trait>(
        &'life0 self,
        token_hash: &'life1 [u8; 32],
        node_addr: SocketAddr,
        ts_ms: u64,
    ) -> Pin<Box<dyn Future<Output = Result<(), TokenStateError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn revert_inflight<'life0, 'life1, 'async_trait>(
        &'life0 self,
        token_hash: &'life1 [u8; 32],
    ) -> Pin<Box<dyn Future<Output = Result<(), TokenStateError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn get(&self, token_hash: &[u8; 32]) -> Option<JoinTokenState>;
}
Expand description

Abstraction over where token state is persisted.

The in-memory implementation (InMemoryTokenStore) is used in tests and single-node deployments that don’t need cross-crash single-use guarantees. Production deployments wire a Raft-backed implementation that proposes each transition through the metadata group.

The trait is async so the Raft-backed implementation can call MetadataProposer::propose_and_wait directly. InMemoryTokenStore uses immediate async { } bodies — zero overhead.

Required Methods§

Source

fn register<'life0, 'async_trait>( &'life0 self, state: JoinTokenState, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Register a freshly issued token with Issued state.

Source

fn begin_inflight<'life0, 'life1, 'async_trait>( &'life0 self, token_hash: &'life1 [u8; 32], node_addr: SocketAddr, ) -> Pin<Box<dyn Future<Output = Result<(), TokenStateError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Attempt to transition from IssuedInFlight. Returns Err(AlreadyConsumed) / Err(Expired) / Err(Aborted) if the token is already in a terminal or conflicting state.

Source

fn mark_consumed<'life0, 'life1, 'async_trait>( &'life0 self, token_hash: &'life1 [u8; 32], node_addr: SocketAddr, ts_ms: u64, ) -> Pin<Box<dyn Future<Output = Result<(), TokenStateError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Transition from InFlightConsumed. Called after the bundle has been sent and the peer has acknowledged receipt.

Source

fn revert_inflight<'life0, 'life1, 'async_trait>( &'life0 self, token_hash: &'life1 [u8; 32], ) -> Pin<Box<dyn Future<Output = Result<(), TokenStateError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Revert InFlightIssued (joiner timed out before ACK).

Source

fn get(&self, token_hash: &[u8; 32]) -> Option<JoinTokenState>

Look up the current state.

Implementors§