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

Function peek_tunnel_protocol

crates/openshell-supervisor-network/src/proxy.rs:406–428  ·  view source on GitHub ↗
(client: &TcpStream)

Source from the content-addressed store, hash-verified

404}
405
406async fn peek_tunnel_protocol(client: &TcpStream) -> Result<Option<TunnelProtocol>> {
407 let mut peek_buf = [0u8; TUNNEL_PROTOCOL_PEEK_BYTES];
408 let deadline = tokio::time::Instant::now() + TUNNEL_PROTOCOL_PEEK_TIMEOUT;
409
410 loop {
411 let n = client.peek(&mut peek_buf).await.into_diagnostic()?;
412 if n == 0 {
413 return Ok(None);
414 }
415
416 let peek = &peek_buf[..n];
417 let protocol = classify_tunnel_protocol(peek);
418 if protocol != TunnelProtocol::Unsupported
419 || !could_be_supported_tunnel_protocol_prefix(peek)
420 || n == peek_buf.len()
421 || tokio::time::Instant::now() >= deadline
422 {
423 return Ok(Some(protocol));
424 }
425
426 tokio::time::sleep(TUNNEL_PROTOCOL_PEEK_POLL).await;
427 }
428}
429
430fn emit_connect_activity_if_l4_only(
431 tx: &Option<ActivitySender>,

Calls 3

classify_tunnel_protocolFunction · 0.85
lenMethod · 0.80

Tested by

no test coverage detected