diff --git a/network/tor/tor/src/main/java/bisq/tor/controller/BootstrapEventParser.java b/network/tor/tor/src/main/java/bisq/tor/controller/BootstrapEventParser.java index d72cd673dd..10fa81402c 100644 --- a/network/tor/tor/src/main/java/bisq/tor/controller/BootstrapEventParser.java +++ b/network/tor/tor/src/main/java/bisq/tor/controller/BootstrapEventParser.java @@ -7,16 +7,22 @@ public class BootstrapEventParser { public static Optional tryParse(String line) { // 650 STATUS_CLIENT NOTICE BOOTSTRAP PROGRESS=50 TAG=loading_descriptors SUMMARY="Loading relay descriptors" - String[] parts = line.split(" "); + if (isStatusClientEvent(line)) { + String[] parts = line.split(" "); - if (isBootstrapEvent(parts)) { - BootstrapEvent bootstrapEvent = parseBootstrapEvent(parts); - return Optional.of(bootstrapEvent); + if (isBootstrapEvent(parts)) { + BootstrapEvent bootstrapEvent = parseBootstrapEvent(parts); + return Optional.of(bootstrapEvent); + } } return Optional.empty(); } + private static boolean isStatusClientEvent(String line) { + // 650 STATUS_CLIENT NOTICE CIRCUIT_ESTABLISHED + return line.startsWith("650 STATUS_CLIENT"); + } private static boolean isBootstrapEvent(String[] parts) { // 650 STATUS_CLIENT NOTICE BOOTSTRAP PROGRESS=50 TAG=loading_descriptors SUMMARY="Loading relay descriptors" diff --git a/network/tor/tor/src/main/java/bisq/tor/controller/TorControlProtocol.java b/network/tor/tor/src/main/java/bisq/tor/controller/TorControlProtocol.java index 44c54d044a..dea50a7154 100644 --- a/network/tor/tor/src/main/java/bisq/tor/controller/TorControlProtocol.java +++ b/network/tor/tor/src/main/java/bisq/tor/controller/TorControlProtocol.java @@ -55,6 +55,16 @@ public void addOnion(TorKeyPair torKeyPair, int onionPort, int localPort) throws String reply = receiveReply(); } + public String getInfo(String keyword) throws IOException { + String command = "GETINFO " + keyword + "\r\n"; + sendCommand(command); + String reply = receiveReply(); + if (!reply.startsWith("250-")) { + throw new ControlCommandFailedException("Couldn't get info: " + keyword); + } + return reply; + } + public void resetConf(String configName) throws IOException { String command = "RESETCONF " + configName + "\r\n"; sendCommand(command); diff --git a/network/tor/tor/src/main/java/bisq/tor/controller/WhonixTorControlReader.java b/network/tor/tor/src/main/java/bisq/tor/controller/WhonixTorControlReader.java index 99bc1aef56..76da07a56a 100644 --- a/network/tor/tor/src/main/java/bisq/tor/controller/WhonixTorControlReader.java +++ b/network/tor/tor/src/main/java/bisq/tor/controller/WhonixTorControlReader.java @@ -33,14 +33,13 @@ public void start() { String line; while ((line = bufferedReader.readLine()) != null) { - if (isStatusClientEvent(line)) { + if (isEvent(line)) { Optional bootstrapEventOptional = BootstrapEventParser.tryParse(line); - if (bootstrapEventOptional.isPresent()) { BootstrapEvent bootstrapEvent = bootstrapEventOptional.get(); bootstrapEventListeners.forEach(listener -> listener.onBootstrapStatusEvent(bootstrapEvent)); } else { - log.info("Unknown status client event: {}", line); + log.info("Unknown Tor event: {}", line); } } else { @@ -81,8 +80,8 @@ public void removeBootstrapEventListener(BootstrapEventListener listener) { bootstrapEventListeners.remove(listener); } - private boolean isStatusClientEvent(String line) { + private boolean isEvent(String line) { // 650 STATUS_CLIENT NOTICE CIRCUIT_ESTABLISHED - return line.startsWith("650 STATUS_CLIENT"); + return line.startsWith("650"); } }