Skip to main content

PlatformOps

Trait PlatformOps 

pub trait PlatformOps: ProtocolIO {
    // Required method
    fn p2p_hole_punch<R>(
        session: CitadelSession<R, Self>,
        peer_connection_type: PeerConnectionType,
        ticket: Ticket,
        peer_nat_info: PeerNatInfo,
        channel_signal: NodeResult<R>,
        hole_punch_compat_stream: ReliableOrderedCompatStream<R>,
        endpoint_ratchet: R,
        peer_cid: u64,
        sync_instant: Instant,
        node_type: RelativeNodeType,
        udp_mode: UdpMode,
        session_security_settings: SessionSecuritySettings,
        cancel_rx: Option<Receiver<()>>,
    ) -> impl Future<Output = Result<(), NetworkError>> + ContextRequirements
       where R: Ratchet;

    // Provided methods
    fn identify_nat_type(
        stun_servers: Option<Vec<String>>,
    ) -> impl Future<Output = Result<NatType, Error>> + ContextRequirements { ... }
    fn quic_udp_channel(
        conn: Connection,
        local_addr: SocketAddr,
    ) -> Option<UdpSplittableTypes> { ... }
    fn c2s_hole_punch<R>(
        stream: ReliableOrderedCompatStream<R>,
        ratchet: R,
        security_level: SecurityLevel,
        target_cid: u64,
        stun_servers: Option<Vec<String>>,
        node_type: RelativeNodeType,
    ) -> impl Future<Output = Result<Option<UdpSplittableTypes>, NetworkError>> + ContextRequirements
       where R: Ratchet { ... }
    fn open_and_validate_for_transfer(
        source_path: &Path,
        expected_metadata: Option<&VirtualObjectMetadata>,
    ) -> Result<TransferMetadata, NetworkError> { ... }
    fn async_delete_file(source: PathBuf) { ... }
    fn spawn_udp_socket_loader<R>(
        session: CitadelSession<R, Self>,
        v_target: VirtualConnectionType,
        udp_conn: UdpSplittableTypes,
        addr: TargettedSocketAddr,
        ticket: Ticket,
        tcp_conn_awaiter: Option<Receiver<()>>,
    )
       where R: Ratchet { ... }
}
Expand description

Platform-specific capabilities extending the transport abstraction.

[ProtocolIO] defines how bytes move on the wire. PlatformOps defines what the platform can do: NAT traversal, file I/O, UDP session management, P2P hole punching.

Each platform (NativeIO, WasmIO) provides its own implementation. Business logic uses T: PlatformOps and calls T::method() directly — no cfg gates, no dispatch modules.

Required Methods§

fn p2p_hole_punch<R>( session: CitadelSession<R, Self>, peer_connection_type: PeerConnectionType, ticket: Ticket, peer_nat_info: PeerNatInfo, channel_signal: NodeResult<R>, hole_punch_compat_stream: ReliableOrderedCompatStream<R>, endpoint_ratchet: R, peer_cid: u64, sync_instant: Instant, node_type: RelativeNodeType, udp_mode: UdpMode, session_security_settings: SessionSecuritySettings, cancel_rx: Option<Receiver<()>>, ) -> impl Future<Output = Result<(), NetworkError>> + ContextRequirements
where R: Ratchet,

Orchestrate P2P hole punch: register endpoint, punch, establish connection, send channel_signal to kernel. On failure (or on WASM), sends channel_signal as TCP-only fallback.

Provided Methods§

fn identify_nat_type( stun_servers: Option<Vec<String>>, ) -> impl Future<Output = Result<NatType, Error>> + ContextRequirements

Identify local NAT type via STUN servers. Default: returns NatType::offline() (appropriate for WASM).

fn quic_udp_channel( conn: Connection, local_addr: SocketAddr, ) -> Option<UdpSplittableTypes>

Create a UDP channel from an existing QUIC connection. Default: returns None (QUIC not available).

fn c2s_hole_punch<R>( stream: ReliableOrderedCompatStream<R>, ratchet: R, security_level: SecurityLevel, target_cid: u64, stun_servers: Option<Vec<String>>, node_type: RelativeNodeType, ) -> impl Future<Output = Result<Option<UdpSplittableTypes>, NetworkError>> + ContextRequirements
where R: Ratchet,

Perform C2S UDP hole punch via NetworkEndpoint + encrypted hole punch. Returns the resulting UDP interface, or None if unavailable. Default: returns Ok(None) (hole punching not available).

fn open_and_validate_for_transfer( source_path: &Path, expected_metadata: Option<&VirtualObjectMetadata>, ) -> Result<TransferMetadata, NetworkError>

Open a file and validate it for transfer. Default: returns an error (file transfer not supported).

fn async_delete_file(source: PathBuf)

Asynchronously delete a file after transfer. Default: no-op.

fn spawn_udp_socket_loader<R>( session: CitadelSession<R, Self>, v_target: VirtualConnectionType, udp_conn: UdpSplittableTypes, addr: TargettedSocketAddr, ticket: Ticket, tcp_conn_awaiter: Option<Receiver<()>>, )
where R: Ratchet,

Spawn the UDP socket loader for a session. On native: spawns an async task for the full UDP subsystem. Default: no-op.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§