Commit 18df760f authored by zeroleak's avatar zeroleak
Browse files

add cli.torConfig.fileCreationTimeout

parent 9ce463be
......@@ -91,6 +91,10 @@ cli.torConfig.backend.onion = true # wallet backend
- `true`: Tor hidden services
- `false`: clearnet over Tor
Tor startup timeout can be customized with:
```
cli.torConfig.fileCreationTimeout = 20 # 20s
```
## Build instructions
Build with maven:
......
......@@ -35,13 +35,11 @@ public class JavaTorClient {
public void setup() throws Exception {
TorSettings torSettings = computeTorSettings();
Optional<File> torExecutable = computeTorExecutableAndVerify();
WhirlpoolTorInstaller torInstaller = new WhirlpoolTorInstaller("whirlpoolTor", torExecutable);
WhirlpoolTorInstaller torInstaller = computeTorInstaller();
this.torInstance = new TorOnionProxyInstance(torInstaller, torSettings, torHttpUsages);
}
private Optional<File> computeTorExecutableAndVerify() throws Exception {
private WhirlpoolTorInstaller computeTorInstaller() throws Exception {
CliTorExecutableMode executableMode = cliConfig.getTorConfig().getExecutableMode();
String executablePath =
CliTorExecutableMode.SPECIFIED.equals(executableMode)
......@@ -54,7 +52,7 @@ public class JavaTorClient {
computeTorExecutable(executableMode, executablePath, tryEmbedded);
try {
// verify Tor executable is supported
checkTorExecutable(torExecutable); // throws exception when Tor not supported
return checkTorInstaller(torExecutable); // throws exception when Tor not supported
} catch (Exception e) {
if (tryEmbedded) {
log.warn(
......@@ -66,7 +64,7 @@ public class JavaTorClient {
tryEmbedded = false;
torExecutable = computeTorExecutable(executableMode, executablePath, tryEmbedded);
try {
checkTorExecutable(torExecutable); // throws exception when Tor not supported
return checkTorInstaller(torExecutable); // throws exception when Tor not supported
} catch (Exception ee) {
log.error(
"Tor executable failed ("
......@@ -90,7 +88,6 @@ public class JavaTorClient {
throw e;
}
}
return torExecutable;
}
private Optional<File> computeTorExecutable(
......@@ -171,14 +168,18 @@ public class JavaTorClient {
return file;
}
private void checkTorExecutable(Optional<File> torExecutable) throws Exception {
private WhirlpoolTorInstaller checkTorInstaller(Optional<File> torExecutable) throws Exception {
if (log.isDebugEnabled()) {
log.debug(
"Verifying Tor executable ("
+ (torExecutable.isPresent() ? torExecutable.get().getAbsolutePath() : "embedded")
+ ")");
}
new WhirlpoolTorInstaller("whirlpoolTorInstaller", torExecutable).setup(); // throws
int fileCreationTimeout = cliConfig.getTorConfig().getFileCreationTimeout();
WhirlpoolTorInstaller torInstaller =
new WhirlpoolTorInstaller("whirlpoolTor", torExecutable, fileCreationTimeout);
torInstaller.setup(); // throws
return torInstaller;
}
public void connect() {
......
......@@ -23,13 +23,14 @@ public final class WhirlpoolTorInstaller extends TorInstaller {
private final TorConfig config;
private boolean useExecutableFromZip;
public WhirlpoolTorInstaller(String torDir, Optional<File> torExecutable) throws Exception {
this.config = computeTorConfig(torDir, torExecutable);
public WhirlpoolTorInstaller(String torDir, Optional<File> torExecutable, int fileCreationTimeout)
throws Exception {
this.config = computeTorConfig(torDir, torExecutable, fileCreationTimeout);
this.useExecutableFromZip = !torExecutable.isPresent();
}
private TorConfig computeTorConfig(String dirName, Optional<File> torExecutable)
throws Exception {
private static TorConfig computeTorConfig(
String dirName, Optional<File> torExecutable, int fileCreationTimeout) throws Exception {
File dir = Files.createTempDirectory(dirName).toFile();
dir.deleteOnExit();
......@@ -43,6 +44,7 @@ public final class WhirlpoolTorInstaller extends TorInstaller {
// use existing local Tor instead of embedded one
torConfigBuilder.torExecutable(torExecutable.get());
}
torConfigBuilder.fileCreationTimeout(fileCreationTimeout);
TorConfig torConfig = torConfigBuilder.build();
return torConfig;
......
......@@ -364,6 +364,7 @@ public abstract class CliConfigFile {
@NotEmpty private TorConfigItem coordinator;
@NotEmpty private TorConfigItem backend;
private String customTorrc;
private int fileCreationTimeout;
public TorConfig() {}
......@@ -372,6 +373,7 @@ public abstract class CliConfigFile {
this.coordinator = copy.coordinator;
this.backend = copy.backend;
this.customTorrc = copy.customTorrc;
this.fileCreationTimeout = copy.fileCreationTimeout;
}
public String getExecutable() {
......@@ -415,12 +417,21 @@ public abstract class CliConfigFile {
this.customTorrc = customTorrc;
}
public int getFileCreationTimeout() {
return fileCreationTimeout;
}
public void setFileCreationTimeout(int fileCreationTimeout) {
this.fileCreationTimeout = fileCreationTimeout;
}
public Map<String, String> getConfigInfo() {
Map<String, String> configInfo = new HashMap<>();
configInfo.put("cli/tor/executable", executable);
configInfo.put("cli/tor/coordinator", coordinator.toString());
configInfo.put("cli/tor/backend", backend.toString());
configInfo.put("cli/tor/customTorrc", customTorrc != null ? customTorrc : "null");
configInfo.put("cli/tor/fileCreationTimeout", Integer.toString(fileCreationTimeout));
return configInfo;
}
}
......
......@@ -24,6 +24,8 @@ cli.torConfig.coordinator.enabled = true
cli.torConfig.coordinator.onion = true
cli.torConfig.backend.enabled = true
cli.torConfig.backend.onion = true
cli.torConfig.customTorrc =
cli.torConfig.fileCreationTimeout = 20
cli.apiKey =
cli.seed =
cli.seedAppendPassphrase = true
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment