Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tor: Remove lock if not running #2332

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions network/tor/tor/src/main/java/bisq/tor/TorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,6 +77,16 @@ public CompletableFuture<Boolean> 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();
Expand Down Expand Up @@ -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);
Expand Down
Loading