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
impl ProxyServer
Sourcepub fn new(bind_addr: SocketAddr) -> Self
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);Sourcepub async fn run(&self) -> Result<(), ProxyError>
pub async fn run(&self) -> Result<(), ProxyError>
Run the proxy server, accepting and handling connections.
This method:
- Binds to the configured address
- Spawns a background task to clean up expired rendezvous codes
- Accepts incoming WebSocket connections
- Spawns a handler task for each connection
- 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?;Sourcepub async fn run_with_listener(
&self,
listener: TcpListener,
) -> Result<(), ProxyError>
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§
impl !Freeze for ProxyServer
impl !RefUnwindSafe for ProxyServer
impl Send for ProxyServer
impl Sync for ProxyServer
impl Unpin for ProxyServer
impl UnsafeUnpin for ProxyServer
impl !UnwindSafe for ProxyServer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more