alternative mode: nginx speaks http directly with the daemon
Prototype of an architecture that removes the descriptor handover. Turned on
with SPU_HTTP_DIRECT in brisk-spush.phh; the default stays FALSE, that is the
historic behaviour, and the two modes live side by side.
Today the descriptor the daemon receives is the one of the nginx->apache
connection, already in clear because nginx stripped the TLS one hop earlier.
With this mode nginx opens an ordinary http connection on the unix socket and
the daemon uses it directly.
What it takes away:
- php-ancillary, the C extension
- mod_proxy_fdpass2, the apache module
- ngx_http_fdpass_module, the nginx module
- apache as an intermediate layer
- the kTLS requirement, which would be needed if nginx were to hand over the
browser descriptor (encrypted) instead of the cleartext one towards apache
That is three pieces of bespoke C, each of which needed a port in this very
migration, plus a kernel requirement. The daemon becomes an ordinary http
server behind a reverse proxy.
The code:
- spu_head_end() and spu_head_to_info() repackage the request read from the
network in the same format the control channel produced ("The-Request:" in
front of the request line), so that spu_process_info() does not know where
the data comes from
- the head of the request is NOT read by blocking: there is a single event
loop for every player. The connection is registered in the
PENDINGPAGE_WAITHEAD state among the watched sockets and completed
incrementally, reusing the machinery already in place for the bodies of
partial POSTs; if the body is still missing, it moves on to
pendpage_try_addwait seamlessly
- trim() on the header value: it was missing, and real http writes
"Name: value" with a space, which would have ended up inside the value,
breaking the cookies and the comparisons on Upgrade
Checked in the container with nginx 1.26.3 and php 8.4, without apache: the
page, an authenticated login, comet streaming, POST, and a complete game over
HTTPS with five players, the auction, 40 cards and the score saved on
postgresql. Secure websockets work (101 Switching Protocols and frames from
the daemon), confirmed from chrome too. Zero errors in the daemon.
Not verified yet: behaviour under load, and the reuse of connections between
nginx and the daemon (in the tests keepalive towards the upstream is off).
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014M1jiEq9cHdE5SE5j6vFuE