mirror of
https://github.com/NVIDIA/OpenShell.git
synced 2026-10-26 06:52:57 +08:00
3.3 KiB
3.3 KiB
Server Architecture
Overview
navigator-server is the gateway service that exposes gRPC APIs, HTTP health endpoints, and
optional TLS on a single shared port. It also persists sandbox data and coordinates Kubernetes
sandbox lifecycle.
Components
- Entry point:
crates/navigator-server/src/main.rs- Loads config, sets up tracing, and invokes
run_server.
- Loads config, sets up tracing, and invokes
- Server runtime:
crates/navigator-server/src/lib.rs- Builds shared
ServerState, starts background watchers, and accepts connections.
- Builds shared
- Protocol multiplexing:
crates/navigator-server/src/multiplex.rs- Routes requests by inspecting
content-type. application/grpc*goes to gRPC handlers; everything else to HTTP router.
- Routes requests by inspecting
- gRPC API:
crates/navigator-server/src/grpc.rs- Implements
Navigatorservice (health, sandbox CRUD, watch streaming).
- Implements
- HTTP API:
crates/navigator-server/src/http.rs- Simple health endpoints:
/health,/healthz,/readyz.
- Simple health endpoints:
- TLS:
crates/navigator-server/src/tls.rs- Wraps accepted connections with rustls when TLS is configured.
- ALPN advertises
h2andhttp/1.1so gRPC and HTTP can share the port.
- Persistence:
crates/navigator-server/src/persistence/- Stores protobuf messages in SQLite or Postgres.
- Selected by database URL.
- Sandbox integration:
crates/navigator-server/src/sandbox/- Creates sandbox CRDs in Kubernetes and watches for status updates.
- Event and log buses:
crates/navigator-server/src/sandbox_watch.rs,crates/navigator-server/src/tracing_bus.rs- In-memory buses used to stream sandbox updates and logs over gRPC.
Connection Flow
- TCP listener accepts a connection (TLS optional).
- If TLS is enabled, the connection is upgraded with rustls.
- The multiplexing layer inspects each request:
content-type: application/grpc-> gRPC service- otherwise -> HTTP router
Multiplexing Details
The multiplexing implementation is in crates/navigator-server/src/multiplex.rs and uses
Hyper’s per-connection server with a custom service:
- Each accepted connection is handed to Hyper’s
server::conn::auto::Builder, which handles HTTP/1.1 and HTTP/2 on the same socket. - A lightweight
MultiplexedServiceimplementshyper::service::Service<Request<Incoming>>. - For each request, the service checks the request headers and routes based on:
content-typeheader starts withapplication/grpc-> gRPC handler- otherwise -> HTTP health router
- Both the gRPC and HTTP handlers are
tower::Serviceimplementations. Requests are converted into a boxed body type (BoxBody) to normalize differences between the two stacks, then the response is boxed back for Hyper.
TLS + ALPN Interaction
When TLS is enabled:
TlsAcceptorwraps the incoming TCP stream before it reaches Hyper.- ALPN advertises
h2andhttp/1.1, which lets:- gRPC clients negotiate HTTP/2 automatically
- health checks fall back to HTTP/1.1 if needed
Routing Assumptions
- gRPC detection is header-based and assumes well-formed gRPC requests include
content-type: application/grpc(including variants likeapplication/grpc+proto). - Non-gRPC traffic (including HTTP health checks) is routed to the HTTP router.
Notes
- gRPC and HTTP share the same bind address and port.
- TLS requires ALPN to negotiate
h2for gRPC andhttp/1.1for health checks.