Issue #33 follow-ups: enum-based remotes, conn cap, UDP alloc, parser rewrite - #35
Merged
Conversation
Closes the bullets from issue #33: - RemoteRequest is now an unambiguous tagged enum (Direction + RemoteKind with Tcp / Udp / Socks5 variants). Server and client dispatch collapse to flat match arms with no string sentinels. Wire-format break — bumps to 0.4.0. - Adds --max-connections N server flag backed by a tokio::sync::Semaphore permit held for the lifetime of handle_client_connection. Surplus connections are refused at the QUIC layer rather than queued. - UDP forward client uses bytes::Bytes channels fed from a rolling BytesMut arena (split_to(n).freeze() is zero-copy), eliminating the per-datagram Vec allocation. - RemoteRequest::from_str rewritten as a layered parser (direction → protocol → tokens → kind) with per-arity helpers. - Documents the decision to leave clippy::expect_used / panic un-denied. Co-authored-by: Cursor <cursoragent@cursor.com>
The previous helper bound to `:0`, recorded the kernel-assigned port, dropped the listener, and returned the number. Under CI parallelism two sibling tests in the same binary could observe the same port number, the first to bind would win, the second's silent `bind` failure caused a SOCKS5 handshake to land on a plain TCP listener (the listener's `read` returned `[5, 1, 0]`). Replace it with a process-wide monotonic counter (`AtomicU32::fetch_add`) in the 40_000-60_000 range, PID-seeded so parallel `cargo test` invocations don't collide. The counter alone guarantees no in-process duplicate; a follow-up bind probe still rules out ports a different process on the host happens to hold. Stress-tested 15× clean (was ~6/10 failing before). Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #33.
Addresses every bullet from the follow-ups roll-up. Primarily an internal refactor; the only externally-visible additions are a new
--max-connectionsflag and a wire-format version bump that requires client and server to upgrade together.Summary
RemoteRequestis now{ direction: Direction, kind: RemoteKind }whereRemoteKindisTcp { local, remote } | Udp { local, remote } | Socks5 { local }. The wire-level magic pairremote_host == "socks" && remote_port == 0is gone. Dispatchers insrc/server/mod.rsandsrc/client/mod.rscollapse to flatmatch (direction, &kind)with no_placeholders and no string sentinels. Breaking wire change — version bumped to 0.4.0.--max-connections Nserver flag. Backed by atokio::sync::Semaphorewhose permit is held for the lifetime ofhandle_client_connection; surplus connections are refused at the QUIC layer (Incoming::refuse()) rather than queued.0(default) keeps behaviour uncapped.tunnel_udp_clientnow usesmpsc::Sender<bytes::Bytes>fed from a rollingBytesMutpool:recv_fromwrites into the arena,split_to(n).freeze()hands a zero-copy frozen slice to the session task, and the underlying allocation reverts to the pool when outstanding handles drop.RemoteRequest::from_stris layered now (parse_direction → parse_protocol → split_addr_tokens → tokens_to_kind) with per-arity helper fns. The 150-line nested match is gone. All 25 existing parser tests pass plus 3 new ones covering the new helper API.Cargo.tomlandCHANGELOG.md: not liftingclippy::expect_used/clippy::panicto deny. Would only force three#[allow]annotations on infallible-invariant call sites; not worth the noise without an explicit "production code never panics" goal.Made with Cursor