Skip to main content

ProxyServer

Struct ProxyServer 

Source
pub struct ProxyServer { /* private fields */ }
Expand description

The proxy server that accepts client connections and relays messages.

This server handles:

  • Client authentication using MlDsa65 challenge-response
  • Rendezvous code generation and lookup
  • Message routing between authenticated clients
  • Automatic cleanup of expired rendezvous codes

§Examples

Run a standalone server:

use ap_proxy::server::ProxyServer;
use std::net::SocketAddr;

let addr: SocketAddr = "127.0.0.1:8080".parse()?;
let server = ProxyServer::new(addr);

println!("Starting proxy server on {}", addr);
server.run().await?;

Embed in an application with cancellation:

use ap_proxy::server::ProxyServer;
use std::net::SocketAddr;
use tokio::signal;

let addr: SocketAddr = "127.0.0.1:8080".parse()?;
let server = ProxyServer::new(addr);

tokio::select! {
    result = server.run() => {
        result?;
    }
    _ = signal::ctrl_c() => {
        println!("Shutting down...");
    }
}

Implementations§

Source§

impl ProxyServer

Source

pub fn new(bind_addr: SocketAddr) -> Self

Create a new proxy server that will listen on the given address.

This does not start the server - call run() to begin accepting connections.

§Examples
use ap_proxy::server::ProxyServer;
use std::net::SocketAddr;

let addr: SocketAddr = "127.0.0.1:8080".parse().unwrap();
let server = ProxyServer::new(addr);
Source

pub async fn run(&self) -> Result<(), ProxyError>

Run the proxy server, accepting and handling connections.

This method:

  1. Binds to the configured address
  2. Spawns a background task to clean up expired rendezvous codes
  3. Accepts incoming WebSocket connections
  4. Spawns a handler task for each connection
  5. Runs indefinitely until an error occurs or cancelled
§Cancellation

Use tokio::select! or similar to cancel the server:

use ap_proxy::server::ProxyServer;
use std::net::SocketAddr;
use tokio::signal;

let addr: SocketAddr = "127.0.0.1:8080".parse()?;
let server = ProxyServer::new(addr);

tokio::select! {
    result = server.run() => result?,
    _ = signal::ctrl_c() => {
        println!("Shutting down gracefully");
    }
}
§Errors

Returns an error if:

  • The bind address is already in use
  • The address is invalid or cannot be bound
  • A network error occurs
§Examples
use ap_proxy::server::ProxyServer;
use std::net::SocketAddr;

let addr: SocketAddr = "127.0.0.1:8080".parse()?;
let server = ProxyServer::new(addr);
server.run().await?;
Source

pub async fn run_with_listener( &self, listener: TcpListener, ) -> Result<(), ProxyError>

Run the proxy server using an already-bound TcpListener.

This is useful in tests to avoid the race condition of binding a port, dropping the listener, and re-binding.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more