MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / start_ws_proxy

Function start_ws_proxy

crates/openshell-server/tests/ws_tunnel_integration.rs:186–203  ·  view source on GitHub ↗

Start a local TCP listener that bridges each connection to the WS tunnel. Returns the local address the proxy is listening on.

(ws_url: String)

Source from the content-addressed store, hash-verified

184///
185/// Returns the local address the proxy is listening on.
186async fn start_ws_proxy(ws_url: String) -> SocketAddr {
187 let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
188 let local_addr = listener.local_addr().unwrap();
189
190 tokio::spawn(async move {
191 loop {
192 let Ok((tcp_stream, _)) = listener.accept().await else {
193 continue;
194 };
195 let ws_url = ws_url.clone();
196 tokio::spawn(async move {
197 let _ = proxy_connection(tcp_stream, &ws_url).await;
198 });
199 }
200 });
201
202 local_addr
203}
204
205/// Bridge a single local TCP connection through a WebSocket to the tunnel.
206async fn proxy_connection(

Callers 1

startMethod · 0.85

Calls 2

proxy_connectionFunction · 0.85
spawnFunction · 0.50

Tested by

no test coverage detected