feat: multi-Tor round-robin via tor_nodes config
New top-level tor_nodes list distributes traffic across multiple Tor SOCKS proxies. First hop is replaced at connection time by round-robin selection; health tests also rotate across all nodes. FirstHopPools are created for each node when pool_size > 0. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -255,6 +255,51 @@ class TestHandleConfig:
|
||||
assert body["proxy_pool"]["sources"][0]["url"] == "http://api:8081/proxies"
|
||||
assert body["listeners"][0]["pool_hops"] == 1
|
||||
|
||||
def test_with_tor_nodes(self):
|
||||
config = Config(
|
||||
tor_nodes=[
|
||||
ChainHop("socks5", "10.200.1.1", 9050),
|
||||
ChainHop("socks5", "10.200.1.13", 9050),
|
||||
],
|
||||
listeners=[ListenerConfig()],
|
||||
)
|
||||
ctx = _make_ctx(config=config)
|
||||
_, body = _handle_config(ctx)
|
||||
assert body["tor_nodes"] == [
|
||||
"socks5://10.200.1.1:9050",
|
||||
"socks5://10.200.1.13:9050",
|
||||
]
|
||||
|
||||
def test_no_tor_nodes(self):
|
||||
config = Config(listeners=[ListenerConfig()])
|
||||
ctx = _make_ctx(config=config)
|
||||
_, body = _handle_config(ctx)
|
||||
assert "tor_nodes" not in body
|
||||
|
||||
|
||||
class TestHandleStatusTorNodes:
|
||||
"""Test tor_nodes in GET /status response."""
|
||||
|
||||
def test_tor_nodes_in_status(self):
|
||||
config = Config(
|
||||
tor_nodes=[
|
||||
ChainHop("socks5", "10.200.1.1", 9050),
|
||||
ChainHop("socks5", "10.200.1.13", 9050),
|
||||
],
|
||||
listeners=[ListenerConfig()],
|
||||
)
|
||||
ctx = _make_ctx(config=config)
|
||||
_, body = _handle_status(ctx)
|
||||
assert body["tor_nodes"] == [
|
||||
"socks5://10.200.1.1:9050",
|
||||
"socks5://10.200.1.13:9050",
|
||||
]
|
||||
|
||||
def test_no_tor_nodes_in_status(self):
|
||||
ctx = _make_ctx()
|
||||
_, body = _handle_status(ctx)
|
||||
assert "tor_nodes" not in body
|
||||
|
||||
|
||||
# -- routing -----------------------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user