Commit df7fc12
Vasilchenko Igor
Add optional anonymous transaction broadcast over Tor (native P2P)
When node.tor.enabled is true, transactions submitted to this node's own
broadcast API are validated locally as before but, instead of being
advertised to the node's directly-connected sync peers (which exposes the
origin node's IP), are relayed via the native TRON P2P protocol through the
local Tor SOCKS5 proxy to standard, unmodified nodes learned via the (UDP)
discovery layer that are NOT currently used as sync peers. Those nodes
re-gossip the transaction as usual, hiding the origin. Block sync and normal
P2P traffic are unaffected. The feature is off by default.
Reaching a Tor peer and completing the P2P handshake costs several seconds,
which is paid per connection, not per transaction. To broadcast quickly even
at a high transaction rate, the service keeps a pool of persistent Tor
tunnels to verified, at-head relay nodes: each tunnel is handshaked once,
kept alive (answering keep-alive pings) and reused for every broadcast. The
read timeout of an established tunnel is set well above the peer keep-alive
interval so an idle but healthy tunnel is not torn down between pings.
Transactions are buffered and flushed as a single TransactionsMessage batch
(capped) over broadcastCount tunnels in parallel, so a burst is delivered in
about one round-trip; broadcastTransaction enqueues and returns immediately.
Expired transactions are dropped from the buffer.
Each tunnel advertises a fresh random public IP (never our real one, and a
fresh random node id per hello, so tunnels can't be clustered or linked to
our clear-net node) and echoes the peer's head block so the peer marks the
connection sync-complete before it will fetch a transaction. Relay candidates
are discovered nodes minus current sync peers; only nodes at (or near) our
head are kept.
Resilience: no transaction is lost if Tor or a relay is down or degraded — it
stays buffered and is delivered once a tunnel can be (re)built. A flush never
blocks the pool on a silently-dead tunnel (writes are bounded; a stalled
tunnel is dropped and rebuilt). Pool maintenance refills only the missing
tunnels (plus a small margin) and backs off exponentially when Tor is
congested, so it does not flood a struggling Tor with circuit requests. If no
tunnel can be built for several rounds and node.tor.controlPort is set, the
node signals NEWNYM over the Tor control port to rebuild circuits with fresh
exit IPs. libp2p is used as a library only; it is not modified.
- NodeConfig/Args/CommonParameter: parse and hold node.tor.* config
(incl. optional controlPort/controlPassword for NEWNYM recovery)
- TronNetService: expose discovery-table nodes (getTableNodes)
- TorBroadcastService: persistent Tor tunnel pool + batched native-P2P relay,
with bounded writes, adaptive refill/backoff, NEWNYM recovery, idle-safe
read timeout, expired-tx eviction, and public-only advertised addresses
- Wallet.broadcastTransaction: route through Tor when enabled
- config.conf: documented node.tor block
- Tests: delivery over a persistent tunnel via a SOCKS5 forwarder; Tor-outage
and relay-degradation recovery; NEWNYM on a stuck pool; and routing (Tor
path when enabled, normal P2P broadcast when disabled)1 parent 381d369 commit df7fc12
9 files changed
Lines changed: 1616 additions & 1 deletion
File tree
- common/src/main/java/org/tron
- common/parameter
- core/config/args
- framework/src
- main
- java/org/tron/core
- config/args
- net
- service/tor
- resources
- test/java/org/tron/core
- net/service/tor
Lines changed: 31 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
144 | 175 | | |
145 | 176 | | |
146 | 177 | | |
| |||
Lines changed: 78 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
120 | 187 | | |
121 | 188 | | |
122 | 189 | | |
| |||
394 | 461 | | |
395 | 462 | | |
396 | 463 | | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
397 | 475 | | |
398 | 476 | | |
399 | 477 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
| 192 | + | |
192 | 193 | | |
193 | 194 | | |
194 | 195 | | |
| |||
277 | 278 | | |
278 | 279 | | |
279 | 280 | | |
| 281 | + | |
| 282 | + | |
280 | 283 | | |
281 | 284 | | |
282 | 285 | | |
| |||
556 | 559 | | |
557 | 560 | | |
558 | 561 | | |
559 | | - | |
560 | 562 | | |
561 | 563 | | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
562 | 580 | | |
563 | 581 | | |
564 | 582 | | |
| |||
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
640 | 640 | | |
641 | 641 | | |
642 | 642 | | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
643 | 654 | | |
644 | 655 | | |
645 | 656 | | |
| |||
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
138 | 139 | | |
139 | 140 | | |
140 | 141 | | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
141 | 151 | | |
142 | 152 | | |
143 | 153 | | |
| |||
0 commit comments