diff --git a/p2p/src/main/java/bisq/network/p2p/NetworkNodeProvider.java b/p2p/src/main/java/bisq/network/p2p/NetworkNodeProvider.java index 5061ec7956e..7f6eba5be40 100644 --- a/p2p/src/main/java/bisq/network/p2p/NetworkNodeProvider.java +++ b/p2p/src/main/java/bisq/network/p2p/NetworkNodeProvider.java @@ -69,7 +69,7 @@ public NetworkNodeProvider(NetworkProtoResolver networkProtoResolver, password, cookieFile, useSafeCookieAuthentication); - networkNode = new TorNetworkNode(port, networkProtoResolver, streamIsolation, torMode, banFilter, maxConnections); + networkNode = new TorNetworkNode(port, networkProtoResolver, streamIsolation, torMode, banFilter, maxConnections, controlHost); } } diff --git a/p2p/src/main/java/bisq/network/p2p/network/TorNetworkNode.java b/p2p/src/main/java/bisq/network/p2p/network/TorNetworkNode.java index 87c20d7873c..2815336e73e 100644 --- a/p2p/src/main/java/bisq/network/p2p/network/TorNetworkNode.java +++ b/p2p/src/main/java/bisq/network/p2p/network/TorNetworkNode.java @@ -51,6 +51,8 @@ public class TorNetworkNode extends NetworkNode { private static final long SHUT_DOWN_TIMEOUT = 2; + private final String torControlHost; + private HiddenServiceSocket hiddenServiceSocket; private Timer shutDownTimeoutTimer; private Tor tor; @@ -70,10 +72,11 @@ public TorNetworkNode(int servicePort, boolean useStreamIsolation, TorMode torMode, @Nullable BanFilter banFilter, - int maxConnections) { + int maxConnections, String torControlHost) { super(servicePort, networkProtoResolver, banFilter, maxConnections); this.torMode = torMode; this.streamIsolation = useStreamIsolation; + this.torControlHost = torControlHost; executor = SingleThreadExecutorUtils.getSingleThreadExecutor("StartTor"); } @@ -98,7 +101,7 @@ protected Socket createSocket(NodeAddress peerNodeAddress) throws IOException { checkArgument(peerNodeAddress.getHostName().endsWith(".onion"), "PeerAddress is not an onion address"); // If streamId is null stream isolation gets deactivated. // Hidden services use stream isolation by default, so we pass null. - return new TorSocket(peerNodeAddress.getHostName(), peerNodeAddress.getPort(), null); + return new TorSocket(peerNodeAddress.getHostName(), peerNodeAddress.getPort(), torControlHost, null); } public Socks5Proxy getSocksProxy() { @@ -112,7 +115,7 @@ public Socks5Proxy getSocksProxy() { if (socksProxy == null || streamIsolation) { tor = Tor.getDefault(); - socksProxy = tor != null ? tor.getProxy(stream) : null; + socksProxy = tor != null ? tor.getProxy(torControlHost, stream) : null; } return socksProxy; } catch (Throwable t) { diff --git a/p2p/src/test/java/bisq/network/p2p/network/TorNetworkNodeTest.java b/p2p/src/test/java/bisq/network/p2p/network/TorNetworkNodeTest.java index c75999b8ddc..d3a1ab6f94a 100644 --- a/p2p/src/test/java/bisq/network/p2p/network/TorNetworkNodeTest.java +++ b/p2p/src/test/java/bisq/network/p2p/network/TorNetworkNodeTest.java @@ -56,7 +56,7 @@ public void testTorNodeBeforeSecondReady() throws InterruptedException, IOExcept latch = new CountDownLatch(1); int port = 9001; TorNetworkNode node1 = new TorNetworkNode(port, TestUtils.getNetworkProtoResolver(), false, - new NewTor(new File("torNode_" + port), null, "", this::getBridgeAddresses), null, 12); + new NewTor(new File("torNode_" + port), null, "", this::getBridgeAddresses), null, 12, "127.0.0.1"); node1.start(new SetupListener() { @Override public void onTorNodeReady() { @@ -83,7 +83,7 @@ public void onRequestCustomBridges() { latch = new CountDownLatch(1); int port2 = 9002; TorNetworkNode node2 = new TorNetworkNode(port2, TestUtils.getNetworkProtoResolver(), false, - new NewTor(new File("torNode_" + port), null, "", this::getBridgeAddresses), null, 12); + new NewTor(new File("torNode_" + port), null, "", this::getBridgeAddresses), null, 12, "127.0.0.1"); node2.start(new SetupListener() { @Override public void onTorNodeReady() { @@ -141,7 +141,7 @@ public void testTorNodeAfterBothReady() throws InterruptedException, IOException latch = new CountDownLatch(2); int port = 9001; TorNetworkNode node1 = new TorNetworkNode(port, TestUtils.getNetworkProtoResolver(), false, - new NewTor(new File("torNode_" + port), null, "", this::getBridgeAddresses), null, 12); + new NewTor(new File("torNode_" + port), null, "", this::getBridgeAddresses), null, 12, "127.0.0.1"); node1.start(new SetupListener() { @Override public void onTorNodeReady() { @@ -167,7 +167,7 @@ public void onRequestCustomBridges() { int port2 = 9002; TorNetworkNode node2 = new TorNetworkNode(port2, TestUtils.getNetworkProtoResolver(), false, - new NewTor(new File("torNode_" + port), null, "", this::getBridgeAddresses), null, 12); + new NewTor(new File("torNode_" + port), null, "", this::getBridgeAddresses), null, 12, "127.0.0.1"); node2.start(new SetupListener() { @Override public void onTorNodeReady() {