mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Move 'rpcPort' option handling to Config
This commit is contained in:
parent
182f472394
commit
86e1ae1008
@ -67,10 +67,11 @@ public class Config {
|
||||
public static final String RPC_USER = "rpcUser";
|
||||
public static final String RPC_PASSWORD = "rpcPassword";
|
||||
public static final String RPC_HOST = "rpcHost";
|
||||
public static final String RPC_PORT = "rpcPort";
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(Config.class);
|
||||
|
||||
public static final int DEFAULT_INT = Integer.MIN_VALUE;
|
||||
public static final int UNSPECIFIED_PORT = -1;
|
||||
static final String DEFAULT_CONFIG_FILE_NAME = "bisq.properties";
|
||||
public static final String DEFAULT_REGTEST_HOST = "localhost";
|
||||
public static final int DEFAULT_NUM_CONNECTIONS_FOR_BTC = 9; // down from BitcoinJ default of 12
|
||||
@ -131,6 +132,7 @@ public class Config {
|
||||
private final String rpcUser;
|
||||
private final String rpcPassword;
|
||||
private final String rpcHost;
|
||||
private final int rpcPort;
|
||||
|
||||
// properties derived from cli options, but not exposed as cli options themselves
|
||||
private boolean localBitcoinNodeIsRunning = false; // FIXME: eliminate mutable state
|
||||
@ -356,7 +358,8 @@ public class Config {
|
||||
.availableUnless(TORRC_FILE, TORRC_OPTIONS)
|
||||
.withRequiredArg()
|
||||
.ofType(int.class)
|
||||
.describedAs("port");
|
||||
.describedAs("port")
|
||||
.defaultsTo(UNSPECIFIED_PORT);
|
||||
|
||||
ArgumentAcceptingOptionSpec<String> torControlPasswordOpt =
|
||||
parser.accepts(TOR_CONTROL_PASSWORD, "The password for controlling the already running Tor service.")
|
||||
@ -460,6 +463,12 @@ public class Config {
|
||||
.withRequiredArg()
|
||||
.defaultsTo("");
|
||||
|
||||
ArgumentAcceptingOptionSpec<Integer> rpcPortOpt =
|
||||
parser.accepts(RPC_PORT, "Bitcoind rpc port")
|
||||
.withRequiredArg()
|
||||
.ofType(int.class)
|
||||
.defaultsTo(UNSPECIFIED_PORT);
|
||||
|
||||
try {
|
||||
OptionSet cliOpts = parser.parse(args);
|
||||
|
||||
@ -512,7 +521,7 @@ public class Config {
|
||||
this.logLevel = options.valueOf(logLevelOpt);
|
||||
this.torrcFile = options.has(torrcFileOpt) ? options.valueOf(torrcFileOpt).toFile() : null;
|
||||
this.torrcOptions = options.valueOf(torrcOptionsOpt);
|
||||
this.torControlPort = options.has(torControlPortOpt) ? options.valueOf(torControlPortOpt) : DEFAULT_INT;
|
||||
this.torControlPort = options.valueOf(torControlPortOpt);
|
||||
this.torControlPassword = options.valueOf(torControlPasswordOpt);
|
||||
this.torControlCookieFile = options.has(torControlCookieFileOpt) ?
|
||||
options.valueOf(torControlCookieFileOpt).toFile() : null;
|
||||
@ -550,6 +559,7 @@ public class Config {
|
||||
this.rpcUser = options.valueOf(rpcUserOpt);
|
||||
this.rpcPassword = options.valueOf(rpcPasswordOpt);
|
||||
this.rpcHost = options.valueOf(rpcHostOpt);
|
||||
this.rpcPort = options.valueOf(rpcPortOpt);
|
||||
} catch (OptionException ex) {
|
||||
throw new ConfigException(format("problem parsing option '%s': %s",
|
||||
ex.options().get(0),
|
||||
@ -825,4 +835,8 @@ public class Config {
|
||||
public String getRpcHost() {
|
||||
return rpcHost;
|
||||
}
|
||||
|
||||
public int getRpcPort() {
|
||||
return rpcPort;
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public class BisqEnvironment extends StandardEnvironment {
|
||||
protected boolean isBitcoinLocalhostNodeRunning;
|
||||
|
||||
protected final String
|
||||
rpcPort, rpcBlockNotificationPort, rpcBlockNotificationHost, dumpBlockchainData, fullDaoNode,
|
||||
rpcBlockNotificationPort, rpcBlockNotificationHost, dumpBlockchainData, fullDaoNode,
|
||||
genesisTxId, genesisBlockHeight, genesisTotalSupply,
|
||||
daoActivated;
|
||||
|
||||
@ -69,7 +69,6 @@ public class BisqEnvironment extends StandardEnvironment {
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public BisqEnvironment(PropertySource commandLineProperties) {
|
||||
//DaoOptionKeys
|
||||
rpcPort = getProperty(commandLineProperties, DaoOptionKeys.RPC_PORT, "");
|
||||
rpcBlockNotificationPort = getProperty(commandLineProperties, DaoOptionKeys.RPC_BLOCK_NOTIFICATION_PORT, "");
|
||||
rpcBlockNotificationHost = getProperty(commandLineProperties, DaoOptionKeys.RPC_BLOCK_NOTIFICATION_HOST, "");
|
||||
dumpBlockchainData = getProperty(commandLineProperties, DaoOptionKeys.DUMP_BLOCKCHAIN_DATA, "");
|
||||
@ -95,7 +94,6 @@ public class BisqEnvironment extends StandardEnvironment {
|
||||
private PropertySource<?> defaultProperties() {
|
||||
return new PropertiesPropertySource(BISQ_DEFAULT_PROPERTY_SOURCE_NAME, new Properties() {
|
||||
{
|
||||
setProperty(DaoOptionKeys.RPC_PORT, rpcPort);
|
||||
setProperty(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_PORT, rpcBlockNotificationPort);
|
||||
setProperty(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_HOST, rpcBlockNotificationHost);
|
||||
setProperty(DaoOptionKeys.DUMP_BLOCKCHAIN_DATA, dumpBlockchainData);
|
||||
|
@ -285,10 +285,6 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet
|
||||
.ofType(boolean.class);
|
||||
|
||||
//RpcOptionKeys
|
||||
parser.accepts(DaoOptionKeys.RPC_PORT,
|
||||
"Bitcoind rpc port")
|
||||
.withRequiredArg();
|
||||
|
||||
parser.accepts(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_PORT,
|
||||
"Bitcoind rpc port for block notifications")
|
||||
.withRequiredArg();
|
||||
|
@ -226,7 +226,7 @@ public class DaoModule extends AppModule {
|
||||
bindConstant().annotatedWith(named(Config.RPC_USER)).to(config.getRpcUser());
|
||||
bindConstant().annotatedWith(named(Config.RPC_PASSWORD)).to(config.getRpcPassword());
|
||||
bindConstant().annotatedWith(named(Config.RPC_HOST)).to(config.getRpcHost());
|
||||
bindConstant().annotatedWith(named(DaoOptionKeys.RPC_PORT)).to(environment.getRequiredProperty(DaoOptionKeys.RPC_PORT));
|
||||
bindConstant().annotatedWith(named(Config.RPC_PORT)).to(config.getRpcPort());
|
||||
bindConstant().annotatedWith(named(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_PORT))
|
||||
.to(environment.getRequiredProperty(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_PORT));
|
||||
bindConstant().annotatedWith(named(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_HOST))
|
||||
|
@ -21,7 +21,6 @@ package bisq.core.dao;
|
||||
* Provides program argument options used in the DAO domain.
|
||||
*/
|
||||
public class DaoOptionKeys {
|
||||
public static final String RPC_PORT = "rpcPort";
|
||||
public static final String RPC_BLOCK_NOTIFICATION_PORT = "rpcBlockNotificationPort";
|
||||
public static final String RPC_BLOCK_NOTIFICATION_HOST = "rpcBlockNotificationHost";
|
||||
|
||||
|
@ -74,7 +74,7 @@ public class RpcService {
|
||||
private final String rpcUser;
|
||||
private final String rpcPassword;
|
||||
private final String rpcHost;
|
||||
private final String rpcPort;
|
||||
private final int rpcPort;
|
||||
private final String rpcBlockPort;
|
||||
private final String rpcBlockHost;
|
||||
|
||||
@ -94,7 +94,7 @@ public class RpcService {
|
||||
@Inject
|
||||
public RpcService(Preferences preferences,
|
||||
@Named(Config.RPC_HOST) String rpcHost,
|
||||
@Named(DaoOptionKeys.RPC_PORT) String rpcPort,
|
||||
@Named(Config.RPC_PORT) int rpcPort,
|
||||
@Named(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_PORT) String rpcBlockPort,
|
||||
@Named(DaoOptionKeys.RPC_BLOCK_NOTIFICATION_HOST) String rpcBlockHost) {
|
||||
this.rpcUser = preferences.getRpcUser();
|
||||
@ -102,15 +102,15 @@ public class RpcService {
|
||||
|
||||
// mainnet is 8332, testnet 18332, regtest 18443
|
||||
boolean isHostSet = !rpcHost.isEmpty();
|
||||
boolean isPortSet = rpcPort != null && !rpcPort.isEmpty();
|
||||
boolean isPortSet = rpcPort != Config.UNSPECIFIED_PORT;
|
||||
boolean isMainnet = BaseCurrencyNetwork.CURRENT_NETWORK.isMainnet();
|
||||
boolean isTestnet = BaseCurrencyNetwork.CURRENT_NETWORK.isTestnet();
|
||||
boolean isDaoBetaNet = BaseCurrencyNetwork.CURRENT_NETWORK.isDaoBetaNet();
|
||||
this.rpcHost = isHostSet ? rpcHost : "127.0.0.1";
|
||||
this.rpcPort = isPortSet ? rpcPort :
|
||||
isMainnet || isDaoBetaNet ? "8332" :
|
||||
isTestnet ? "18332" :
|
||||
"18443"; // regtest
|
||||
isMainnet || isDaoBetaNet ? 8332 :
|
||||
isTestnet ? 18332 :
|
||||
18443; // regtest
|
||||
boolean isBlockPortSet = rpcBlockPort != null && !rpcBlockPort.isEmpty();
|
||||
boolean isBlockHostSet = rpcBlockHost != null && !rpcBlockHost.isEmpty();
|
||||
this.rpcBlockPort = isBlockPortSet ? rpcBlockPort : "5125";
|
||||
@ -139,11 +139,11 @@ public class RpcService {
|
||||
nodeConfig.setProperty("node.bitcoind.rpc.auth_scheme", "Basic");
|
||||
nodeConfig.setProperty("node.bitcoind.rpc.user", rpcUser);
|
||||
nodeConfig.setProperty("node.bitcoind.rpc.password", rpcPassword);
|
||||
nodeConfig.setProperty("node.bitcoind.rpc.port", rpcPort);
|
||||
nodeConfig.setProperty("node.bitcoind.rpc.port", Integer.toString(rpcPort));
|
||||
nodeConfig.setProperty("node.bitcoind.notification.block.port", rpcBlockPort);
|
||||
nodeConfig.setProperty("node.bitcoind.notification.block.host", rpcBlockHost);
|
||||
nodeConfig.setProperty("node.bitcoind.notification.alert.port", String.valueOf(bisq.network.p2p.Utils.findFreeSystemPort()));
|
||||
nodeConfig.setProperty("node.bitcoind.notification.wallet.port", String.valueOf(bisq.network.p2p.Utils.findFreeSystemPort()));
|
||||
nodeConfig.setProperty("node.bitcoind.notification.alert.port", Integer.toString(bisq.network.p2p.Utils.findFreeSystemPort()));
|
||||
nodeConfig.setProperty("node.bitcoind.notification.wallet.port", Integer.toString(bisq.network.p2p.Utils.findFreeSystemPort()));
|
||||
|
||||
nodeConfig.setProperty("node.bitcoind.http.auth_scheme", "Basic");
|
||||
BtcdClientImpl client = new BtcdClientImpl(httpProvider, nodeConfig);
|
||||
|
@ -56,7 +56,7 @@ public class NetworkNodeProvider implements Provider<NetworkNode> {
|
||||
networkNode = useLocalhostForP2P ?
|
||||
new LocalhostNetworkNode(port, networkProtoResolver) :
|
||||
new TorNetworkNode(port, networkProtoResolver, streamIsolation,
|
||||
controlPort != Config.DEFAULT_INT ?
|
||||
controlPort != Config.UNSPECIFIED_PORT ?
|
||||
new RunningTor(torDir, controlPort, password, cookieFile, useSafeCookieAuthentication) :
|
||||
new NewTor(torDir, torrcFile, torrcOptions, bridgeAddressProvider.getBridgeAddresses()));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user