Move 'seedNode' option handling to Config

And eliminate @Named injection in favor of calling config.getSeedNodes()
This commit is contained in:
Chris Beams 2019-12-13 15:29:11 +01:00
parent 7be2ff19f8
commit e118165e9a
No known key found for this signature in database
GPG Key ID: 3D214F8F5BC5ED73
8 changed files with 26 additions and 27 deletions

View File

@ -39,6 +39,7 @@ public class Config {
public static final String IGNORE_DEV_MSG = "ignoreDevMsg"; public static final String IGNORE_DEV_MSG = "ignoreDevMsg";
public static final String PROVIDERS = "providers"; public static final String PROVIDERS = "providers";
public static final String LOG_LEVEL = "logLevel"; public static final String LOG_LEVEL = "logLevel";
public static final String SEED_NODES = "seedNodes";
static final String DEFAULT_CONFIG_FILE_NAME = "bisq.properties"; static final String DEFAULT_CONFIG_FILE_NAME = "bisq.properties";
static final int DEFAULT_NODE_PORT = 9999; static final int DEFAULT_NODE_PORT = 9999;
@ -74,6 +75,7 @@ public class Config {
private final int maxMemory; private final int maxMemory;
private final boolean ignoreDevMsg; private final boolean ignoreDevMsg;
private final List<String> providers; private final List<String> providers;
private final List<String> seedNodes;
// 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
@ -244,6 +246,14 @@ public class Config {
.withRequiredArg() .withRequiredArg()
.withValuesSeparatedBy(',') .withValuesSeparatedBy(',')
.describedAs("host:port[,...]"); .describedAs("host:port[,...]");
ArgumentAcceptingOptionSpec<String> seedNodesOpt =
parser.accepts(SEED_NODES, "Override hard coded seed nodes as comma separated list e.g. " +
"'rxdkppp3vicnbgqt.onion:8002,mfla72c4igh5ta2t.onion:8002'")
.withRequiredArg()
.withValuesSeparatedBy(',')
.describedAs("host:port[,...]");
try { try {
OptionSet cliOpts = parser.parse(args); OptionSet cliOpts = parser.parse(args);
@ -302,6 +312,7 @@ public class Config {
this.maxMemory = options.valueOf(maxMemoryOpt); this.maxMemory = options.valueOf(maxMemoryOpt);
this.ignoreDevMsg = options.valueOf(ignoreDevMsgOpt); this.ignoreDevMsg = options.valueOf(ignoreDevMsgOpt);
this.providers = options.valuesOf(providersOpt); this.providers = options.valuesOf(providersOpt);
this.seedNodes = options.valuesOf(seedNodesOpt);
} catch (OptionException ex) { } catch (OptionException ex) {
throw new ConfigException(format("problem parsing option '%s': %s", throw new ConfigException(format("problem parsing option '%s': %s",
ex.options().get(0), ex.options().get(0),
@ -473,4 +484,8 @@ public class Config {
public List<String> getProviders() { public List<String> getProviders() {
return providers; return providers;
} }
public List<String> getSeedNodes() {
return seedNodes;
}
} }

View File

@ -63,7 +63,7 @@ public class BisqEnvironment extends StandardEnvironment {
@Setter @Setter
protected boolean isBitcoinLocalhostNodeRunning; protected boolean isBitcoinLocalhostNodeRunning;
protected final String btcNodes, seedNodes, useTorForBtc, rpcUser, rpcPassword, protected final String btcNodes, useTorForBtc, rpcUser, rpcPassword,
rpcHost, rpcPort, rpcBlockNotificationPort, rpcBlockNotificationHost, dumpBlockchainData, fullDaoNode, rpcHost, rpcPort, rpcBlockNotificationPort, rpcBlockNotificationHost, dumpBlockchainData, fullDaoNode,
banList, socks5ProxyBtcAddress, banList, socks5ProxyBtcAddress,
torRcFile, torRcOptions, externalTorControlPort, externalTorPassword, externalTorCookieFile, torRcFile, torRcOptions, externalTorControlPort, externalTorPassword, externalTorCookieFile,
@ -83,7 +83,6 @@ public class BisqEnvironment extends StandardEnvironment {
@SuppressWarnings("ConstantConditions") @SuppressWarnings("ConstantConditions")
public BisqEnvironment(PropertySource commandLineProperties) { public BisqEnvironment(PropertySource commandLineProperties) {
//NetworkOptionKeys //NetworkOptionKeys
seedNodes = getProperty(commandLineProperties, NetworkOptionKeys.SEED_NODES_KEY, "");
banList = getProperty(commandLineProperties, NetworkOptionKeys.BAN_LIST, ""); banList = getProperty(commandLineProperties, NetworkOptionKeys.BAN_LIST, "");
socks5ProxyBtcAddress = getProperty(commandLineProperties, NetworkOptionKeys.SOCKS_5_PROXY_BTC_ADDRESS, ""); socks5ProxyBtcAddress = getProperty(commandLineProperties, NetworkOptionKeys.SOCKS_5_PROXY_BTC_ADDRESS, "");
socks5ProxyHttpAddress = getProperty(commandLineProperties, NetworkOptionKeys.SOCKS_5_PROXY_HTTP_ADDRESS, ""); socks5ProxyHttpAddress = getProperty(commandLineProperties, NetworkOptionKeys.SOCKS_5_PROXY_HTTP_ADDRESS, "");
@ -140,7 +139,6 @@ public class BisqEnvironment extends StandardEnvironment {
private PropertySource<?> defaultProperties() { private PropertySource<?> defaultProperties() {
return new PropertiesPropertySource(BISQ_DEFAULT_PROPERTY_SOURCE_NAME, new Properties() { return new PropertiesPropertySource(BISQ_DEFAULT_PROPERTY_SOURCE_NAME, new Properties() {
{ {
setProperty(NetworkOptionKeys.SEED_NODES_KEY, seedNodes);
setProperty(NetworkOptionKeys.BAN_LIST, banList); setProperty(NetworkOptionKeys.BAN_LIST, banList);
setProperty(NetworkOptionKeys.NETWORK_ID, String.valueOf(BaseCurrencyNetwork.CURRENT_NETWORK.ordinal())); setProperty(NetworkOptionKeys.NETWORK_ID, String.valueOf(BaseCurrencyNetwork.CURRENT_NETWORK.ordinal()));
setProperty(NetworkOptionKeys.SOCKS_5_PROXY_BTC_ADDRESS, socks5ProxyBtcAddress); setProperty(NetworkOptionKeys.SOCKS_5_PROXY_BTC_ADDRESS, socks5ProxyBtcAddress);

View File

@ -276,12 +276,6 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet
protected void customizeOptionParsing(OptionParser parser) { protected void customizeOptionParsing(OptionParser parser) {
//NetworkOptionKeys //NetworkOptionKeys
parser.accepts(NetworkOptionKeys.SEED_NODES_KEY,
"Override hard coded seed nodes as comma separated list e.g. " +
"'rxdkppp3vicnbgqt.onion:8002,mfla72c4igh5ta2t.onion:8002'")
.withRequiredArg()
.describedAs("host:port[,...]");
parser.accepts(NetworkOptionKeys.BAN_LIST, parser.accepts(NetworkOptionKeys.BAN_LIST,
"Nodes to exclude from network connections.") "Nodes to exclude from network connections.")
.withRequiredArg() .withRequiredArg()

View File

@ -17,21 +17,18 @@
package bisq.core.network.p2p.seed; package bisq.core.network.p2p.seed;
import bisq.network.NetworkOptionKeys;
import bisq.network.p2p.NodeAddress; import bisq.network.p2p.NodeAddress;
import bisq.network.p2p.seed.SeedNodeRepository; import bisq.network.p2p.seed.SeedNodeRepository;
import bisq.common.config.Config; import bisq.common.config.Config;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -40,8 +37,6 @@ import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import javax.annotation.Nullable;
// If a new BaseCurrencyNetwork type gets added we need to add the resource file for it as well! // If a new BaseCurrencyNetwork type gets added we need to add the resource file for it as well!
@Slf4j @Slf4j
@Singleton @Singleton
@ -51,22 +46,18 @@ public class DefaultSeedNodeRepository implements SeedNodeRepository {
private static final String ENDING = ".seednodes"; private static final String ENDING = ".seednodes";
private final Collection<NodeAddress> cache = new HashSet<>(); private final Collection<NodeAddress> cache = new HashSet<>();
private final Config config; private final Config config;
@Nullable
private final String seedNodes;
@Inject @Inject
public DefaultSeedNodeRepository(Config config, public DefaultSeedNodeRepository(Config config) {
@Nullable @Named(NetworkOptionKeys.SEED_NODES_KEY) String seedNodes) {
this.config = config; this.config = config;
this.seedNodes = seedNodes;
} }
private void reload() { private void reload() {
try { try {
// see if there are any seed nodes configured manually // see if there are any seed nodes configured manually
if (seedNodes != null && !seedNodes.isEmpty()) { if (!config.getSeedNodes().isEmpty()) {
cache.clear(); cache.clear();
Arrays.stream(seedNodes.split(",")).forEach(s -> cache.add(new NodeAddress(s))); config.getSeedNodes().forEach(s -> cache.add(new NodeAddress(s)));
return; return;
} }

View File

@ -19,16 +19,19 @@ package bisq.core.network.p2p.seed;
import bisq.network.p2p.NodeAddress; import bisq.network.p2p.NodeAddress;
import bisq.common.config.Config;
import bisq.common.config.TestConfig; import bisq.common.config.TestConfig;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import static java.lang.String.format;
public class DefaultSeedNodeRepositoryTest { public class DefaultSeedNodeRepositoryTest {
@Test @Test
public void getSeedNodes() { public void getSeedNodes() {
DefaultSeedNodeRepository DUT = new DefaultSeedNodeRepository(new TestConfig(), null); DefaultSeedNodeRepository DUT = new DefaultSeedNodeRepository(new TestConfig());
Assert.assertFalse(DUT.getSeedNodeAddresses().isEmpty()); Assert.assertFalse(DUT.getSeedNodeAddresses().isEmpty());
} }
@ -36,8 +39,8 @@ public class DefaultSeedNodeRepositoryTest {
public void manualSeedNodes() { public void manualSeedNodes() {
String seed1 = "asdf:8001"; String seed1 = "asdf:8001";
String seed2 = "fdsa:6001"; String seed2 = "fdsa:6001";
String seedNodes = seed1 + "," + seed2; String seedNodes = format("--%s=%s,%s", Config.SEED_NODES, seed1, seed2);
DefaultSeedNodeRepository DUT = new DefaultSeedNodeRepository(new TestConfig(), seedNodes); DefaultSeedNodeRepository DUT = new DefaultSeedNodeRepository(new TestConfig(seedNodes));
Assert.assertFalse(DUT.getSeedNodeAddresses().isEmpty()); Assert.assertFalse(DUT.getSeedNodeAddresses().isEmpty());
Assert.assertEquals(2, DUT.getSeedNodeAddresses().size()); Assert.assertEquals(2, DUT.getSeedNodeAddresses().size());
Assert.assertTrue(DUT.getSeedNodeAddresses().contains(new NodeAddress(seed1))); Assert.assertTrue(DUT.getSeedNodeAddresses().contains(new NodeAddress(seed1)));

View File

@ -135,7 +135,7 @@ public class P2PNetworkLoad extends Metric implements MessageListener, SetupList
NetworkProtoResolver networkProtoResolver = new CoreNetworkProtoResolver(Clock.systemDefaultZone()); NetworkProtoResolver networkProtoResolver = new CoreNetworkProtoResolver(Clock.systemDefaultZone());
CorePersistenceProtoResolver persistenceProtoResolver = new CorePersistenceProtoResolver(null, CorePersistenceProtoResolver persistenceProtoResolver = new CorePersistenceProtoResolver(null,
networkProtoResolver, storageDir, corruptedDatabaseFilesHandler); networkProtoResolver, storageDir, corruptedDatabaseFilesHandler);
DefaultSeedNodeRepository seedNodeRepository = new DefaultSeedNodeRepository(config, null); DefaultSeedNodeRepository seedNodeRepository = new DefaultSeedNodeRepository(config);
PeerManager peerManager = new PeerManager(networkNode, seedNodeRepository, new ClockWatcher(), PeerManager peerManager = new PeerManager(networkNode, seedNodeRepository, new ClockWatcher(),
maxConnections, new Storage<PeerList>(storageDir, persistenceProtoResolver, corruptedDatabaseFilesHandler)); maxConnections, new Storage<PeerList>(storageDir, persistenceProtoResolver, corruptedDatabaseFilesHandler));

View File

@ -22,7 +22,6 @@ public class NetworkOptionKeys {
public static final String MAX_CONNECTIONS = "maxConnections"; public static final String MAX_CONNECTIONS = "maxConnections";
public static final String PORT_KEY = "nodePort"; public static final String PORT_KEY = "nodePort";
public static final String NETWORK_ID = "networkId"; public static final String NETWORK_ID = "networkId";
public static final String SEED_NODES_KEY = "seedNodes";
public static final String BAN_LIST = "banList"; public static final String BAN_LIST = "banList";
//SOCKS_5_PROXY_BTC_ADDRESS used in network module so dont move it to BtcOptionKeys //SOCKS_5_PROXY_BTC_ADDRESS used in network module so dont move it to BtcOptionKeys
public static final String SOCKS_5_PROXY_BTC_ADDRESS = "socks5ProxyBtcAddress"; public static final String SOCKS_5_PROXY_BTC_ADDRESS = "socks5ProxyBtcAddress";

View File

@ -90,7 +90,6 @@ public class P2PModule extends AppModule {
Integer networkId = environment.getProperty(NetworkOptionKeys.NETWORK_ID, int.class, 1); Integer networkId = environment.getProperty(NetworkOptionKeys.NETWORK_ID, int.class, 1);
bind(int.class).annotatedWith(Names.named(NetworkOptionKeys.NETWORK_ID)).toInstance(networkId); bind(int.class).annotatedWith(Names.named(NetworkOptionKeys.NETWORK_ID)).toInstance(networkId);
bindConstant().annotatedWith(named(NetworkOptionKeys.SEED_NODES_KEY)).to(environment.getRequiredProperty(NetworkOptionKeys.SEED_NODES_KEY));
bindConstant().annotatedWith(named(NetworkOptionKeys.BAN_LIST)).to(environment.getRequiredProperty(NetworkOptionKeys.BAN_LIST)); bindConstant().annotatedWith(named(NetworkOptionKeys.BAN_LIST)).to(environment.getRequiredProperty(NetworkOptionKeys.BAN_LIST));
bindConstant().annotatedWith(named(NetworkOptionKeys.SOCKS_5_PROXY_BTC_ADDRESS)).to(environment.getRequiredProperty(NetworkOptionKeys.SOCKS_5_PROXY_BTC_ADDRESS)); bindConstant().annotatedWith(named(NetworkOptionKeys.SOCKS_5_PROXY_BTC_ADDRESS)).to(environment.getRequiredProperty(NetworkOptionKeys.SOCKS_5_PROXY_BTC_ADDRESS));
bindConstant().annotatedWith(named(NetworkOptionKeys.SOCKS_5_PROXY_HTTP_ADDRESS)).to(environment.getRequiredProperty(NetworkOptionKeys.SOCKS_5_PROXY_HTTP_ADDRESS)); bindConstant().annotatedWith(named(NetworkOptionKeys.SOCKS_5_PROXY_HTTP_ADDRESS)).to(environment.getRequiredProperty(NetworkOptionKeys.SOCKS_5_PROXY_HTTP_ADDRESS));