Skip to content

Feature/structured logging msgpack - #23

Merged
guyte149 merged 7 commits into
masterfrom
feature/structured-logging-msgpack
Apr 29, 2026
Merged

Feature/structured logging msgpack#23
guyte149 merged 7 commits into
masterfrom
feature/structured-logging-msgpack

Conversation

@guyte149

Copy link
Copy Markdown
Owner

No description provided.

guyte149 and others added 7 commits April 29, 2026 15:04
Replace the custom verbose! macro with tracing spans that provide
hierarchical context per session and tunnel. Log lines now show which
session and tunnel they belong to using the remote's Display format
(e.g. session{id=1}: tunnel{remote=3000=>127.0.0.1:8080/tcp}).

Also adds version bump check to CI and simplifies --verbose/--debug
log level mapping.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Split tests across focused files (combinations, concurrent, edge_cases,
large_transfer) sharing helpers in tests/common/mod.rs, and refactor
tunnels.rs onto the same helpers.

The new suites deliberately leave 9 tests failing to surface real bugs:
the remote_start handshake race that silently truncates TCP payloads
written immediately after connect, the UDP tunnel's lack of per-datagram
framing, and the UDP forward client latching onto the first sender's
source address.

Made-with: Cursor
QUIC streams are byte-oriented, so the previous code's single
recv.read(&mut [u8; 1024]) calls in server_receive_remote_request and
server_receive_remote_start were unsafe: any client write that landed
in the same QUIC frame as the next message would be silently consumed
along with the discarded buffer. The remote_start step in particular
caused exactly 1012 bytes of payload loss on every TCP connection
because the client wrote payload immediately after the sentinel.

Replace the raw reads with a u32 little-endian length prefix and drop
the remote_start round trip entirely (also saves one RTT per TCP
connection). The wire format changes; client and server must be
deployed together.

Fixes the 7 failing TCP integration tests in tests/{large_transfer,
concurrent,edge_cases}.rs. The 2 remaining UDP-related failures are
tracked separately (issue #18 sections 3 and 5).

Made-with: Cursor
The UDP tunnel previously copied raw bytes onto a QUIC byte-stream and
read them back with a fixed 1024-byte buffer, with no per-datagram
framing. Two consecutive datagrams could be coalesced into a single
far-side read and re-emitted as one oversized packet (silently
corrupting protocols like DNS, WireGuard, RTP), and any datagram
larger than 1024 bytes was truncated.

Frame each datagram on the wire as a u16 little-endian length plus
payload, and bump the buffer to 65535 bytes so real-world UDP
payloads (up to the IPv4 cap of 65507) round-trip intact. Hoist the
buffer out of the hot loop while we're here, and log dropped
unexpected-source datagrams instead of silently discarding them.

Fixes large_transfer::test_udp_forward_many_packets. The remaining
multi-source UDP bug (issue #18 §5) is tracked separately.

Made-with: Cursor
The forward UDP tunnel previously latched onto the first sender's
SocketAddr in tunnel_udp_client and silently dropped every packet from
any other source — see issue #18 §5. Multi-client UDP scenarios (e.g.
several apps using the tunnel as a DNS forwarder) were broken with no
log to diagnose.

Replace the single-stream design with a per-source session: each new
SocketAddr observed on the local UDP socket gets its own QUIC bi-stream
and its own RemoteRequest, fed by a bounded mpsc channel from the recv
loop. Sessions self-terminate after 60 s of inactivity to bound memory
under churn. Backpressure drops are logged at debug level instead of
silent.

Fixes concurrent::test_udp_forward_multiple_senders. Full test suite
(30 tests across 5 files) is now green.

Made-with: Cursor
Three small correctness wins surfaced by issues #20:

- tunnel_socks_client previously did `tokio::spawn(...).await?` per
  accepted connection, which serialized the entire SOCKS5 accept loop
  on each handshake. Drop the outer .await? and merge the two nested
  spawns into one fire-and-forget task so handshake + tunnel both run
  concurrently with future accepts (#20 §1).

- tunnel_tcp_stream and tunnel_udp_stream now use tokio::join! instead
  of try_join!, so an error in one direction does not cancel the still
  in-flight copy in the other and lose buffered application data
  (#20 §3). Errors are still logged at debug.

- Drop the stale `// TODO - support udp over socks5 :)` comment in
  socks.rs (#22 §2).

Made-with: Cursor
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@guyte149
guyte149 merged commit 5e4b233 into master Apr 29, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant