citadel_sdk::prefabs::client

Module single_connection

Source
Expand description

A kernel that only makes a single client-to-server connection Single Client-Server Connection Kernel

This module implements a network kernel for managing a single client-to-server connection in the Citadel Protocol. It provides NAT traversal, peer discovery, and secure communication channels between clients and a central server.

§Features

  • Multiple authentication modes (Credentials, Transient)
  • NAT traversal support with configurable UDP mode
  • Secure session management with customizable security settings
  • Object transfer handling for file/data exchange
  • Pre-shared key authentication for server access
  • Automatic connection lifecycle management

§Example

use citadel_sdk::prelude::*;
use citadel_sdk::prefabs::client::single_connection::SingleClientServerConnectionKernel;

async fn connect_to_server() -> Result<(), NetworkError> {
    let settings = DefaultServerConnectionSettingsBuilder::transient("127.0.0.1:25021")
        .with_udp_mode(UdpMode::Enabled)
        .build()?;

    let kernel = SingleClientServerConnectionKernel::new(
        settings,
        |conn| async move {
            println!("Connected to server!");
            Ok(())
        },
    );

    Ok(())
}

§Important Notes

  • Only manages a single server connection at a time
  • Connection handler must be Send + Future
  • UDP mode affects NAT traversal capabilities
  • Object transfer requires proper handler setup

Structs§

  • This SingleClientServerConnectionKernel is the base kernel type for other built-in implementations of NetKernel. It establishes connections to a central node for purposes of NAT traversal and peer discovery, and depending on the application layer, can leverage the client to server connection for other purposes that require communication between the two.