diff --git a/network/tor/tor/src/main/java/bisq/tor/TorService.java b/network/tor/tor/src/main/java/bisq/tor/TorService.java index 5f090326c9..8f3966e061 100644 --- a/network/tor/tor/src/main/java/bisq/tor/TorService.java +++ b/network/tor/tor/src/main/java/bisq/tor/TorService.java @@ -32,6 +32,7 @@ import lombok.extern.slf4j.Slf4j; import net.freehaven.tor.control.PasswordDigest; +import java.io.File; import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; @@ -76,6 +77,16 @@ public CompletableFuture initialize() { createTorrcConfigFile(torDataDirPath, hashedControlPassword); Path torBinaryPath = getTorBinaryPath(); + if (!isTorRunning(torBinaryPath.toString())) { + File lockFile = torDataDirPath.resolve("lock").toFile(); + if (lockFile.exists()) { + boolean isSuccess = lockFile.delete(); + if (!isSuccess) { + throw new IllegalStateException("Couldn't remove tor lock file."); + } + } + } + var nativeTorProcess = new NativeTorProcess(torBinaryPath, torDataDirPath); torProcess = Optional.of(nativeTorProcess); nativeTorProcess.start(); @@ -170,6 +181,14 @@ private Path getTorBinaryPath() { return torDataDirPath.resolve("tor"); } + private boolean isTorRunning(String absoluteTorBinaryPath) { + return ProcessHandle.allProcesses() + .anyMatch(processHandle -> processHandle.info() + .commandLine() + .orElse("") + .startsWith(absoluteTorBinaryPath)); + } + private void installTorIfNotUpToDate() { Path torDataDirPath = transportConfig.getDataDir(); var torInstaller = new TorInstaller(torDataDirPath);