Commit 3f2012c
bitreq: add SOCKS5 proxy support
Add SOCKS5 proxy support (RFC 1928) alongside existing HTTP CONNECT.
Targets are encoded per RFC 1928: IPv4 literals as ATYP 0x01, IPv6
literals as ATYP 0x04, and anything else as a domain name (ATYP 0x03)
with DNS resolution left to the proxy. The latter enables .onion
routing through Tor.
New public API:
- `Proxy::new_socks5(addr)` for unauthenticated SOCKS5. Accepts both
`socks5://` and `socks5h://` URL schemes; both behave identically.
- `Proxy::new_socks5_with_credentials(addr, user, pass)` for RFC 1929
username/password auth at construction.
- `Proxy::set_credentials(user, pass)` to mutate credentials on an
existing `Proxy`. Takes `String` so callers can hand over an
existing allocation. Lets a caller hold one `Proxy` and rotate
credentials for Tor circuit isolation without rebuilding from URL.
Length validation is kind-aware: SOCKS5 enforces RFC 1929's 1-255 /
0-255 byte limits; HTTP Basic (RFC 7617) has no protocol-level limit.
Internally, both proxy kinds expose a single `handshake_sync` /
`handshake_async` entry point. The connection layer treats every
proxy uniformly and no longer branches on type. Sync and async
handshake bodies share protocol logic via two `macro_rules!` macros
that template over `.await` insertion.
Motivation: ldk-node needs to route HTTP calls (RGS, scoring) through
Tor's SOCKS proxy. See lightningdevkit/ldk-node#834.
Tests cover SOCKS5 parsing and credentials (including empty-user and
length-limit edge cases per proxy kind), SOCKS5 mock-server handshakes
(success, .onion, server rejection, port encoding, domain length,
IPv4/IPv6 literal ATYP encoding, credential auth, rejection, no-auth,
rotation), and HTTP CONNECT mock-server handshakes through the
polymorphic dispatcher.1 parent 774a655 commit 3f2012c
4 files changed
Lines changed: 1034 additions & 78 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
14 | 33 | | |
15 | 34 | | |
16 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
18 | 16 | | |
19 | 17 | | |
20 | 18 | | |
| |||
337 | 335 | | |
338 | 336 | | |
339 | 337 | | |
340 | | - | |
341 | 338 | | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
| 339 | + | |
370 | 340 | | |
371 | 341 | | |
372 | 342 | | |
| |||
710 | 680 | | |
711 | 681 | | |
712 | 682 | | |
713 | | - | |
714 | 683 | | |
715 | | - | |
716 | | - | |
717 | | - | |
718 | | - | |
719 | | - | |
720 | | - | |
721 | | - | |
722 | | - | |
723 | | - | |
724 | | - | |
725 | | - | |
726 | | - | |
727 | | - | |
728 | | - | |
729 | | - | |
730 | | - | |
731 | | - | |
732 | | - | |
733 | | - | |
734 | | - | |
735 | | - | |
736 | | - | |
737 | | - | |
738 | | - | |
739 | | - | |
740 | | - | |
741 | | - | |
| 684 | + | |
742 | 685 | | |
743 | 686 | | |
744 | 687 | | |
| |||
0 commit comments