citadel_sdk::prefabs::client

Module peer_connection

Source
Expand description

A kernel that assists in allowing multiple possible peer-to-peer connections Peer-to-Peer Connection Management

This module provides functionality for establishing and managing peer-to-peer connections in the Citadel Protocol. It supports both direct and NAT-traversed connections with configurable security settings and file transfer capabilities.

§Features

  • Multiple simultaneous peer connections
  • Configurable UDP and security settings per peer
  • Built-in file transfer support
  • Automatic peer registration handling
  • Session password protection
  • Connection state management
  • Flexible peer identification

§Example

use citadel_sdk::prelude::*;
use citadel_sdk::prefabs::client::peer_connection::{PeerConnectionKernel, PeerConnectionSetupAggregator};

async fn connect_to_peers() -> Result<(), NetworkError> {
    // Set up connections to multiple peers with different settings
    let peers = PeerConnectionSetupAggregator::default()
        .with_peer_custom("alice")
        .with_udp_mode(UdpMode::Enabled)
        .add()
        .with_peer_custom("bob")
        .with_session_security_settings(Default::default())
        .add();

    let settings = DefaultServerConnectionSettingsBuilder::transient("127.0.0.1:25021")
        .build()?;

    let kernel = PeerConnectionKernel::new(
        settings,
        peers,
        |connections, _remote| async move {
            println!("Attemping to connect to {} peers!", connections.len());
            Ok(())
        },
    );

    Ok(())
}

§Important Notes

  • Peers must be mutually registered before connecting
  • UDP mode affects NAT traversal capabilities
  • File transfers require proper handler setup
  • Session passwords must match on both peers

Structs§