Skip to content

Commit

Permalink
tor: Use system tor (installed by package manager)
Browse files Browse the repository at this point in the history
During Bisq's installation the OS's package manager automatically
installs Tor and its required dependecies.
  • Loading branch information
alvasw committed Oct 19, 2024
1 parent 181f970 commit 4c791be
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package bisq.tor;

public class TorNotInstalledException extends RuntimeException {
}
17 changes: 12 additions & 5 deletions network/tor/tor/src/main/java/bisq/tor/TorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package bisq.tor;

import bisq.common.application.Service;
import bisq.common.file.FileUtils;
import bisq.common.observable.Observable;
import bisq.common.platform.LinuxDistribution;
import bisq.common.platform.OS;
Expand Down Expand Up @@ -74,7 +75,16 @@ public CompletableFuture<Boolean> initialize() {
}

if (!LinuxDistribution.isWhonix()) {
installTorIfNotUpToDate();
try {
Path torDataDirPath = transportConfig.getDataDir();
FileUtils.makeDirs(torDataDirPath.toFile());
} catch (IOException e) {
throw new RuntimeException(e);
}

if (!OS.isLinux()) {
installTorIfNotUpToDate();
}

PasswordDigest hashedControlPassword = PasswordDigest.generateDigest();
createTorrcConfigFile(torDataDirPath, hashedControlPassword);
Expand Down Expand Up @@ -177,11 +187,8 @@ public Socks5Proxy getSocks5Proxy(String streamId) throws IOException {
private Path getTorBinaryPath() {
if (OS.isLinux()) {
Optional<Path> systemTorBinaryPath = NativeTorProcess.getSystemTorPath();
if (systemTorBinaryPath.isPresent()) {
return systemTorBinaryPath.get();
}
return systemTorBinaryPath.orElseThrow(TorNotInstalledException::new);
}

return torDataDirPath.resolve("tor");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ private boolean isTorUpToDate() throws IOException {

private void install() throws IOException {
try {
File torDir = torInstallationFiles.getTorDir();
FileUtils.makeDirs(torDir);

File destDir = torInstallationFiles.getTorDir();
new TorBinaryZipExtractor(destDir).extractBinary();
log.info("Tor files installed to {}", destDir.getAbsolutePath());
Expand Down

0 comments on commit 4c791be

Please sign in to comment.