(client: &TcpStream)
| 404 | } |
| 405 | |
| 406 | async 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 | |
| 430 | fn emit_connect_activity_if_l4_only( |
| 431 | tx: &Option<ActivitySender>, |
no test coverage detected