Skip to content

Commit

Permalink
TorInstallationFiles: Remove dotTorDir and cookieFile
Browse files Browse the repository at this point in the history
  • Loading branch information
alvasw committed Aug 20, 2023
1 parent 0503cec commit fa9a773
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 36 deletions.
3 changes: 0 additions & 3 deletions network/tor/tor/src/main/java/bisq/tor/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public class Constants {
public final static String LOCALHOST = "127.0.0.1";

// Directories
public final static String DOT_TOR_DIR = ".tor";
public final static String HS_DIR = "hiddenservice";
public final static String NATIVE_DIR = "native";
public final static String WIN_DIR = "windows";
Expand All @@ -41,7 +40,6 @@ public class Constants {
public final static String GEO_IPV_6 = "geoip6";
public final static String TORRC = "torrc";
public final static String PID = "pid";
public final static String COOKIE = "control_auth_cookie";
public final static String HOSTNAME = "hostname";
public final static String PRIV_KEY = "private_key";
public final static String TOR_ARCHIVE = "tor.tar.xz";
Expand All @@ -53,7 +51,6 @@ public class Constants {
public final static String TORRC_KEY_GEOIP = "GeoIPFile";
public final static String TORRC_KEY_PID = "PidFile";
public final static String TORRC_KEY_DATA_DIRECTORY = "DataDirectory";
public final static String TORRC_KEY_COOKIE = "CookieAuthFile";

// Tor control connection
public final static String CONTROL_PORT_LOG_SUB_STRING = "Control listener listening on port ";
Expand Down
18 changes: 0 additions & 18 deletions network/tor/tor/src/main/java/bisq/tor/TorBootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import bisq.tor.process.TorProcessConfig;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Scanner;
Expand All @@ -49,7 +48,6 @@ class TorBootstrap {
}

int start() throws IOException, InterruptedException {
torInstallationFiles.removeCookieFileIfPresent();
torInstaller.installIfNotUpToDate();

Process torProcess = startTorProcess();
Expand All @@ -59,15 +57,10 @@ int start() throws IOException, InterruptedException {
int controlPort = waitForControlPort(torProcess);
terminateProcessBuilder(torProcess);

waitForCookieInitialized();
log.info("Cookie initialized");
return controlPort;
}

File getCookieFile() {
return torInstallationFiles.getCookieFile();
}

void deleteVersionFile() {
torInstaller.deleteVersionFile();
}
Expand Down Expand Up @@ -136,17 +129,6 @@ private void terminateProcessBuilder(Process torProcess) throws InterruptedExcep
log.debug("Process builder terminated");
}

private void waitForCookieInitialized() throws InterruptedException, IOException {
long start = System.currentTimeMillis();
File cookieFile = torInstallationFiles.getCookieFile();
while (isRunning.get() && cookieFile.length() < 32 && !Thread.currentThread().isInterrupted()) {
if (System.currentTimeMillis() - start > 5000) {
throw new IOException("Auth cookie not created");
}
Thread.sleep(50);
}
}

void shutdown() {
isRunning.set(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,22 @@
public class TorInstallationFiles {
private final File torDir;
private final File torBinary;
private final File dotTorDir;
private final File pidFile;
private final File geoIPFile;
private final File geoIPv6File;
private final File torrcFile;
private final File cookieFile;
private final File versionFile;

public TorInstallationFiles(Path torDirPath, OsType osType) {
torDir = torDirPath.toFile();
torBinary = new File(torDir, osType.getBinaryName());
dotTorDir = new File(torDir, Constants.DOT_TOR_DIR);
pidFile = new File(torDir, Constants.PID);
geoIPFile = new File(torDir, Constants.GEO_IP);
geoIPv6File = new File(torDir, Constants.GEO_IPV_6);
torrcFile = new File(torDir, Constants.TORRC);
cookieFile = new File(dotTorDir.getAbsoluteFile(), Constants.COOKIE);
versionFile = new File(torDir, Constants.VERSION);
}

public void removeCookieFileIfPresent() throws IOException {
if (cookieFile.exists() && !cookieFile.delete()) {
throw new IOException("Cannot delete old cookie file.");
}
}

public void writePidToDisk(String ownerPid) throws IOException {
FileUtils.writeToFile(ownerPid, pidFile);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ private void install() throws IOException {
File torDir = torInstallationFiles.getTorDir();
FileUtils.makeDirs(torDir);

File dotTorDir = torInstallationFiles.getDotTorDir();
FileUtils.makeDirs(dotTorDir);

File destDir = torInstallationFiles.getTorDir();
new TorBinaryZipExtractor(destDir).extractBinary();
log.info("Tor files installed to {}", destDir.getAbsolutePath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ private void extendTorrcFile() throws IOException {
torInstallationFiles.getGeoIPv6File().getCanonicalPath());
printWriter.println(Constants.TORRC_KEY_PID + " " +
torInstallationFiles.getPidFile().getCanonicalPath());
printWriter.println(Constants.TORRC_KEY_COOKIE + " " +
torInstallationFiles.getCookieFile().getCanonicalPath());
printWriter.println("");
}
}
Expand Down

0 comments on commit fa9a773

Please sign in to comment.