mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Move 'torControlUseSafeCookieAuth' option handling to Config
This commit is contained in:
parent
e90b2566a9
commit
25604c1b29
@ -8,6 +8,7 @@ import joptsimple.OptionException;
|
||||
import joptsimple.OptionParser;
|
||||
import joptsimple.OptionSet;
|
||||
import joptsimple.OptionSpec;
|
||||
import joptsimple.OptionSpecBuilder;
|
||||
import joptsimple.util.PathConverter;
|
||||
import joptsimple.util.PathProperties;
|
||||
import joptsimple.util.RegexMatcher;
|
||||
@ -54,6 +55,7 @@ public class Config {
|
||||
public static final String TOR_CONTROL_PORT = "torControlPort";
|
||||
public static final String TOR_CONTROL_PASSWORD = "torControlPassword";
|
||||
public static final String TOR_CONTROL_COOKIE_FILE = "torControlCookieFile";
|
||||
public static final String TOR_CONTROL_USE_SAFE_COOKIE_AUTH = "torControlUseSafeCookieAuth";
|
||||
|
||||
static final String DEFAULT_CONFIG_FILE_NAME = "bisq.properties";
|
||||
|
||||
@ -98,6 +100,7 @@ public class Config {
|
||||
private final int torControlPort;
|
||||
private final String torControlPassword;
|
||||
private final File torControlCookieFile;
|
||||
private final boolean useTorControlSafeCookieAuth;
|
||||
|
||||
// properties derived from cli options, but not exposed as cli options themselves
|
||||
private boolean localBitcoinNodeIsRunning = false; // FIXME: eliminate mutable state
|
||||
@ -332,12 +335,17 @@ public class Config {
|
||||
|
||||
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")
|
||||
"running Tor service. Use in conjunction with --" + TOR_CONTROL_USE_SAFE_COOKIE_AUTH)
|
||||
.availableIf(TOR_CONTROL_PORT)
|
||||
.availableUnless(TOR_CONTROL_PASSWORD)
|
||||
.withRequiredArg()
|
||||
.describedAs("File")
|
||||
.withValuesConvertedBy(new PathConverter(PathProperties.FILE_EXISTING, PathProperties.READABLE));
|
||||
|
||||
OptionSpecBuilder torControlUseSafeCookieAuthOpt =
|
||||
parser.accepts(TOR_CONTROL_USE_SAFE_COOKIE_AUTH,
|
||||
"Use the SafeCookie method when authenticating to the already running Tor service.")
|
||||
.availableIf(TOR_CONTROL_COOKIE_FILE);
|
||||
try {
|
||||
OptionSet cliOpts = parser.parse(args);
|
||||
|
||||
@ -394,6 +402,7 @@ public class Config {
|
||||
this.torControlPassword = options.valueOf(torControlPasswordOpt);
|
||||
this.torControlCookieFile = options.has(torControlCookieFileOpt) ?
|
||||
options.valueOf(torControlCookieFileOpt).toFile() : null;
|
||||
this.useTorControlSafeCookieAuth = options.has(torControlUseSafeCookieAuthOpt);
|
||||
this.referralId = options.valueOf(referralIdOpt);
|
||||
this.useDevMode = options.valueOf(useDevModeOpt);
|
||||
this.useDevPrivilegeKeys = options.valueOf(useDevPrivilegeKeysOpt);
|
||||
@ -618,4 +627,8 @@ public class Config {
|
||||
public File getTorControlCookieFile() {
|
||||
return torControlCookieFile;
|
||||
}
|
||||
|
||||
public boolean isUseTorControlSafeCookieAuth() {
|
||||
return useTorControlSafeCookieAuth;
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ public class BisqEnvironment extends StandardEnvironment {
|
||||
@Getter
|
||||
protected boolean ignoreLocalBtcNode;
|
||||
|
||||
protected final boolean externalTorUseSafeCookieAuthentication, torStreamIsolation;
|
||||
protected final boolean torStreamIsolation;
|
||||
|
||||
public BisqEnvironment(OptionSet options) {
|
||||
this(new JOptCommandLinePropertySource(BISQ_COMMANDLINE_PROPERTY_SOURCE_NAME, checkNotNull(
|
||||
@ -81,7 +81,6 @@ public class BisqEnvironment extends StandardEnvironment {
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public BisqEnvironment(PropertySource commandLineProperties) {
|
||||
//NetworkOptionKeys
|
||||
externalTorUseSafeCookieAuthentication = commandLineProperties.containsProperty(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE);
|
||||
torStreamIsolation = commandLineProperties.containsProperty(NetworkOptionKeys.TOR_STREAM_ISOLATION);
|
||||
|
||||
msgThrottlePerSec = getProperty(commandLineProperties, NetworkOptionKeys.MSG_THROTTLE_PER_SEC, String.valueOf(ConnectionConfig.MSG_THROTTLE_PER_SEC));
|
||||
@ -130,8 +129,6 @@ public class BisqEnvironment extends StandardEnvironment {
|
||||
return new PropertiesPropertySource(BISQ_DEFAULT_PROPERTY_SOURCE_NAME, new Properties() {
|
||||
{
|
||||
setProperty(NetworkOptionKeys.NETWORK_ID, String.valueOf(BaseCurrencyNetwork.CURRENT_NETWORK.ordinal()));
|
||||
if (externalTorUseSafeCookieAuthentication)
|
||||
setProperty(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE, "true");
|
||||
if (torStreamIsolation)
|
||||
setProperty(NetworkOptionKeys.TOR_STREAM_ISOLATION, "true");
|
||||
|
||||
|
@ -273,10 +273,6 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet
|
||||
|
||||
protected void customizeOptionParsing(OptionParser parser) {
|
||||
//NetworkOptionKeys
|
||||
parser.accepts(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE,
|
||||
"Use the SafeCookie method when authenticating to the already running Tor service.")
|
||||
/*.availableIf(Config.TOR_CONTROL_COOKIE_FILE)*/;
|
||||
|
||||
parser.accepts(NetworkOptionKeys.TOR_STREAM_ISOLATION,
|
||||
"Use stream isolation for Tor [experimental!].");
|
||||
|
||||
|
@ -19,7 +19,6 @@ package bisq.network;
|
||||
|
||||
public class NetworkOptionKeys {
|
||||
public static final String NETWORK_ID = "networkId";
|
||||
public static final String EXTERNAL_TOR_USE_SAFECOOKIE = "torControlUseSafeCookieAuth";
|
||||
public static final String TOR_STREAM_ISOLATION = "torStreamIsolation";
|
||||
public static final String MSG_THROTTLE_PER_SEC = "msgThrottlePerSec";
|
||||
public static final String MSG_THROTTLE_PER_10_SEC = "msgThrottlePer10Sec";
|
||||
|
@ -53,7 +53,7 @@ public class NetworkNodeProvider implements Provider<NetworkNode> {
|
||||
@Named(Config.TOR_CONTROL_PASSWORD) String password,
|
||||
@Nullable @Named(Config.TOR_CONTROL_COOKIE_FILE) File cookieFile,
|
||||
@Named(NetworkOptionKeys.TOR_STREAM_ISOLATION) boolean streamIsolation,
|
||||
@Named(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE) boolean useSafeCookieAuthentication ) {
|
||||
@Named(Config.TOR_CONTROL_USE_SAFE_COOKIE_AUTH) boolean useSafeCookieAuthentication ) {
|
||||
networkNode = useLocalhostForP2P ?
|
||||
new LocalhostNetworkNode(port, networkProtoResolver) :
|
||||
new TorNetworkNode(port, networkProtoResolver, streamIsolation,
|
||||
|
@ -98,7 +98,7 @@ public class P2PModule extends AppModule {
|
||||
bindConstant().annotatedWith(named(TOR_CONTROL_PORT)).to(config.getTorControlPort());
|
||||
bindConstant().annotatedWith(named(TOR_CONTROL_PASSWORD)).to(config.getTorControlPassword());
|
||||
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(TOR_CONTROL_USE_SAFE_COOKIE_AUTH)).to(config.isUseTorControlSafeCookieAuth());
|
||||
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_10_SEC)).to(environment.getRequiredProperty(NetworkOptionKeys.MSG_THROTTLE_PER_10_SEC));
|
||||
|
Loading…
Reference in New Issue
Block a user