mirror of
https://github.com/rosenpass/rosenpass.git
synced 2026-01-09 03:43:35 -08:00
Dynamically dispatch WireguardBrokerMio trait in AppServer. Also allows for mio event registration and poll processing, logic from dev/broker-architecture branch Co-authored-by: Prabhpreet Dua <615318+prabhpreet@users.noreply.github.com> Co-authored-by: Karolin Varner <karo@cupdev.net>
41 lines
1.1 KiB
Rust
41 lines
1.1 KiB
Rust
use rosenpass_secret_memory::{Public, Secret};
|
|
use std::{fmt::Debug, result::Result};
|
|
|
|
pub const WG_KEY_LEN: usize = 32;
|
|
pub const WG_PEER_LEN: usize = 32;
|
|
pub trait WireGuardBroker: Debug {
|
|
type Error;
|
|
fn set_psk(&mut self, config: SerializedBrokerConfig<'_>) -> Result<(), Self::Error>;
|
|
}
|
|
|
|
pub trait WireguardBrokerCfg: Debug {
|
|
fn create_config<'a>(&'a self, psk: &'a Secret<WG_KEY_LEN>) -> SerializedBrokerConfig<'a>;
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct SerializedBrokerConfig<'a> {
|
|
pub interface: &'a [u8],
|
|
pub peer_id: &'a Public<WG_PEER_LEN>,
|
|
pub psk: &'a Secret<WG_KEY_LEN>,
|
|
pub additional_params: &'a [u8],
|
|
}
|
|
|
|
pub trait WireguardBrokerMio: WireGuardBroker {
|
|
type MioError;
|
|
/// Register interested events for mio::Registry
|
|
fn register(
|
|
&mut self,
|
|
registry: &mio::Registry,
|
|
token: mio::Token,
|
|
) -> Result<(), Self::MioError>;
|
|
/// Run after a mio::poll operation
|
|
fn process_poll(&mut self) -> Result<(), Self::MioError>;
|
|
|
|
fn unregister(&mut self, registry: &mio::Registry) -> Result<(), Self::MioError>;
|
|
}
|
|
|
|
#[cfg(feature = "enable_broker_api")]
|
|
pub mod api;
|
|
|
|
pub mod brokers;
|