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

Function handle_tcp_connection

crates/openshell-supervisor-network/src/proxy.rs:540–1366  ·  view source on GitHub ↗
(
    mut client: TcpStream,
    opa_engine: Arc<OpaEngine>,
    identity_cache: Arc<BinaryIdentityCache>,
    entrypoint_pid: Arc<AtomicU32>,
    tls_state: Option<Arc<ProxyTlsState>>,
    inference_

Source from the content-addressed store, hash-verified

538// sites.
539#[allow(clippy::too_many_arguments)]
540async fn handle_tcp_connection(
541 mut client: TcpStream,
542 opa_engine: Arc<OpaEngine>,
543 identity_cache: Arc<BinaryIdentityCache>,
544 entrypoint_pid: Arc<AtomicU32>,
545 tls_state: Option<Arc<ProxyTlsState>>,
546 inference_ctx: Option<Arc<InferenceContext>>,
547 policy_local_ctx: Option<Arc<PolicyLocalContext>>,
548 trusted_host_gateway: Arc<Option<IpAddr>>,
549 secret_resolver: Option<Arc<SecretResolver>>,
550 dynamic_credentials: Option<
551 Arc<
552 std::sync::RwLock<
553 std::collections::HashMap<String, openshell_core::proto::ProviderProfileCredential>,
554 >,
555 >,
556 >,
557 denial_tx: Option<mpsc::UnboundedSender<DenialEvent>>,
558 activity_tx: Option<ActivitySender>,
559) -> Result<()> {
560 let mut buf = vec![0u8; MAX_HEADER_BYTES];
561 let mut used = 0usize;
562
563 loop {
564 if used == buf.len() {
565 respond(
566 &mut client,
567 b"HTTP/1.1 431 Request Header Fields Too Large\r\n\r\n",
568 )
569 .await?;
570 return Ok(());
571 }
572
573 let n = client.read(&mut buf[used..]).await.into_diagnostic()?;
574 if n == 0 {
575 return Ok(());
576 }
577 used += n;
578
579 if buf[..used].windows(4).any(|win| win == b"\r\n\r\n") {
580 break;
581 }
582 }
583
584 let request = String::from_utf8_lossy(&buf[..used]);
585 let mut lines = request.split("\r\n");
586 let request_line = lines.next().unwrap_or("");
587 let mut parts = request_line.split_whitespace();
588 let method = parts.next().unwrap_or("");
589 let target = parts.next().unwrap_or("");
590
591 if method != "CONNECT" {
592 return handle_forward_proxy(
593 method,
594 target,
595 &buf[..],
596 used,
597 &mut client,

Callers 1

start_with_bind_addrMethod · 0.85

Calls 15

respondFunction · 0.85
handle_forward_proxyFunction · 0.85
parse_targetFunction · 0.85
evaluate_opa_tcpFunction · 0.85
emit_denialFunction · 0.85
query_allowed_ipsFunction · 0.85
is_host_gateway_aliasFunction · 0.85

Tested by

no test coverage detected