Repository navigation
Conversation
…, install gateways from signed releases Everything since the last sync, in one commit; this clone keeps its own history. A revoked gateway's cameras can be retired from the roster: a tombstone rather than a delete, so recordings still play and a gateway reporting the camera again brings it back with its history. The action refuses while the gateway is still in service. Each camera can have its own credentials, encrypted on the gateway under the same key as its identity and entered with `vms-gateway credentials`, which reads the password from stdin. The shared CAMERA_USERNAME and CAMERA_PASSWORD stay as the fallback. Gateways install on a site box from a signed release: install.sh verifies the Ed25519-signed manifest before touching anything and sets up a hardened systemd service with a daily self-update. An update keeps a new binary only once the API has accepted a heartbeat from it, and rolls back otherwise. make check-installer runs all of it on a real systemd. Retina now comes from a pinned fork carrying the fix for decimal SSRCs, until upstream releases it. docs/INSTALL-GATEWAY.md says what is checked and what is not; no release has been cut yet, because the release key does not exist yet. Plus the upstream design for TURN over TCP in webrtc-rs, which is open as webrtc-rs/rtc#254 and webrtc-rs/webrtc#907.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #907 +/- ##
==========================================
+ Coverage 86.36% 86.53% +0.17%
==========================================
Files 66 67 +1
Lines 14315 15245 +930
==========================================
+ Hits 12363 13193 +830
- Misses 1952 2052 +100
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@rainliu thanks for merging webrtc-rs/rtc#254. This is now ready for review: rebased on master at 7dba253, with the Three things changed in the rebase:
|
rainliu
left a comment
There was a problem hiding this comment.
There are also robustness gaps (fine as follow-ups)
-
A stalled TURN TCP connection freezes the whole driver. poll_writes awaits tcp_transport.write(), which awaits write_all and so waits for the socket to become writable.
- If the connection is black-holed (network handover, middlebox), the send buffer fills and the event loop stops: no reads, no timers, no ICE restart, no close().
- The stall lasts until the kernel gives up, which can be many minutes.
- The pattern already exists for ICE-TCP, but this PR makes it the primary path on exactly the networks where TCP stalls happen.
- A fix would be a write deadline, or a bounded per-stream queue with a non-blocking write that drops on overflow, treating a stuck stream as lost.
-
A server that accepts TCP but never answers holds gathering for 39.5 s. The connect is bounded at 5 s, but after rtc#254 the Allocate over TCP waits the full Ti (UDP gives up after about 8 s). A captive proxy that accepts any TCP connection would do this, and a 401 retry could double it. Non-trickle apps waiting for Complete will stall. I'd add a gathering deadline for the TCP Allocate that marks gather_finished without killing the client.
-
No TURN-over-TCP at all when there are no UDP sockets. gather() derives the address families to connect from self.local_addrs, which are the UDP sockets. A peer built with only with_tcp_addrs gets zero connects, even though the code comment says the TCP source address "has nothing to do with the UDP sockets". Either derive families from the resolved server addresses or document the limit.
|
|
||
| /// The outcome of a [`ConnectTcp`](RTCTurnRelayEventOut::ConnectTcp). Returns the | ||
| /// four-tuple to register as a TURN stream, or `None` when there is nothing to keep. | ||
| pub(crate) fn on_tcp_connected( |
There was a problem hiding this comment.
Gathering can hang if on_tcp_connected errors (turn_relayer.rs, the TurnClient::new(...)? and client.allocate(...)? lines). The pending entry is already removed, but the ? returns skip maybe_emit_gathering_complete(). If that was the last pending item, the relayer stays in Gathering forever; the driver only logs "TURN over TCP could not start". This is unlikely to trigger, and the fix is to call maybe_emit_gathering_complete() on the error path.
There was a problem hiding this comment.
Fixed in 0ef9faf. Both ? paths now settle gathering before returning the error, like the connect failure and the collision above them.
The test drives it through the constructor rather than asserting on the code: a four-tuple whose ends disagree on address family makes TurnClient::new refuse (it resolves the server for the local family), the error still reaches the caller, and TurnGatheringComplete is emitted instead of the relayer waiting for a candidate that is never coming.
| let result = match crate::runtime::timeout( | ||
| &*runtime, | ||
| TURN_TCP_CONNECT_TIMEOUT, | ||
| runtime.connect_tcp(server), |
There was a problem hiding this comment.
No TCP_NODELAY on the TURN connection. connect_tcp (tokio and smol) never sets it. This stream now carries every media and data packet as a separate small write, so Nagle plus delayed ACK will add latency spikes of tens of milliseconds. ICE-TCP already had this gap, but it matters far more here. A set_nodelay(true) in connect_tcp would fix it.
The set_nodelay(true) should be added inside runtime implementations
There was a problem hiding this comment.
Fixed in 8220b52, in both runtimes: set_nodelay(true) right after the connect, inside connect_tcp, so ICE-TCP gets it as well.
The test reads the option off the socket rather than off the code that sets it: it finds this process's socket by the local address the stream reports (/proc/self/fd, Linux-only like the existing connect_tcp_does_not_block_the_executor) and asks the kernel. It failed before the change on the tokio runtime and passes on both now.
|
@rainliu thanks for the review — all of it is fair. Pushed, and rebased on master: the Addressed here:
Taking you up on follow-ups for the two that are real work:
I'll open both unless you would rather they land here first. |
|
Both robustness follow-ups are written and tested. They sit on a branch stacked on this one Bounding the Allocate over TCP ( Queueing writes ( While writing the test for this, something bigger turned up, and it isn't TCP'sThe new integration test uses a TURN server that accepts the connection and then says
So the deadline in NumbersAgainst the silent TCP server: gathering 8.003 s, |
|
Please rebase it to resolve conflicts |
…hen they end RTCTcpTransport framed every stream with RFC 4571's length prefix, which is ICE-TCP's framing. A connection to a TURN server carries STUN and ChannelData back to back with no prefix (RFC 8656 §12.5), so it could not share that path. Streams now carry their framing from registration: register_stream keeps RFC 4571 for ICE-TCP, register_turn_stream splits with TurnStreamDecoder and writes messages as they are. Around that: - The peer-address fallback that ICE-TCP writes rely on never picks a TURN connection, so ICE traffic cannot land on one. - A TURN connection that ends — EOF, a read error, or bytes that are not TURN — is removed and queued for take_closed_turn_streams, and a later write to it is an error rather than Ok(0), so the relayer's existing write-failure path runs. A reset ends a TURN connection instead of re-arming a read on it. - ICE-TCP behaviour is unchanged: test_ice_tcp_only_connection passes, and a unit test pins its length prefix. Refs webrtc-rs#848.
The relayer skipped every turn: URL that was not UDP, so a peer whose network lets TCP out but not UDP gathered no relay candidate at all. turn:…?transport=tcp is now used; turns: is still skipped, for the TLS change that follows. For a TCP URL the relayer does not create a client straight away. It asks the host for a connection — one per server and address family, since the connection's source address is the kernel's and unrelated to the UDP sockets — and the driver opens it off the event loop with a 5 s bound, the way active ICE-TCP connects already work. on_tcp_connected then creates the client over TCP, asking for a UDP relay (RFC 8656 §7.1), and the driver registers the stream with TURN framing. Around that: - Gathering does not complete while a connect is pending, and a failed or timed-out connect ends that server's part in it. - Connect ids come from a process-wide counter, so one that finishes after an ICE restart or a reconfiguration matches nothing and its stream is dropped. - A TURN connection that ends is reported to the relayer through the existing SocketWriteFailure path, and a client the relayer lets go of on reconfiguration releases its connection. - Inbound matching checks the transport, so a datagram can never be taken for a stream client's traffic even when a TCP source port equals a UDP socket's. Refs webrtc-rs#848.
A TCP twin of run_mock_turn_server: the same answers, on a stream, split with TurnStreamDecoder. Two tests on it: - a relay-only peer connection given turn:…?transport=tcp gathers a relay candidate and no host candidate, and the server sees REQUESTED-TRANSPORT 17 — the connection is TCP, the relay is UDP; - a TURN server whose TCP port refuses the connection costs it its relay but lets gathering complete, promptly, without one. Each was run against a relayer broken the way it guards — TCP URLs skipped again, and a failed connect that never lets go of gathering — and failed. Refs webrtc-rs#848.
…al server The mock proves gathering; this proves the data path. Two relay-only peers connect through one TURN server — the offerer reaching it over TCP, the answerer over UDP — and a data-channel message crosses. With the offerer limited to relay candidates and given only a transport=tcp URL, there is no way across but a relay allocated, refreshed and permitted over TCP. Skips unless WEBRTC_TURN_TCP_SERVER is set, like turn_credential_rotation; the module docs give the coturn command it was run against. Against coturn 4.6 it passes, and with TCP URLs skipped again it fails at the offerer's gathering. Kept as its own commit, to drop if an env-gated test is not wanted here. Refs webrtc-rs#848.
Review follow-ups to TURN over TCP. A credential-only change re-signs established allocations instead of regathering them, and a client still mid-Allocate already makes it fall through to the full teardown. A TCP connect in flight is the same thing — its client does not exist yet — but was not counted, so beside an established UDP client it would come up on the old password. It now counts. A connected stream that cannot report its peer address is treated as a failed connect rather than given the resolved address, which may not be the one it reached. Refs webrtc-rs#848.
Everything after the pending entry is removed is a way out of on_tcp_connected, and two of those ways were an early `?`: a client whose constructor refuses the connection, and an Allocate that cannot be started. The pending entry is gone by then, so the relayer never reaches maybe_emit_gathering_complete and stays in Gathering for good, leaving one line in the log to explain a peer that never finishes. Both failures now settle gathering before returning the error, like the connect failure and the collision above them.
gather derived the address families to connect from self.local_addrs, which are the UDP sockets, while the comment beside it said the TCP source address has nothing to do with them. Both cannot be true: a peer built with with_tcp_addrs alone got zero connects and no relay candidate, which is exactly the TLS-only egress this path is for. The UDP sockets still say which families the host has, so they are kept as the answer when there are any. When there are none, the server's own resolved addresses are the only word on what is worth trying.
connect_tcp never set it, in either runtime. ICE-TCP has always had the gap; with TURN over TCP this stream carries every media and data packet as its own small write, so Nagle holds each one until the last is acknowledged — tens of milliseconds of added latency, on exactly the networks that forced TCP in the first place. The test reads the option off the socket rather than off the code that sets it: it finds this process's socket by the local address the stream reports and asks the kernel.
|
Rebased onto current master (1c07e9f), head is now 483eb7e. Six of the eight commits are unchanged; two needed resolving against #928 in
Verified locally after the rebase: fmt clean, relayer + tcp_transport lib tests, On the review's follow-ups: the TCP gathering deadline (2) and a bounded write queue so a stalled stream cannot freeze the driver (1) are done on a branch on top of this one; I will open them as a separate PR once this lands, or fold them in here if you would rather review them together. |
Closes the TCP half of #848.
turn:…?transport=tcpnow gathers a relay candidate. The connection to the TURN server is TCP and the allocation is still UDP.turns:is still skipped, for the TLS follow-up.Builds on webrtc-rs/rtc#254 (merged); the
rtcsubmodule points at that merge, 7b7aeb5.How it's shaped
As you suggested, it goes through
RTCTcpTransport:register_streamkeeps RFC 4571 for ICE-TCP.register_turn_streamsplits withTurnStreamDecoderand writes messages without a prefix. The ICE-TCP peer-address fallback never picks a TURN connection.on_tcp_connectedthen creates the client over TCP, asking for a UDP relay.SocketWriteFailurepath. After that, a write to it is an error rather thanOk(0). A client the relayer lets go of on reconfiguration releases its connection.Write routing needed no change: relayer output already carries its client's transport, and
handle_writealready sends TCP-tagged messages toRTCTcpTransportfirst.Known limits
AsyncTcpStreamhas no shutdown, and a single future in theFuturesUnorderedcannot be cancelled. In practice the server closes it when the allocation lapses.connect_tcptakes no local address, so the TCP connection's source interface is the kernel's choice. Changing that is public API, and I've left it alone.connect_tcpis a blockingstdconnect inside the async block. That was already true and is unchanged here.Tests
turns:is still skipped; reconfiguration releases the connection; a credential change during a connect regathers.tests/ice_test.rsgets a TCP twin ofrun_mock_turn_server. With it, a relay-only peer gathers a relay candidate over TCP (the server sees REQUESTED-TRANSPORT 17), and a refused TCP port completes gathering without one.tests/turn_over_tcp.rs(separate commit, env-gated liketurn_credential_rotation) connects two relay-only peers through a real TURN server — one over TCP, one over UDP — and a data-channel message crosses. It passes against coturn 4.6 and fails with TCP URLs skipped. The module docs give the coturn command.Each new test was also run against the relayer or transport broken the way it guards, and failed. The full suite passes: 167 tests across 46 targets, 1 ignored (a doc example that was already
ignore).turn_over_tcpskips without its env var; set, against coturn, it passes.Refs #848.