diff --git a/common/src/main/java/bisq/common/config/Config.java b/common/src/main/java/bisq/common/config/Config.java index 53805b7e0a..a5817ca695 100644 --- a/common/src/main/java/bisq/common/config/Config.java +++ b/common/src/main/java/bisq/common/config/Config.java @@ -53,6 +53,7 @@ public class Config { public static final String TORRC_OPTIONS = "torrcOptions"; 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"; static final String DEFAULT_CONFIG_FILE_NAME = "bisq.properties"; @@ -96,6 +97,7 @@ public class Config { private final String torrcOptions; private final int torControlPort; private final String torControlPassword; + private final File torControlCookieFile; // properties derived from cli options, but not exposed as cli options themselves private boolean localBitcoinNodeIsRunning = false; // FIXME: eliminate mutable state @@ -327,6 +329,15 @@ public class Config { .availableIf(TOR_CONTROL_PORT) .withRequiredArg() .defaultsTo(""); + + ArgumentAcceptingOptionSpec 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 { OptionSet cliOpts = parser.parse(args); @@ -381,6 +392,8 @@ public class Config { this.torrcOptions = options.valueOf(torrcOptionsOpt); this.torControlPort = options.has(torControlPortOpt) ? options.valueOf(torControlPortOpt) : NULL_INT; this.torControlPassword = options.valueOf(torControlPasswordOpt); + this.torControlCookieFile = options.has(torControlCookieFileOpt) ? + options.valueOf(torControlCookieFileOpt).toFile() : null; this.referralId = options.valueOf(referralIdOpt); this.useDevMode = options.valueOf(useDevModeOpt); this.useDevPrivilegeKeys = options.valueOf(useDevPrivilegeKeysOpt); @@ -601,4 +614,8 @@ public class Config { public String getTorControlPassword() { return torControlPassword; } + + public File getTorControlCookieFile() { + return torControlCookieFile; + } } diff --git a/core/src/main/java/bisq/core/app/BisqEnvironment.java b/core/src/main/java/bisq/core/app/BisqEnvironment.java index 8c8f647e24..54a2e9f3bb 100644 --- a/core/src/main/java/bisq/core/app/BisqEnvironment.java +++ b/core/src/main/java/bisq/core/app/BisqEnvironment.java @@ -65,7 +65,6 @@ public class BisqEnvironment extends StandardEnvironment { protected final String btcNodes, useTorForBtc, rpcUser, rpcPassword, rpcHost, rpcPort, rpcBlockNotificationPort, rpcBlockNotificationHost, dumpBlockchainData, fullDaoNode, - externalTorCookieFile, useAllProvidedNodes, numConnectionForBtc, genesisTxId, genesisBlockHeight, genesisTotalSupply, daoActivated, msgThrottlePerSec, msgThrottlePer10Sec, sendMsgThrottleTrigger, sendMsgThrottleSleep; @@ -82,7 +81,6 @@ public class BisqEnvironment extends StandardEnvironment { @SuppressWarnings("ConstantConditions") public BisqEnvironment(PropertySource commandLineProperties) { //NetworkOptionKeys - externalTorCookieFile = getProperty(commandLineProperties, NetworkOptionKeys.EXTERNAL_TOR_COOKIE_FILE, ""); externalTorUseSafeCookieAuthentication = commandLineProperties.containsProperty(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE); 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() { { setProperty(NetworkOptionKeys.NETWORK_ID, String.valueOf(BaseCurrencyNetwork.CURRENT_NETWORK.ordinal())); - setProperty(NetworkOptionKeys.EXTERNAL_TOR_COOKIE_FILE, externalTorCookieFile); if (externalTorUseSafeCookieAuthentication) setProperty(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE, "true"); if (torStreamIsolation) diff --git a/core/src/main/java/bisq/core/app/BisqExecutable.java b/core/src/main/java/bisq/core/app/BisqExecutable.java index a259f474ad..de96502646 100644 --- a/core/src/main/java/bisq/core/app/BisqExecutable.java +++ b/core/src/main/java/bisq/core/app/BisqExecutable.java @@ -51,8 +51,6 @@ import org.springframework.core.env.JOptCommandLinePropertySource; import joptsimple.OptionException; import joptsimple.OptionParser; import joptsimple.OptionSet; -import joptsimple.util.PathConverter; -import joptsimple.util.PathProperties; import com.google.inject.Guice; import com.google.inject.Injector; @@ -275,17 +273,9 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet protected void customizeOptionParsing(OptionParser parser) { //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, "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, "Use stream isolation for Tor [experimental!]."); diff --git a/p2p/src/main/java/bisq/network/NetworkOptionKeys.java b/p2p/src/main/java/bisq/network/NetworkOptionKeys.java index d5c130fdc7..31f03b69ed 100644 --- a/p2p/src/main/java/bisq/network/NetworkOptionKeys.java +++ b/p2p/src/main/java/bisq/network/NetworkOptionKeys.java @@ -19,7 +19,6 @@ package bisq.network; public class NetworkOptionKeys { 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 TOR_STREAM_ISOLATION = "torStreamIsolation"; public static final String MSG_THROTTLE_PER_SEC = "msgThrottlePerSec"; diff --git a/p2p/src/main/java/bisq/network/p2p/NetworkNodeProvider.java b/p2p/src/main/java/bisq/network/p2p/NetworkNodeProvider.java index d5f64e6f8c..c552c81eb2 100644 --- a/p2p/src/main/java/bisq/network/p2p/NetworkNodeProvider.java +++ b/p2p/src/main/java/bisq/network/p2p/NetworkNodeProvider.java @@ -51,7 +51,7 @@ public class NetworkNodeProvider implements Provider { @Named(Config.TORRC_OPTIONS) String torrcOptions, @Named(Config.TOR_CONTROL_PORT) int controlPort, @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.EXTERNAL_TOR_USE_SAFECOOKIE) boolean useSafeCookieAuthentication ) { networkNode = useLocalhostForP2P ? diff --git a/p2p/src/main/java/bisq/network/p2p/P2PModule.java b/p2p/src/main/java/bisq/network/p2p/P2PModule.java index df3ecd7b55..0bdef39721 100644 --- a/p2p/src/main/java/bisq/network/p2p/P2PModule.java +++ b/p2p/src/main/java/bisq/network/p2p/P2PModule.java @@ -97,7 +97,7 @@ public class P2PModule extends AppModule { bindConstant().annotatedWith(named(TORRC_OPTIONS)).to(config.getTorrcOptions()); bindConstant().annotatedWith(named(TOR_CONTROL_PORT)).to(config.getTorControlPort()); 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.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)); diff --git a/p2p/src/main/java/bisq/network/p2p/network/RunningTor.java b/p2p/src/main/java/bisq/network/p2p/network/RunningTor.java index 4af31d2ab9..e39be46a97 100644 --- a/p2p/src/main/java/bisq/network/p2p/network/RunningTor.java +++ b/p2p/src/main/java/bisq/network/p2p/network/RunningTor.java @@ -29,11 +29,11 @@ import lombok.extern.slf4j.Slf4j; /** * This class creates a brand new instance of the Tor onion router. - * + * * When asked, the class checks for the authentication method selected and * connects to the given control port. Finally, a {@link Tor} instance is * returned for further use. - * + * * @author Florian Reimair * */ @@ -46,12 +46,12 @@ public class RunningTor extends TorMode { 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) { super(torDir); this.controlPort = controlPort; this.password = password; - this.cookieFile = new File(cookieFile); + this.cookieFile = cookieFile; this.useSafeCookieAuthentication = useSafeCookieAuthentication; }