* Match IPv4 clients against the relay lists in their IPv4 form
hbbr listens dual-stack by default, so a direct IPv4 client reaches
relay() as ::ffff:a.b.c.d. relay() checked BLACKLIST and BLOCKLIST with
that form, while the lists hold the plain IPv4 that `ba` and `Ba` are
given. A blacklisted IPv4 client was therefore never throttled, and
adding it to the blocklist did not end its session. handle_connection
already normalizes with try_into_v4 for its accept-time check; relay()
now does the same.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JAxkkiaGp2k8okvs4MpCUq
* Keep IPv4-mapped list entries matching in relay()
The previous commit looked the lists up in the plain IPv4 form only, so
an entry in the ::ffff:a.b.c.d form stopped matching. That is the form
`usage` and the pairing logs print, so an admin copying an address from
them, or an existing list file holding one, lost the throttle and the
mid-session blocklist check. relay() now matches either form.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JAxkkiaGp2k8okvs4MpCUq
* Match either form of an IPv4-mapped client at accept too
handle_connection checked the blocklist in plain IPv4 form only, so an
entry in the ::ffff: form, the one usage prints, let the client connect.
If that client was the leg parked first, relay() never checks it and the
whole session ran. It now matches either form, as relay() does.
The relay() test gains a client that is not listed, which must outlive
the first list check, and a new test covers the accept check.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JAxkkiaGp2k8okvs4MpCUq
* Require a timeout in the list tests' unlisted cases
An unlisted client passed if relay() or the connection ended with an
error, not only if it stayed up until the timeout. Each case now names
the one outcome it expects.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JAxkkiaGp2k8okvs4MpCUq
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
hbbs drops a connection whose frame header announces more than
MAX_MESSAGE_KB (default 64, capped at 65536) on 21115, 21116 and the
websocket 21118, and gives each websocket 8 KiB buffers instead of
tungstenite's 128 KiB default.
hbbr bounds the relay request to 128 KiB until the two legs pair, then
lifts the bound on framed legs and restores tungstenite's defaults on
websocket legs. That needs set_config on an accepted stream, so
tokio-tungstenite and tungstenite now come from the rustdesk-org forks.
Claude-Session: https://claude.ai/code/session_01JAxkkh9Gd5dwGW8vL9JNV8
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Since #717 the console sends its reply with write_all, which waits until
every byte is sent. A local client that sends a command and then stops
reading would hold the task and its socket forever. Give the write the
same 1 s deadline as the read above it, and log a reply that fails or
runs late instead of dropping the error.
Claude-Session: https://claude.ai/code/session_01JAxkkiaGp2k8okvs4MpCUq
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* Fix relay waiter expiration after pair ID reuse
* Keep waiter regressions separate from other relay tests
* Document changed function contracts
* Clarify relay authentication documentation
The peer sends the relay uuid to whatever relay_server names, so a uuid
carrying line breaks reaches that service verbatim. RequestRelay and
RelayResponse with a uuid that is empty, longer than 128 bytes, or outside
[A-Za-z0-9_-] now close the connection. The empty ack a peer sends for a
RequestRelay is still allowed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JAxkkh9Gd5dwGW8vL9JNV8
* fix(hbbs): bound the punch-request record store
PUNCH_REQS grew without limit; its dedupe scan only covers the newest 30
entries, so cycling 31 online peer ids from one source appended a record
per request for the lifetime of the process. Keep at most 10,000 entries,
evicting the oldest.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PkpVy2ufxgEjKd3SjXPnJ8
* feat(hbbs): make the punch-request record cap configurable
MAX_PUNCH_REQUESTS sets how many records the punch-requests console
command keeps (default 10000); 0 disables recording.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PkpVy2ufxgEjKd3SjXPnJ8
* fix(hbbs): cap peer id length at 253 bytes
RegisterPk accepted ids up to a whole UDP datagram, so 31 registered
peers with ~64 KB ids still let the bounded punch-request store reach
hundreds of MB. Reject longer ids in RegisterPk and RegisterPeer, the
same bound the Pro server uses.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PkpVy2ufxgEjKd3SjXPnJ8
* feat(hbbs): keep 100000 punch-request records by default
With peer ids capped at 253 bytes a full store is roughly 45 MB at
worst, so a larger default keeps more console history.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PkpVy2ufxgEjKd3SjXPnJ8
* test(hbbs): assert which punch-request records survive eviction
The length check alone passed if the newest record were evicted or new
records were dropped once full.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PkpVy2ufxgEjKd3SjXPnJ8
* test(hbbs): cover MAX_PUNCH_REQUESTS=0 in the punch-request test
At zero capacity the loop never ran and the new front/back asserts
unwrapped an empty queue. Make at least one request so the disabled
path is exercised, and only check eviction order when records are kept.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PkpVy2ufxgEjKd3SjXPnJ8
---------
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
`Duration::as_millis()` returns u128; casting it `as i32` in the
online-status and punch-hole checks keeps only the low 32 bits as a
signed integer. Once a peer has not registered for more than 2^31 ms
(~24.855 days), the value wraps negative and passes the
`elapsed < REG_TIMEOUT` test, so a long-offline peer is reported online
and connection attempts are relayed to its stale socket_addr. The
in-memory peer map is never evicted, so last_reg_time stays frozen until
hbbs restarts, making the false-online window 24.86-49.71 days (and it
repeats every ~49.71 days).
Widen REG_TIMEOUT and the two elapsed casts from i32 to i64 so the
comparison no longer overflows.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>