From 24928bce51b769b1383f6fbe500ef6bc742c0846 Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Wed, 22 May 2024 16:35:16 +0000 Subject: [PATCH] WhonixTorController: Implement TAKEOWNERSHIP command --- .../tor/controller/ControlCommandFailedException.java | 4 ++++ .../java/bisq/tor/controller/WhonixTorController.java | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/network/tor/tor/src/main/java/bisq/tor/controller/ControlCommandFailedException.java b/network/tor/tor/src/main/java/bisq/tor/controller/ControlCommandFailedException.java index 67476d2fe3..18e0e435e6 100644 --- a/network/tor/tor/src/main/java/bisq/tor/controller/ControlCommandFailedException.java +++ b/network/tor/tor/src/main/java/bisq/tor/controller/ControlCommandFailedException.java @@ -18,6 +18,10 @@ package bisq.tor.controller; public class ControlCommandFailedException extends RuntimeException { + public ControlCommandFailedException(String message) { + super(message); + } + public ControlCommandFailedException(String message, Throwable cause) { super(message, cause); } diff --git a/network/tor/tor/src/main/java/bisq/tor/controller/WhonixTorController.java b/network/tor/tor/src/main/java/bisq/tor/controller/WhonixTorController.java index 4610c844c5..c3b4ccb939 100644 --- a/network/tor/tor/src/main/java/bisq/tor/controller/WhonixTorController.java +++ b/network/tor/tor/src/main/java/bisq/tor/controller/WhonixTorController.java @@ -52,6 +52,15 @@ public void addOnion(TorKeyPair torKeyPair, int onionPort, int localPort) throws String reply = receiveReply(); } + public void takeOwnership() throws IOException { + String command = "TAKEOWNERSHIP\r\n"; + sendCommand(command); + String reply = receiveReply(); + if (!reply.equals("250 OK")) { + throw new ControlCommandFailedException("Couldn't take ownership"); + } + } + private void sendCommand(String command) throws IOException { byte[] commandBytes = command.getBytes(StandardCharsets.US_ASCII); outputStream.write(commandBytes);