mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Move 'useLocalhostForP2P' option handling to Config
This commit is contained in:
parent
ef7196ef8a
commit
0e48a3ef2c
@ -42,6 +42,7 @@ public class Config {
|
||||
public static final String SEED_NODES = "seedNodes";
|
||||
public static final String BAN_LIST = "banList";
|
||||
public static final String NODE_PORT = "nodePort";
|
||||
public static final String USE_LOCALHOST_FOR_P2P = "useLocalhostForP2P";
|
||||
|
||||
static final String DEFAULT_CONFIG_FILE_NAME = "bisq.properties";
|
||||
|
||||
@ -78,6 +79,7 @@ public class Config {
|
||||
private final List<String> providers;
|
||||
private final List<String> seedNodes;
|
||||
private final List<String> banList;
|
||||
private final boolean useLocalhostForP2P;
|
||||
|
||||
// properties derived from cli options, but not exposed as cli options themselves
|
||||
private boolean localBitcoinNodeIsRunning = false; // FIXME: eliminate mutable state
|
||||
@ -261,6 +263,12 @@ public class Config {
|
||||
.withRequiredArg()
|
||||
.withValuesSeparatedBy(',')
|
||||
.describedAs("host:port[,...]");
|
||||
|
||||
ArgumentAcceptingOptionSpec<Boolean> useLocalhostForP2POpt =
|
||||
parser.accepts(USE_LOCALHOST_FOR_P2P, "Use localhost P2P network for development")
|
||||
.withRequiredArg()
|
||||
.ofType(boolean.class)
|
||||
.defaultsTo(false);
|
||||
try {
|
||||
OptionSet cliOpts = parser.parse(args);
|
||||
|
||||
@ -321,6 +329,7 @@ public class Config {
|
||||
this.providers = options.valuesOf(providersOpt);
|
||||
this.seedNodes = options.valuesOf(seedNodesOpt);
|
||||
this.banList = options.valuesOf(banListOpt);
|
||||
this.useLocalhostForP2P = options.valueOf(useLocalhostForP2POpt);
|
||||
} catch (OptionException ex) {
|
||||
throw new ConfigException(format("problem parsing option '%s': %s",
|
||||
ex.options().get(0),
|
||||
@ -500,4 +509,8 @@ public class Config {
|
||||
public List<String> getBanList() {
|
||||
return banList;
|
||||
}
|
||||
|
||||
public boolean isUseLocalhostForP2P() {
|
||||
return useLocalhostForP2P;
|
||||
}
|
||||
}
|
||||
|
@ -276,11 +276,6 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet
|
||||
|
||||
protected void customizeOptionParsing(OptionParser parser) {
|
||||
//NetworkOptionKeys
|
||||
parser.accepts(NetworkOptionKeys.USE_LOCALHOST_FOR_P2P,
|
||||
format("Use localhost P2P network for development (default: %s)", "false"))
|
||||
.withRequiredArg()
|
||||
.ofType(boolean.class);
|
||||
|
||||
parser.accepts(NetworkOptionKeys.MAX_CONNECTIONS,
|
||||
format("Max. connections a peer will try to keep (default: %s)", P2PService.MAX_CONNECTIONS_DEFAULT))
|
||||
.withRequiredArg()
|
||||
|
@ -19,11 +19,11 @@ package bisq.core.notifications;
|
||||
|
||||
import bisq.core.user.Preferences;
|
||||
|
||||
import bisq.network.NetworkOptionKeys;
|
||||
import bisq.network.http.HttpClient;
|
||||
|
||||
import bisq.common.UserThread;
|
||||
import bisq.common.app.Version;
|
||||
import bisq.common.config.Config;
|
||||
import bisq.common.util.Utilities;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
@ -93,7 +93,7 @@ public class MobileNotificationService {
|
||||
MobileNotificationValidator mobileNotificationValidator,
|
||||
MobileModel mobileModel,
|
||||
HttpClient httpClient,
|
||||
@Named(NetworkOptionKeys.USE_LOCALHOST_FOR_P2P) Boolean useLocalHost) {
|
||||
@Named(Config.USE_LOCALHOST_FOR_P2P) boolean useLocalHost) {
|
||||
this.preferences = preferences;
|
||||
this.mobileMessageEncryption = mobileMessageEncryption;
|
||||
this.mobileNotificationValidator = mobileNotificationValidator;
|
||||
|
@ -17,8 +17,6 @@
|
||||
|
||||
package bisq.core.provider;
|
||||
|
||||
import bisq.network.NetworkOptionKeys;
|
||||
|
||||
import bisq.common.config.Config;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
@ -65,7 +63,7 @@ public class ProvidersRepository {
|
||||
@Inject
|
||||
public ProvidersRepository(Config config,
|
||||
@Named(Config.PROVIDERS) List<String> providers,
|
||||
@Named(NetworkOptionKeys.USE_LOCALHOST_FOR_P2P) boolean useLocalhostForP2P) {
|
||||
@Named(Config.USE_LOCALHOST_FOR_P2P) boolean useLocalhostForP2P) {
|
||||
|
||||
this.config = config;
|
||||
this.providersFromProgramArgs = providers;
|
||||
|
@ -18,7 +18,6 @@
|
||||
package bisq.network;
|
||||
|
||||
public class NetworkOptionKeys {
|
||||
public static final String USE_LOCALHOST_FOR_P2P = "useLocalhostForP2P";
|
||||
public static final String MAX_CONNECTIONS = "maxConnections";
|
||||
public static final String NETWORK_ID = "networkId";
|
||||
//SOCKS_5_PROXY_BTC_ADDRESS used in network module so dont move it to BtcOptionKeys
|
||||
|
@ -42,7 +42,7 @@ public class NetworkNodeProvider implements Provider<NetworkNode> {
|
||||
@Inject
|
||||
public NetworkNodeProvider(NetworkProtoResolver networkProtoResolver,
|
||||
BridgeAddressProvider bridgeAddressProvider,
|
||||
@Named(NetworkOptionKeys.USE_LOCALHOST_FOR_P2P) boolean useLocalhostForP2P,
|
||||
@Named(Config.USE_LOCALHOST_FOR_P2P) boolean useLocalhostForP2P,
|
||||
@Named(Config.NODE_PORT) int port,
|
||||
@Named(Config.TOR_DIR) File torDir,
|
||||
@Named(NetworkOptionKeys.TORRC_FILE) String torrcFile,
|
||||
|
@ -52,6 +52,7 @@ import java.util.List;
|
||||
import static bisq.common.config.Config.BAN_LIST;
|
||||
import static bisq.common.config.Config.NODE_PORT;
|
||||
import static bisq.common.config.Config.TOR_DIR;
|
||||
import static bisq.common.config.Config.USE_LOCALHOST_FOR_P2P;
|
||||
import static com.google.inject.name.Names.named;
|
||||
|
||||
public class P2PModule extends AppModule {
|
||||
@ -81,8 +82,7 @@ public class P2PModule extends AppModule {
|
||||
|
||||
requestStaticInjection(Connection.class);
|
||||
|
||||
Boolean useLocalhostForP2P = environment.getProperty(NetworkOptionKeys.USE_LOCALHOST_FOR_P2P, boolean.class, false);
|
||||
bind(boolean.class).annotatedWith(Names.named(NetworkOptionKeys.USE_LOCALHOST_FOR_P2P)).toInstance(useLocalhostForP2P);
|
||||
bindConstant().annotatedWith(Names.named(USE_LOCALHOST_FOR_P2P)).to(config.isUseLocalhostForP2P());
|
||||
|
||||
bind(File.class).annotatedWith(named(TOR_DIR)).toInstance(config.getTorDir());
|
||||
|
||||
|
@ -111,8 +111,8 @@ public class DummySeedNode {
|
||||
maxConnections = Integer.parseInt(arg);
|
||||
log.debug("From processArgs: maxConnections=" + maxConnections);
|
||||
checkArgument(maxConnections < MAX_CONNECTIONS_LIMIT, "maxConnections seems to be a bit too high...");
|
||||
} else if (arg.startsWith(NetworkOptionKeys.USE_LOCALHOST_FOR_P2P)) {
|
||||
arg = arg.substring(NetworkOptionKeys.USE_LOCALHOST_FOR_P2P.length() + 1);
|
||||
} else if (arg.startsWith(Config.USE_LOCALHOST_FOR_P2P)) {
|
||||
arg = arg.substring(Config.USE_LOCALHOST_FOR_P2P.length() + 1);
|
||||
checkArgument(arg.equals("true") || arg.equals("false"));
|
||||
useLocalhostForP2P = ("true").equals(arg);
|
||||
log.debug("From processArgs: useLocalhostForP2P=" + useLocalhostForP2P);
|
||||
|
Loading…
Reference in New Issue
Block a user