From 78919096825b7ffc4e986c75ca5c073366e69b03 Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Sun, 2 Jun 2024 14:20:56 +0000 Subject: [PATCH] TorController: Implement getSocksPort --- .../bisq/tor/controller/TorController.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/network/tor/tor/src/main/java/bisq/tor/controller/TorController.java b/network/tor/tor/src/main/java/bisq/tor/controller/TorController.java index 04867ec9af..c7e4ff9af3 100644 --- a/network/tor/tor/src/main/java/bisq/tor/controller/TorController.java +++ b/network/tor/tor/src/main/java/bisq/tor/controller/TorController.java @@ -57,6 +57,30 @@ public void bootstrapTor() throws IOException { waitUntilBootstrapped(); } + public Optional getSocksPort() { + try { + TorControlProtocol torControlProtocol = getTorControlProtocol(); + String socksListenersString = torControlProtocol.getInfo("net/listeners/socks"); + + String socksListener; + if (socksListenersString.contains(" ")) { + String[] socksPorts = socksListenersString.split(" "); + socksListener = socksPorts[0]; + } else { + socksListener = socksListenersString; + } + + // "127.0.0.1:12345" + socksListener = socksListener.replace("\"", ""); + String portString = socksListener.split(":")[1]; + + int port = Integer.parseInt(portString); + return Optional.of(port); + } catch (IOException e) { + return Optional.empty(); + } + } + @Override public void onBootstrapStatusEvent(BootstrapEvent bootstrapEvent) { log.info("Tor bootstrap event: {}", bootstrapEvent);