pub struct LocalProxy { /* private fields */ }Expand description
Manages proxying connections to local services
Implementations§
Source§impl LocalProxy
impl LocalProxy
Sourcepub fn new(connect_timeout: Duration) -> Self
pub fn new(connect_timeout: Duration) -> Self
Create a new local proxy with the specified connection timeout
Sourcepub fn register_service(&self, service_id: Uuid, config: ServiceConfig)
pub fn register_service(&self, service_id: Uuid, config: ServiceConfig)
Register a service for proxying
Sourcepub fn unregister_service(&self, service_id: Uuid)
pub fn unregister_service(&self, service_id: Uuid)
Unregister a service
Sourcepub async fn handle_connection(
&self,
service_id: Uuid,
connection_id: Uuid,
) -> Result<TcpStream>
pub async fn handle_connection( &self, service_id: Uuid, connection_id: Uuid, ) -> Result<TcpStream>
Handle an incoming connection request
This connects to the local service and returns a channel for the data stream. The caller is responsible for connecting the other end (server data channel).
§Errors
Returns an error if:
- The
service_idis not registered - Connection to the local service times out
- Connection to the local service fails
Sourcepub async fn proxy_streams(
local: TcpStream,
remote: TcpStream,
) -> Result<(u64, u64)>
pub async fn proxy_streams( local: TcpStream, remote: TcpStream, ) -> Result<(u64, u64)>
Proxy data between two streams bidirectionally
Returns when either side closes or an error occurs.
Returns the number of bytes (sent_to_remote, received_from_remote).
§Errors
This method does not return errors; it gracefully handles stream closure and I/O errors by terminating the proxy loop.
Sourcepub fn start_proxy(
&self,
connection_id: Uuid,
local: TcpStream,
remote: TcpStream,
) -> JoinHandle<Result<(u64, u64)>>
pub fn start_proxy( &self, connection_id: Uuid, local: TcpStream, remote: TcpStream, ) -> JoinHandle<Result<(u64, u64)>>
Start a proxy task for a connection
Spawns a background task that proxies data between the local and remote streams. The task is automatically cleaned up when the proxy completes or is cancelled.
Sourcepub fn cancel_connection(&self, connection_id: Uuid)
pub fn cancel_connection(&self, connection_id: Uuid)
Cancel a proxy connection
Sourcepub fn connection_count(&self) -> usize
pub fn connection_count(&self) -> usize
Get count of active connections
Sourcepub fn service_count(&self) -> usize
pub fn service_count(&self) -> usize
Get count of registered services