Skip to content

Commit

Permalink
Use same private_key in NewTor and RunningTor mode
Browse files Browse the repository at this point in the history
  • Loading branch information
freimair committed Nov 28, 2018
1 parent 926744c commit 5d5c4a9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 26 deletions.
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ configure(subprojects) {
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
maven { url 'https://raw.githubusercontent.com/JesusMcCloud/tor-binary/8.0.3/release/' }
}

dependencies {
Expand Down Expand Up @@ -190,10 +189,10 @@ configure(project(':common')) {
configure(project(':p2p')) {
dependencies {
compile project(':common')
compile('com.github.JesusMcCloud.netlayer:tor.native:0.6') {
compile('com.github.JesusMcCloud.netlayer:tor.native:0.6.1') {
exclude(module: 'slf4j-api')
}
compile('com.github.JesusMcCloud.netlayer:tor.external:0.6') {
compile('com.github.JesusMcCloud.netlayer:tor.external:0.6.1') {
exclude(module: 'slf4j-api')
}
compile('org.apache.httpcomponents:httpclient:4.5.3') {
Expand Down
11 changes: 1 addition & 10 deletions p2p/src/main/java/bisq/network/p2p/network/NewTor.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,12 @@
@Slf4j
public class NewTor extends TorMode {

/**
* <code>Netlayer</code> stores its hidden service files in a custom
* subdirectory of <code>$torDir/hiddenservice/</code>. Note that the
* {@link HiddenServiceSocket} does add this part on its own, hence,
* {@link NewTor#getHiddenServiceDirectory()} returns only the custom
* subdirectory (which happens to be <code>""</code>)
*/
private static final String HIDDEN_SERVICE_DIRECTORY = "hiddenservice";

private final String torrcFile;
private final String torrcOptions;
private final Collection<String> bridgeEntries;

public NewTor(File torWorkingDirectory, String torrcFile, String torrcOptions, Collection<String> bridgeEntries) {
super(torWorkingDirectory, HIDDEN_SERVICE_DIRECTORY);
super(torWorkingDirectory);
this.torrcFile = torrcFile;
this.torrcOptions = torrcOptions;
this.bridgeEntries = bridgeEntries;
Expand Down
5 changes: 2 additions & 3 deletions p2p/src/main/java/bisq/network/p2p/network/RunningTor.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
@Slf4j
public class RunningTor extends TorMode {

private static final String EXTERNAL_TOR_HIDDEN_SERVICE = "externalTorHiddenService";
private final int controlPort;
private final String password;
private final File cookieFile;
Expand All @@ -49,7 +48,7 @@ public class RunningTor extends TorMode {

public RunningTor(final File torDir, final int controlPort, final String password, final String cookieFile,
final boolean useSafeCookieAuthentication) {
super(torDir, EXTERNAL_TOR_HIDDEN_SERVICE);
super(torDir);
this.controlPort = controlPort;
this.password = password;
this.cookieFile = new File(cookieFile);
Expand Down Expand Up @@ -81,7 +80,7 @@ else if (cookieFile.exists())

@Override
public String getHiddenServiceDirectory() {
return new File(torDir, EXTERNAL_TOR_HIDDEN_SERVICE).getAbsolutePath();
return new File(torDir, HIDDEN_SERVICE_DIRECTORY).getAbsolutePath();
}

}
19 changes: 9 additions & 10 deletions p2p/src/main/java/bisq/network/p2p/network/TorMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
public abstract class TorMode {

/**
* The directory where the <code>private_key</code> file sits in. Kept private,
* because it is only valid for the {@link TorMode#doRollingBackup()} due to the
* inner workings of the <code>Netlayer</code> dependency.
* The sub-directory where the <code>private_key</code> file sits in. Kept
* private, because it only concerns implementations of {@link TorMode}.
*/
private final File hiddenServiceDirectory;
protected static final String HIDDEN_SERVICE_DIRECTORY = "hiddenservice";

protected final File torDir;

/**
Expand All @@ -51,9 +51,8 @@ public abstract class TorMode {
* necessarily equal
* {@link TorMode#getHiddenServiceDirectory()}.
*/
public TorMode(File torDir, String hiddenServiceDir) {
public TorMode(File torDir) {
this.torDir = torDir;
this.hiddenServiceDirectory = new File(torDir, hiddenServiceDir);
}

/**
Expand All @@ -70,9 +69,9 @@ public TorMode(File torDir, String hiddenServiceDir) {
* other stuff to the hiddenServiceDir, thus, selecting nothing (i.e.
* <code>""</code>) as a hidden service directory is fine. {@link ExternalTor},
* however, does not have a Tor installation path and thus, takes the hidden
* service path literally. Hence, we set
* <code>"torDir/externalTorHiddenService"</code> as the hidden service
* directory.
* service path literally. Hence, we set <code>"torDir/hiddenservice"</code> as
* the hidden service directory. By doing so, we use the same
* <code>private_key</code> file as in {@link NewTor} mode.
*
* @return <code>""</code> in {@link NewTor} Mode,
* <code>"torDir/externalTorHiddenService"</code> in {@link RunningTor}
Expand All @@ -84,7 +83,7 @@ public TorMode(File torDir, String hiddenServiceDir) {
* Do a rolling backup of the "private_key" file.
*/
protected void doRollingBackup() {
FileUtil.rollingBackup(hiddenServiceDirectory, "private_key", 20);
FileUtil.rollingBackup(new File(torDir, HIDDEN_SERVICE_DIRECTORY), "private_key", 20);
}

}

0 comments on commit 5d5c4a9

Please sign in to comment.