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

Function proxy_connection

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

Bridge a single local TCP connection through a WebSocket to the tunnel.

(
    tcp_stream: TcpStream,
    ws_url: &str,
)

Source from the content-addressed store, hash-verified

204
205/// Bridge a single local TCP connection through a WebSocket to the tunnel.
206async fn proxy_connection(
207 tcp_stream: TcpStream,
208 ws_url: &str,
209) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
210 let (ws_stream, _response) = tokio_tungstenite::connect_async(ws_url).await?;
211 let (ws_sink, ws_source) = ws_stream.split();
212 let (tcp_read, tcp_write) = tokio::io::split(tcp_stream);
213
214 let mut tcp_to_ws = tokio::spawn(proxy_tcp_to_ws(tcp_read, ws_sink));
215 let mut ws_to_tcp = tokio::spawn(proxy_ws_to_tcp(ws_source, tcp_write));
216
217 tokio::select! {
218 _ = &mut tcp_to_ws => {
219 ws_to_tcp.abort();
220 }
221 _ = &mut ws_to_tcp => {
222 tcp_to_ws.abort();
223 }
224 }
225
226 Ok(())
227}
228
229async fn proxy_tcp_to_ws(
230 mut tcp_read: tokio::io::ReadHalf<TcpStream>,

Callers 1

start_ws_proxyFunction · 0.85

Calls 3

proxy_tcp_to_wsFunction · 0.85
proxy_ws_to_tcpFunction · 0.85
spawnFunction · 0.50

Tested by

no test coverage detected