Move 'torControlCookieFile' option handling to Config

This commit is contained in:
Chris Beams 2019-12-16 20:58:39 +01:00
parent 5966d0ddcb
commit e90b2566a9
No known key found for this signature in database
GPG key ID: 3D214F8F5BC5ED73
7 changed files with 24 additions and 21 deletions

View file

@ -53,6 +53,7 @@ public class Config {
public static final String TORRC_OPTIONS = "torrcOptions"; public static final String TORRC_OPTIONS = "torrcOptions";
public static final String TOR_CONTROL_PORT = "torControlPort"; public static final String TOR_CONTROL_PORT = "torControlPort";
public static final String TOR_CONTROL_PASSWORD = "torControlPassword"; public static final String TOR_CONTROL_PASSWORD = "torControlPassword";
public static final String TOR_CONTROL_COOKIE_FILE = "torControlCookieFile";
static final String DEFAULT_CONFIG_FILE_NAME = "bisq.properties"; static final String DEFAULT_CONFIG_FILE_NAME = "bisq.properties";
@ -96,6 +97,7 @@ public class Config {
private final String torrcOptions; private final String torrcOptions;
private final int torControlPort; private final int torControlPort;
private final String torControlPassword; private final String torControlPassword;
private final File torControlCookieFile;
// properties derived from cli options, but not exposed as cli options themselves // properties derived from cli options, but not exposed as cli options themselves
private boolean localBitcoinNodeIsRunning = false; // FIXME: eliminate mutable state private boolean localBitcoinNodeIsRunning = false; // FIXME: eliminate mutable state
@ -327,6 +329,15 @@ public class Config {
.availableIf(TOR_CONTROL_PORT) .availableIf(TOR_CONTROL_PORT)
.withRequiredArg() .withRequiredArg()
.defaultsTo(""); .defaultsTo("");
ArgumentAcceptingOptionSpec<Path> torControlCookieFileOpt =
parser.accepts(TOR_CONTROL_COOKIE_FILE, "The cookie file for authenticating against the already " +
"running Tor service. Use in conjunction with --torControlUseSafeCookieAuth")
.availableIf(TOR_CONTROL_PORT)
.availableUnless(TOR_CONTROL_PASSWORD)
.withRequiredArg()
.describedAs("File")
.withValuesConvertedBy(new PathConverter(PathProperties.FILE_EXISTING, PathProperties.READABLE));
try { try {
OptionSet cliOpts = parser.parse(args); OptionSet cliOpts = parser.parse(args);
@ -381,6 +392,8 @@ public class Config {
this.torrcOptions = options.valueOf(torrcOptionsOpt); this.torrcOptions = options.valueOf(torrcOptionsOpt);
this.torControlPort = options.has(torControlPortOpt) ? options.valueOf(torControlPortOpt) : NULL_INT; this.torControlPort = options.has(torControlPortOpt) ? options.valueOf(torControlPortOpt) : NULL_INT;
this.torControlPassword = options.valueOf(torControlPasswordOpt); this.torControlPassword = options.valueOf(torControlPasswordOpt);
this.torControlCookieFile = options.has(torControlCookieFileOpt) ?
options.valueOf(torControlCookieFileOpt).toFile() : null;
this.referralId = options.valueOf(referralIdOpt); this.referralId = options.valueOf(referralIdOpt);
this.useDevMode = options.valueOf(useDevModeOpt); this.useDevMode = options.valueOf(useDevModeOpt);
this.useDevPrivilegeKeys = options.valueOf(useDevPrivilegeKeysOpt); this.useDevPrivilegeKeys = options.valueOf(useDevPrivilegeKeysOpt);
@ -601,4 +614,8 @@ public class Config {
public String getTorControlPassword() { public String getTorControlPassword() {
return torControlPassword; return torControlPassword;
} }
public File getTorControlCookieFile() {
return torControlCookieFile;
}
} }

View file

@ -65,7 +65,6 @@ public class BisqEnvironment extends StandardEnvironment {
protected final String btcNodes, useTorForBtc, rpcUser, rpcPassword, protected final String btcNodes, useTorForBtc, rpcUser, rpcPassword,
rpcHost, rpcPort, rpcBlockNotificationPort, rpcBlockNotificationHost, dumpBlockchainData, fullDaoNode, rpcHost, rpcPort, rpcBlockNotificationPort, rpcBlockNotificationHost, dumpBlockchainData, fullDaoNode,
externalTorCookieFile,
useAllProvidedNodes, numConnectionForBtc, genesisTxId, genesisBlockHeight, genesisTotalSupply, useAllProvidedNodes, numConnectionForBtc, genesisTxId, genesisBlockHeight, genesisTotalSupply,
daoActivated, msgThrottlePerSec, msgThrottlePer10Sec, sendMsgThrottleTrigger, sendMsgThrottleSleep; daoActivated, msgThrottlePerSec, msgThrottlePer10Sec, sendMsgThrottleTrigger, sendMsgThrottleSleep;
@ -82,7 +81,6 @@ public class BisqEnvironment extends StandardEnvironment {
@SuppressWarnings("ConstantConditions") @SuppressWarnings("ConstantConditions")
public BisqEnvironment(PropertySource commandLineProperties) { public BisqEnvironment(PropertySource commandLineProperties) {
//NetworkOptionKeys //NetworkOptionKeys
externalTorCookieFile = getProperty(commandLineProperties, NetworkOptionKeys.EXTERNAL_TOR_COOKIE_FILE, "");
externalTorUseSafeCookieAuthentication = commandLineProperties.containsProperty(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE); externalTorUseSafeCookieAuthentication = commandLineProperties.containsProperty(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE);
torStreamIsolation = commandLineProperties.containsProperty(NetworkOptionKeys.TOR_STREAM_ISOLATION); torStreamIsolation = commandLineProperties.containsProperty(NetworkOptionKeys.TOR_STREAM_ISOLATION);
@ -132,7 +130,6 @@ public class BisqEnvironment extends StandardEnvironment {
return new PropertiesPropertySource(BISQ_DEFAULT_PROPERTY_SOURCE_NAME, new Properties() { return new PropertiesPropertySource(BISQ_DEFAULT_PROPERTY_SOURCE_NAME, new Properties() {
{ {
setProperty(NetworkOptionKeys.NETWORK_ID, String.valueOf(BaseCurrencyNetwork.CURRENT_NETWORK.ordinal())); setProperty(NetworkOptionKeys.NETWORK_ID, String.valueOf(BaseCurrencyNetwork.CURRENT_NETWORK.ordinal()));
setProperty(NetworkOptionKeys.EXTERNAL_TOR_COOKIE_FILE, externalTorCookieFile);
if (externalTorUseSafeCookieAuthentication) if (externalTorUseSafeCookieAuthentication)
setProperty(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE, "true"); setProperty(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE, "true");
if (torStreamIsolation) if (torStreamIsolation)

View file

@ -51,8 +51,6 @@ import org.springframework.core.env.JOptCommandLinePropertySource;
import joptsimple.OptionException; import joptsimple.OptionException;
import joptsimple.OptionParser; import joptsimple.OptionParser;
import joptsimple.OptionSet; import joptsimple.OptionSet;
import joptsimple.util.PathConverter;
import joptsimple.util.PathProperties;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
@ -275,17 +273,9 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet
protected void customizeOptionParsing(OptionParser parser) { protected void customizeOptionParsing(OptionParser parser) {
//NetworkOptionKeys //NetworkOptionKeys
parser.accepts(NetworkOptionKeys.EXTERNAL_TOR_COOKIE_FILE,
"The cookie file for authenticating against the already running Tor service. " +
"Use in conjunction with --" + NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE)
//.availableIf(NetworkOptionKeys.EXTERNAL_TOR_CONTROL_PORT)
//.availableUnless(Config.EXTERNAL_TOR_PASSWORD)
.withRequiredArg()
.withValuesConvertedBy(new PathConverter(PathProperties.FILE_EXISTING, PathProperties.READABLE));
parser.accepts(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE, parser.accepts(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE,
"Use the SafeCookie method when authenticating to the already running Tor service.") "Use the SafeCookie method when authenticating to the already running Tor service.")
.availableIf(NetworkOptionKeys.EXTERNAL_TOR_COOKIE_FILE); /*.availableIf(Config.TOR_CONTROL_COOKIE_FILE)*/;
parser.accepts(NetworkOptionKeys.TOR_STREAM_ISOLATION, parser.accepts(NetworkOptionKeys.TOR_STREAM_ISOLATION,
"Use stream isolation for Tor [experimental!]."); "Use stream isolation for Tor [experimental!].");

View file

@ -19,7 +19,6 @@ package bisq.network;
public class NetworkOptionKeys { public class NetworkOptionKeys {
public static final String NETWORK_ID = "networkId"; public static final String NETWORK_ID = "networkId";
public static final String EXTERNAL_TOR_COOKIE_FILE = "torControlCookieFile";
public static final String EXTERNAL_TOR_USE_SAFECOOKIE = "torControlUseSafeCookieAuth"; public static final String EXTERNAL_TOR_USE_SAFECOOKIE = "torControlUseSafeCookieAuth";
public static final String TOR_STREAM_ISOLATION = "torStreamIsolation"; public static final String TOR_STREAM_ISOLATION = "torStreamIsolation";
public static final String MSG_THROTTLE_PER_SEC = "msgThrottlePerSec"; public static final String MSG_THROTTLE_PER_SEC = "msgThrottlePerSec";

View file

@ -51,7 +51,7 @@ public class NetworkNodeProvider implements Provider<NetworkNode> {
@Named(Config.TORRC_OPTIONS) String torrcOptions, @Named(Config.TORRC_OPTIONS) String torrcOptions,
@Named(Config.TOR_CONTROL_PORT) int controlPort, @Named(Config.TOR_CONTROL_PORT) int controlPort,
@Named(Config.TOR_CONTROL_PASSWORD) String password, @Named(Config.TOR_CONTROL_PASSWORD) String password,
@Named(NetworkOptionKeys.EXTERNAL_TOR_COOKIE_FILE) String cookieFile, @Nullable @Named(Config.TOR_CONTROL_COOKIE_FILE) File cookieFile,
@Named(NetworkOptionKeys.TOR_STREAM_ISOLATION) boolean streamIsolation, @Named(NetworkOptionKeys.TOR_STREAM_ISOLATION) boolean streamIsolation,
@Named(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE) boolean useSafeCookieAuthentication ) { @Named(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE) boolean useSafeCookieAuthentication ) {
networkNode = useLocalhostForP2P ? networkNode = useLocalhostForP2P ?

View file

@ -97,7 +97,7 @@ public class P2PModule extends AppModule {
bindConstant().annotatedWith(named(TORRC_OPTIONS)).to(config.getTorrcOptions()); bindConstant().annotatedWith(named(TORRC_OPTIONS)).to(config.getTorrcOptions());
bindConstant().annotatedWith(named(TOR_CONTROL_PORT)).to(config.getTorControlPort()); bindConstant().annotatedWith(named(TOR_CONTROL_PORT)).to(config.getTorControlPort());
bindConstant().annotatedWith(named(TOR_CONTROL_PASSWORD)).to(config.getTorControlPassword()); bindConstant().annotatedWith(named(TOR_CONTROL_PASSWORD)).to(config.getTorControlPassword());
bindConstant().annotatedWith(named(NetworkOptionKeys.EXTERNAL_TOR_COOKIE_FILE)).to(environment.getRequiredProperty(NetworkOptionKeys.EXTERNAL_TOR_COOKIE_FILE)); bind(File.class).annotatedWith(named(TOR_CONTROL_COOKIE_FILE)).toProvider(of(config.getTorControlCookieFile()));
bindConstant().annotatedWith(named(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE)).to(environment.containsProperty(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE)); bindConstant().annotatedWith(named(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE)).to(environment.containsProperty(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE));
bindConstant().annotatedWith(named(NetworkOptionKeys.TOR_STREAM_ISOLATION)).to(environment.containsProperty(NetworkOptionKeys.TOR_STREAM_ISOLATION)); bindConstant().annotatedWith(named(NetworkOptionKeys.TOR_STREAM_ISOLATION)).to(environment.containsProperty(NetworkOptionKeys.TOR_STREAM_ISOLATION));
bindConstant().annotatedWith(named(NetworkOptionKeys.MSG_THROTTLE_PER_SEC)).to(environment.getRequiredProperty(NetworkOptionKeys.MSG_THROTTLE_PER_SEC)); bindConstant().annotatedWith(named(NetworkOptionKeys.MSG_THROTTLE_PER_SEC)).to(environment.getRequiredProperty(NetworkOptionKeys.MSG_THROTTLE_PER_SEC));

View file

@ -29,11 +29,11 @@ import lombok.extern.slf4j.Slf4j;
/** /**
* This class creates a brand new instance of the Tor onion router. * This class creates a brand new instance of the Tor onion router.
* *
* When asked, the class checks for the authentication method selected and * When asked, the class checks for the authentication method selected and
* connects to the given control port. Finally, a {@link Tor} instance is * connects to the given control port. Finally, a {@link Tor} instance is
* returned for further use. * returned for further use.
* *
* @author Florian Reimair * @author Florian Reimair
* *
*/ */
@ -46,12 +46,12 @@ public class RunningTor extends TorMode {
private final boolean useSafeCookieAuthentication; private final boolean useSafeCookieAuthentication;
public RunningTor(final File torDir, final int controlPort, final String password, final String cookieFile, public RunningTor(final File torDir, final int controlPort, final String password, final File cookieFile,
final boolean useSafeCookieAuthentication) { final boolean useSafeCookieAuthentication) {
super(torDir); super(torDir);
this.controlPort = controlPort; this.controlPort = controlPort;
this.password = password; this.password = password;
this.cookieFile = new File(cookieFile); this.cookieFile = cookieFile;
this.useSafeCookieAuthentication = useSafeCookieAuthentication; this.useSafeCookieAuthentication = useSafeCookieAuthentication;
} }