Repository navigation
Net: the WebSocket transport over libcurl CONNECT_ONLY - #1283
Conversation
net::connect_only opens a connection with CURLOPT_CONNECT_ONLY, so libcurl does the name lookup, the TCP connect and the TLS handshake with peer and host verification on, then hands over the socket from CURLINFO_ACTIVESOCKET. Bytes then move through curl_easy_send and curl_easy_recv, which report CURLE_AGAIN instead of blocking. The three symbols sit in their own dynlib! table with the same candidate list as the main one, loaded once and checked before any call, so a libcurl without them turns off only this socket. Nothing is dialled when only serialised TLS is safe, plain ws:// included: on that fallback every easy handle runs under the one serial lock, and this socket's would not. The nowan trigger refuses a name here as at the other three resolver doors. Trust is the device store or a shipped bundle; the pinned mode is refused. Every security option is checked and a refusal ends the open. Also updates docs/agent-reference.md, which counted two libcurl modules and a fixed number of dynlib! callers, and the refuse_name doc in net.rs. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Filippo Scatigna <[email protected]>
ws::run drives the merged codec over net::connect_only on the calling worker: ws:// or wss:// address, a message size limit, an idle bound and a cancel flag in, Opened/Text/Binary events out, and an End that says how the connection finished. An Outbox (any thread) queues text, binary and close, and refuses a close the protocol does not allow; a socket pair wakes the poll() at once and cannot read as closed while the Inbox lives. Every pass reads until CURLE_AGAIN before it polls, because TLS can hold decrypted bytes the socket no longer shows. A pass stops after 1 MiB and goes round again without polling, so a peer that never pauses cannot hold off the cancel flag, the deadlines or the outbox. Writes keep the same buffer until it is taken whole, as an OpenSSL retry requires. After a close or a protocol failure the client waits up to 2 s for the server to close the TCP connection; after a refused upgrade it does not wait. Masks and the key come from /dev/urandom. Tests run against loopback servers, plain and TLS: echo, a message queued before the upgrade, ping, the server's close, a 40 KB TLS burst read in 512-byte test chunks, an untrusted certificate, serial TLS, cancel under a peer that never pauses, idle, a dropped connection, a refused upgrade, invalid closes, the wake socket and bad addresses. An ignored test drives the Autobahn client suite. The connection module exposes close_code_allowed to its sibling. Also registers the three new bounds in ci/list-caps.ini, and updates the plx_net crate doc, the net layer comment in ci/module-layers.ini and the Watch Together entry in docs/parity-gaps.md, which said the transport did not exist yet. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Filippo Scatigna <[email protected]>
GLinnik21
left a comment
There was a problem hiding this comment.
Thanks, the transport is clear to follow, and the Autobahn run is a solid result for the codec and the echo path. The comments below are from a review of 81b74f19, grouped by priority:
Must fix before merge
- HTTP/1.1 is not pinned, so a
wssserver that picks h2 by ALPN never opens. Reproduced on this branch; the fix is one setopt (inline onconnect_only.rs:84). - A test race with
SerialTlsGuard/nowan: most dialling tests do not taketestlock::serial(). - Cancel is not seen in
finish()(up to 2 s) or during the connect (up to 10 s). Yes to the progress callback you offered. - Frames masked with
[0; 4]can be flushed on thefinishpath and on the cancel path.
Should fix
5. The 1001 on cancel gets one non-blocking flush and can be lost behind a partial frame.
6. Outbox returns true for messages that will never be sent: after a close, after run ends, and on a reused Inbox.
7. host_of duplicates origin::url_host.
8. require duplicates require_setopt!, with different log wording.
Not blocking: open bypasses request_tls_sink, so it has none of the keypin/roots fallback rungs and no ResolvePin. Please list it under "Not covered"; it will get its own issue.
None of these would show up in Autobahn: it runs over ws://, never cancels, and never sends after a close.
Generated by Claude Code
| } | ||
| } | ||
| if let Some(end) = ended { | ||
| return if matches!(end, End::Failed(Fault::Handshake(_))) { end } else { self.finish(end) }; |
There was a problem hiding this comment.
Must fix: frames masked with the [0; 4] fallback can reach the wire. The short check runs before each flush in the main loop, but two paths skip it:
ended→finish. If a refill of/dev/urandomfails inside the read loop while the codec answers a Ping or echoes a Close,shortis set.endedisSome, though, so this line goes tofinish, which pushestake_outgoing()and flushes the all-zero-masked frames. The run also reportsClosed/Failedinstead ofNoEntropy.- The cancel branch (lines 166–169) masks a new 1001 close and flushes it without checking
short.
RFC 6455 §5.3 requires an unpredictable masking key. Please check short before every push to wire. The simplest way is in one place: inside a helper that does push(take_outgoing()) and flush.
Generated by Claude Code
There was a problem hiding this comment.
Fixed in 0669636: every write goes through send_out, which returns NoEntropy before it pushes anything once a refill has failed. finish and the cancel path call it too. There's no test, since nothing here can make /dev/urandom fail.
SerialTlsGuard and the nowan trigger are process-global, and connect_only::open reads both. A test that dialled while another forced serial TLS could be refused and fail at random. Every test that dials now takes testlock::serial(), as the net_stream_tests dials do. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Filippo Scatigna <[email protected]>
…eading require_setopt! and the CAINFO refusal in request_tls_sink now call require_option and require_trust_store, and connect_only::open calls the same two, so a refused option logs the same line on both paths. The nowan gate reads the host through origin::url_host instead of a second parser. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Filippo Scatigna <[email protected]>
Since 7.62, a libcurl built with nghttp2 offers h2 by ALPN, and in CONNECT_ONLY mode it writes the HTTP/2 preface itself when the server picks h2, so the upgrade request went onto an HTTP/2 connection and the run ended Lost. CURLOPT_HTTP_VERSION is now HTTP/1.1, and checked. The new test serves wss offering h2 and http/1.1 and must reach Opened; it failed before the pin. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Filippo Scatigna <[email protected]>
… linger connect_only::open takes the cancel flag and installs libcurl's progress callback for the connect, XFERINFO or PROGRESS before 7.32, as stream_tls does. A cancel during the name lookup, the TCP connect or the TLS handshake ends the open with OpenError::Cancelled within about a second, libcurl's idle callback rate. finish() reads the flag on every pass and waits at most POLL_CAP. Two tests: a TLS handshake that never completes, and a server that holds the TCP connection after its close. Both failed before, after 10 s and 2 s. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Filippo Scatigna <[email protected]>
…, an honest Outbox This commit carries three fixes, all in transport.rs: - Every write goes through send_out, which stops with NoEntropy before it pushes anything when /dev/urandom failed, the finish and cancel paths included. - A cancel keeps flushing the 1001 for up to 300 ms instead of making one non-blocking attempt. - Outbox and Inbox share a live flag. Outbox::close clears it, and so do the end of the connection and dropping the Inbox, so a message that will never be sent returns false. run takes the Inbox by value, so a channel serves one connection. Tests: an Outbox after its close, and the echo test checks the Outbox after run. The entropy and 1001 paths have no test: there is no seam to fail /dev/urandom, and no way to hold a partial frame on loopback. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Filippo Scatigna <[email protected]>
|
Thanks for the review. All eight points are fixed in five commits on top of 81b74f1, one per group of fixes, and each passes
The description now covers the HTTP/1.1 pin, the cancel bounds and the |
GLinnik21
left a comment
There was a problem hiding this comment.
Thanks, all eight points are addressed in 9a68922..0669636. Checked on 0669636d:
- Read the fixes: the HTTP/1.1 pin, every dialling test under
testlock::serial(), cancel in the connect (progress callback) and infinish(), onesend_out()gate for entropy before every write, the bounded 1001 ingoing_away(), theOutboxlive flag, plusorigin::url_hostand the sharedrequire_option/require_trust_store. make test-crate C=plx_net T=ws::three runs in a row, libcurl 8.5.0 with nghttp2:55 passed; 0 failed; 1 ignoredeach time.- CI: 14/14 green.
Agreed that the NoEntropy path and the bounded 1001 flush stay untested for now. The request_tls_sink bypass is tracked under "Not covered" and will get its own issue.
Generated by Claude Code
Conflict: docs/agent-reference.md, the dynlib callers paragraph. Both sides dropped the old caller count; kept this branch's wording (it excludes dynlib.rs from the grep) and main's new `net::connect_only` sentence. Semantic fix the merge needs: main's plxnative#1283 added `net::connect_only`, a third libcurl table bound with `raw::load(None)`, i.e. always the system candidates. Its easy handle comes from `net::curl_easy_init`, which in a CURLSTACK=1 build is the bundled libcurl-plx.so.4, so curl_easy_send/recv/getinfo from the system library would be handed a handle from another libcurl. The table now binds from `net::bundled_curl()` when it is Some, as curlio's multi table does; the agent-reference and curlstack module docs say so. Signed-off-by: fraygox <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Part 2 of 4 for Open Watch Party (#1090): the transport that runs the codec from #1273 over the socket libcurl hands back with
CURLOPT_CONNECT_ONLY. Nothing in the app calls it yet. The OWP client crate is parts 3 and 4.What
net::connect_only: libcurl does the name lookup, the TCP connect and TLS with peer and host verification, then returns the socket fromCURLINFO_ACTIVESOCKET.sendandrecvwrapcurl_easy_send/curl_easy_recvand returnIo::AgainforCURLE_AGAIN.curl_easy_send,curl_easy_recvandcurl_easy_getinfoare their owndynlib!table, with the same candidates in the same order ascurl, loaded once and checked before any call. A libcurl without them loses only the WebSocket.!threaded_tls_ready(), forws://as well aswss://: on that fallback every easy handle runs under the serial lock, and this one would not.refuse_nameapplies, throughorigin::url_host, so/tmp/plxnative-nowanrefuses a WebSocket name as it does at the other three resolver doors.CURLOPT_HTTP_VERSION). Otherwise a libcurl with nghttp2 offers h2 by ALPN and, when the server picks it, writes the HTTP/2 preface itself before the upgrade.Tls::CaorTls::CaBundle;Tls::Pinnedis refused.CURLOPT_PROTOCOLS(HTTPS or HTTP only), both verify options,CAINFO,HTTP_VERSIONandCONNECT_ONLYare checked throughrequire_optionandrequire_trust_store, the funnel's own checks, so a refusal ends the open and logs the same line as inrequest_tls_sink.stream_tlsdoes.load_from(net::bundled_curl()), as agreed in Net: an RFC 6455 WebSocket codec, sans-IO, for Open Watch Party #1273.ws::rundrives one connection on the calling worker (it takes&OffFrame) until it ends:Dial(ws://orwss://URL, trust, message limit, idle bound), a cancel flag and theInbox, by value, so a channel serves one connection. Out:Opened,TextandBinaryevents, then anEnd:Closed { code, reason },Failed(Fault),Refused(..),Lost,TimedOut,Idle,NoEntropyorCancelled.Outbox(clonable, any thread) queues text, binary and close, and refuses a close code or reason the protocol does not allow. It returnsfalseonce nothing more will be sent: after its own close, after the connection ends, or once theInboxis gone. A message queued while the server's close is already on its way can still returntrueand be dropped. A Unix socket pair wakes thepoll()at once; theInboxholds its write end, so it never reads as closed. Messages queued before the upgrade go out once it is accepted.CURLE_AGAINbefore it polls. A pass stops after 1 MiB and goes round again without polling, so the cancel flag, the deadlines and the outbox are still read under a peer that never pauses.CURLE_AGAINis retried with the same buffer, and frames queued meanwhile wait in a second one (OpenSSL's retry rule)./dev/urandom, read 256 bytes at a time. Every write goes through one check that ends the run withNoEntropybefore anything is pushed, once a refill has failed.Dial, through the codec.Autobahn
Autobahn|Testsuite 25.10.1 (autobahn 0.10.9), with the fuzzing server from
crossbario/autobahn-testsuitein Docker. The client is the ignored testws::transport::tests::autobahn_client_cases, which echoes every text and binary message, with a 64 MiB limit. Cases 12.* and 13.* (permessage-deflate) are excluded, since no extension is negotiated.LD_LIBRARY_PATH)receive, before the test's echo of the valid message is queued. Strict expects the echo first.To repeat it:
The report is
autobahn/reports/clients/index.html.Against the OWP relay
A scratch test, not in this diff, drove
ws::runthrough create,joined,ping/pong, a hold with no data messages, a secondpong,end,closedand a 1000 close:wss://eu.relay.openwatch.party/v1/wswith a 75 s hold (the relay pings every 30 s and drops a connection after 60 s of silence): passed with libcurl 8.5.0 and 7.53.1;owp-relay:1locally with--timer-scale 0.1and a 15 s hold: passed with both.Checks
On the committed tree, WSL2 x86_64:
make checkon 0669636: 43 suites, 25681 passed, 0 failed, 200 ignored.make check-nodef: clean.cargo check --lib --target armv7-unknown-linux-gnueabi -p plx_base -p plx_net: clean.make test-crate C=plx_net T=ws::: 55 passed (33 codec, 22 transport), plus the ignored Autobahn driver. The same binary with libcurl 7.53.1: 55 passed.CURLE_AGAIN: without it the 40 KB TLS burst takes over 2 s, because the tests read in 512-byte chunks and OpenSSL keeps the rest of each record;Outboxclose check, and the wake socket's write end held by theInbox;Outboxafter its close.fw-compat-reviewer(a source review, since no ARM ELF can be built here):tools/fwcompat.py:libcurl.so.5on 1.2.0–4.10.0,libcurl.so.4on 5.3.1–11.2.0.curl_easy_getinfohas...beforeout. The candidates and their order matchcurl. No#[link], no newDT_NEEDED.CURLINFO_ACTIVESOCKETneeds 7.45.0. The database places 4.4.2–4.10.0 between 7.44 (it exportscurl_pushheader_bynum) and 7.56 (nocurl_mime_init), and you named 7.53.1 for those sets. On a 7.44 the open would end withNoSocket.pr-reviewer: one round, 2 major and 5 minor findings. Six are fixed in this branch: the wake socket at EOF, thews://dial under serial TLS, the unbounded linger, the silently refused close,nowan, and the read bound per pass. The seventh is under "Not covered".doc-claim-auditor: three findings, fixed (docs/agent-reference.mdtwice,ci/module-layers.ini).T=ws::on its own.No
Cargo.toml,Makefile, workflow or module change: theci/module-layers.iniedit is the net layer's comment. So there is nobuild-benchtable.Not covered
connect_only::openbuilds its handle outsiderequest_tls_sink. It has no keypin or roots rung, so on a set with a stale trust store or a wrong clock awssopen fails with rc 60 where ordinary requests recover, and it has noResolvePin. You will open an issue for it.NoEntropypath and the bounded 1001 flush have no test: nothing here can make/dev/urandomfail, and a partial frame can't be held in flight on loopback.CURLE_AGAIN, so the test passed with the bound removed too.net/connect_only.rsis not infw-compat-reviewer's scope table. I can add it here.Refs #1090.
🤖 Generated with Claude Code