Repository navigation
friglet: optional Tor (SOCKS5) for all P2P connections (SNB-857) - #87
Open
setavenger wants to merge 5 commits into
Open
setavenger wants to merge 5 commits into
setavenger wants to merge 5 commits into
Conversation
Every P2P connection goes through the proxy when p2p_proxy is set: SOCKS5 dialer with fresh credentials per connection, seeding through the proxy by name, racing connects, and the address book saved beside the state file. Folds this branch's first four commits (SOCKS5 dialer and saved address book; p2p_proxy setting; docs; racing connects and fresh seed addresses) and their merge with SNB-856 into one commit while rebasing onto integration. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Every sender and observer connects through `peers.dialer()`, so through p2p_proxy each one logs in to Tor with its own credentials and gets a circuit of its own. Senders keep 856's handshake (relay off, height 0, placeholder addresses, shared user agent, no getaddr/feefilter) and keep listening after the pong for a parent request, bounded by the budget. - Through a proxy a connection takes 1 to 5 s to a live peer and the full 20 s to a dead one. Proxied timing: 6 observer connects at the start (3 directly), senders start when 3 are ready or after 15 s (5 s), no observer by 30 s (12 s) ends the broadcast, 12 observer tries (9). Budget 45 s (25 s): Sparrow's requests end at about 3, 12, 29, 64 and 99 s (read timeouts 3, 8, 16, 34, 34 s, up to 5 attempts), so the answer lands in the fourth with ~19 s to spare. - Mempool asks (rechecks, resends) race 2 extra connects through a proxy. - Proxy down: no peer is blamed and the error names p2p_proxy. - Tests: two senders and every other connection log in with different credentials and nothing bypasses the proxy; proxy down. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Tor running without a working circuit answers no CONNECT in time (or replies 0x01): that only rests the peer now (`is_proxy_unclear`, `PeerEvent::Unhelpful`) instead of counting it unreachable, so an outage cannot empty the saved address book. A clear refusal (0x02-0x05) still counts. - An empty FRIGLET_P2P_PROXY (a template default) no longer overrides the config file's p2p_proxy: that silently turned Tor off. - Electrum connections through a proxy get at least 20 s for the handshake too, not only for the connect. - The saved address book files are owner-only (0600). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Live on signet through Tor, 5 of the first 6 observers were dead addresses: each held its connect for the full 20 s, and the broadcast ended with "no Bitcoin peers reachable". A broadcast that succeeded in 2.5 s was then answered after 40 s, because the new-tip notification first fetched a header from three dead peers in a row. - Broadcast through a proxy: while fewer than 3 observers are ready, start more every 6 s; once senders start, likewise more senders while fewer than 2 have handed the transaction over. Hand-overs stay capped at 2 (`claim_hand_over`); a rejection no longer waits for hedged senders that can no longer get it. Pong wait 15 s through a proxy. - Header requests through a proxy race their first connection over 3 peers. - Tests: hedging past stalled addresses (FakeSocks5) finishes in < 19 s with at most 2 hand-overs; headers race past stalled peers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…te (SNB-857) CI's newer stable toolchain deprecates AtomicUsize::fetch_update in favour of try_update, which older toolchains lack, so clippy -D warnings failed there. A compare_exchange loop builds cleanly on both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
setavenger
force-pushed
the
snb-856-broadcast
branch
from
November 1, 2026 15:53
17bbbeb to
951c312
Compare
setavenger
force-pushed
the
snb-857-tor
branch
from
November 1, 2026 15:53
01208f4 to
4cc4039
Compare
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.
Optional Tor for friglet: with
p2p_proxy = "127.0.0.1:9050"(or--p2p-proxy,FRIGLET_P2P_PROXY, the tray's new "Tor proxy" field) every Bitcoin P2P connection goes through that SOCKS5 proxy: block downloads, headers, fee sampling, mempool checks, broadcasts, rechecks and peer discovery. Stacked on #86 (SNB-856). Implements SNB-857.What
blindbit-lib/src/net/socks5.rs,Dialer::Socks5): blocking RFC 1928/1929 client. Each connection offers no-auth and a username/password login with random credentials, so Tor puts it on a circuit of its own (each sender and observer of a broadcast sees a different exit). Fail-closed: with the proxy set nothing ever goes out directly, also when it is down..onion) goes to the proxy unresolved; an.onionnode without a proxy is a config error. Seeding through the proxy connects by name tox9.<seed>(else the bare name) of 3 random seeds, asks that node for addresses (getaddr) and hangs up.p2p_proxy(block fetch, headers, broadcast, mempool checks).peers-<network>-{new,tried}.bookbeside the wallet state (bitcoin-address-bookFileExt format, 0600), loaded at start, saved every 10 min when changed and at exit; unreadable → warning, ignored; seeds asked at start only below 50 known addresses.p2p_proxy(an older tray drops the field).--p2p-proxy,fetch_block --proxy, README "Tor" section (what is proxied; the oracle is not), AGENTS.md notes.Deviations from the plan, and why
Measured live through Tor on signet: an address nobody answers at holds a connect for the whole 20 s timeout (Tor keeps retrying), and many gossiped addresses are days old and gone.
getaddranswer enters the book most recently seen first (half of it is > 5 days old).Timing::PROXIED): 6 observer connects at the start, more every 6 s while < 3 are ready; once senders start, more senders every 6 s while < 2 have handed it over, hand-overs capped at 2. Observer window 15 s (5), limit 30 s (12), pong wait 15 s (5). Budget 45 s instead of 25: Sparrow sends a request up to 5 times with read timeouts 3, 8, 16, 34, 34 s (0-2 s apart), so its requests end at about 3, 12, 29, 64 and 99 s and an answer at 45 s lands in the fourth with ~19 s to spare; a later resend is answered from the cached outcome. Direct timings are unchanged.FRIGLET_P2P_PROXYdoes not override the file'sp2p_proxy.Verification
cargo build --workspace;cargo test --workspace(blindbit-lib 124 with integration's 10 testkit tests, friglet 106, friglet-ipc 30+1, friglet-tray 68+7, thread soak 1, console 1: all pass); CI clippy line clean;cargo fmt --checkclean; new network tests 5x without failures.node.invalidreached by name through the proxy; seeding byx9.proxied-seed.invalidwith no local lookup; proxy down or refusing → message namesp2p_proxyand the fake node sees no connection; two broadcast senders (and every other connection) use different credentials and nothing bypasses the proxy; hedging and header racing past stalled addresses; address-book round trip and corrupt files;.onionwithout proxy rejected; empty env var.37181c9c…→ accepted in 4.8 s, confirmed by observer 147.182.229.68:38333; old confirmed tx2fec1b9b…→bad-txns-inputs-missingorspentafter 42.3 s (both senders asked for a parent), never success;ss -tnp: the daemon's sockets were only 127.0.0.1:9050 and the oracle (152.53.151.148:443);strace -f -e trace=network: connects only to 127.0.0.1:9050, the oracle and the local resolver, DNS queries only forsignet.oracle.setor.dev; seed names appear only inside SOCKS CONNECT requests;Known limits
blockchain.relayfeethrough Tor can time out once (2 s) and report the default 1 sat/vB while sampling continues.p2p_proxyempty for it or use its onion address).