mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Move 'seedNode' option handling to Config
And eliminate @Named injection in favor of calling config.getSeedNodes()
This commit is contained in:
parent
7be2ff19f8
commit
e118165e9a
@ -39,6 +39,7 @@ public class Config {
|
||||
public static final String IGNORE_DEV_MSG = "ignoreDevMsg";
|
||||
public static final String PROVIDERS = "providers";
|
||||
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 int DEFAULT_NODE_PORT = 9999;
|
||||
@ -74,6 +75,7 @@ public class Config {
|
||||
private final int maxMemory;
|
||||
private final boolean ignoreDevMsg;
|
||||
private final List<String> providers;
|
||||
private final List<String> seedNodes;
|
||||
|
||||
// properties derived from cli options, but not exposed as cli options themselves
|
||||
private boolean localBitcoinNodeIsRunning = false; // FIXME: eliminate mutable state
|
||||
@ -244,6 +246,14 @@ public class Config {
|
||||
.withRequiredArg()
|
||||
.withValuesSeparatedBy(',')
|
||||
.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 {
|
||||
OptionSet cliOpts = parser.parse(args);
|
||||
|
||||
@ -302,6 +312,7 @@ public class Config {
|
||||
this.maxMemory = options.valueOf(maxMemoryOpt);
|
||||
this.ignoreDevMsg = options.valueOf(ignoreDevMsgOpt);
|
||||
this.providers = options.valuesOf(providersOpt);
|
||||
this.seedNodes = options.valuesOf(seedNodesOpt);
|
||||
} catch (OptionException ex) {
|
||||
throw new ConfigException(format("problem parsing option '%s': %s",
|
||||
ex.options().get(0),
|
||||
@ -473,4 +484,8 @@ public class Config {
|
||||
public List<String> getProviders() {
|
||||
return providers;
|
||||
}
|
||||
|
||||
public List<String> getSeedNodes() {
|
||||
return seedNodes;
|
||||
}
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ public class BisqEnvironment extends StandardEnvironment {
|
||||
@Setter
|
||||
protected boolean isBitcoinLocalhostNodeRunning;
|
||||
|
||||
protected final String btcNodes, seedNodes, useTorForBtc, rpcUser, rpcPassword,
|
||||
protected final String btcNodes, useTorForBtc, rpcUser, rpcPassword,
|
||||
rpcHost, rpcPort, rpcBlockNotificationPort, rpcBlockNotificationHost, dumpBlockchainData, fullDaoNode,
|
||||
banList, socks5ProxyBtcAddress,
|
||||
torRcFile, torRcOptions, externalTorControlPort, externalTorPassword, externalTorCookieFile,
|
||||
@ -83,7 +83,6 @@ public class BisqEnvironment extends StandardEnvironment {
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public BisqEnvironment(PropertySource commandLineProperties) {
|
||||
//NetworkOptionKeys
|
||||
seedNodes = getProperty(commandLineProperties, NetworkOptionKeys.SEED_NODES_KEY, "");
|
||||
banList = getProperty(commandLineProperties, NetworkOptionKeys.BAN_LIST, "");
|
||||
socks5ProxyBtcAddress = getProperty(commandLineProperties, NetworkOptionKeys.SOCKS_5_PROXY_BTC_ADDRESS, "");
|
||||
socks5ProxyHttpAddress = getProperty(commandLineProperties, NetworkOptionKeys.SOCKS_5_PROXY_HTTP_ADDRESS, "");
|
||||
@ -140,7 +139,6 @@ public class BisqEnvironment extends StandardEnvironment {
|
||||
private PropertySource<?> defaultProperties() {
|
||||
return new PropertiesPropertySource(BISQ_DEFAULT_PROPERTY_SOURCE_NAME, new Properties() {
|
||||
{
|
||||
setProperty(NetworkOptionKeys.SEED_NODES_KEY, seedNodes);
|
||||
setProperty(NetworkOptionKeys.BAN_LIST, banList);
|
||||
setProperty(NetworkOptionKeys.NETWORK_ID, String.valueOf(BaseCurrencyNetwork.CURRENT_NETWORK.ordinal()));
|
||||
setProperty(NetworkOptionKeys.SOCKS_5_PROXY_BTC_ADDRESS, socks5ProxyBtcAddress);
|
||||
|
@ -276,12 +276,6 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet
|
||||
|
||||
protected void customizeOptionParsing(OptionParser parser) {
|
||||
//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,
|
||||
"Nodes to exclude from network connections.")
|
||||
.withRequiredArg()
|
||||
|
@ -17,21 +17,18 @@
|
||||
|
||||
package bisq.core.network.p2p.seed;
|
||||
|
||||
import bisq.network.NetworkOptionKeys;
|
||||
import bisq.network.p2p.NodeAddress;
|
||||
import bisq.network.p2p.seed.SeedNodeRepository;
|
||||
|
||||
import bisq.common.config.Config;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.regex.Matcher;
|
||||
@ -40,8 +37,6 @@ import java.util.stream.Collectors;
|
||||
|
||||
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!
|
||||
@Slf4j
|
||||
@Singleton
|
||||
@ -51,22 +46,18 @@ public class DefaultSeedNodeRepository implements SeedNodeRepository {
|
||||
private static final String ENDING = ".seednodes";
|
||||
private final Collection<NodeAddress> cache = new HashSet<>();
|
||||
private final Config config;
|
||||
@Nullable
|
||||
private final String seedNodes;
|
||||
|
||||
@Inject
|
||||
public DefaultSeedNodeRepository(Config config,
|
||||
@Nullable @Named(NetworkOptionKeys.SEED_NODES_KEY) String seedNodes) {
|
||||
public DefaultSeedNodeRepository(Config config) {
|
||||
this.config = config;
|
||||
this.seedNodes = seedNodes;
|
||||
}
|
||||
|
||||
private void reload() {
|
||||
try {
|
||||
// see if there are any seed nodes configured manually
|
||||
if (seedNodes != null && !seedNodes.isEmpty()) {
|
||||
if (!config.getSeedNodes().isEmpty()) {
|
||||
cache.clear();
|
||||
Arrays.stream(seedNodes.split(",")).forEach(s -> cache.add(new NodeAddress(s)));
|
||||
config.getSeedNodes().forEach(s -> cache.add(new NodeAddress(s)));
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -19,16 +19,19 @@ package bisq.core.network.p2p.seed;
|
||||
|
||||
import bisq.network.p2p.NodeAddress;
|
||||
|
||||
import bisq.common.config.Config;
|
||||
import bisq.common.config.TestConfig;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static java.lang.String.format;
|
||||
|
||||
public class DefaultSeedNodeRepositoryTest {
|
||||
|
||||
@Test
|
||||
public void getSeedNodes() {
|
||||
DefaultSeedNodeRepository DUT = new DefaultSeedNodeRepository(new TestConfig(), null);
|
||||
DefaultSeedNodeRepository DUT = new DefaultSeedNodeRepository(new TestConfig());
|
||||
Assert.assertFalse(DUT.getSeedNodeAddresses().isEmpty());
|
||||
}
|
||||
|
||||
@ -36,8 +39,8 @@ public class DefaultSeedNodeRepositoryTest {
|
||||
public void manualSeedNodes() {
|
||||
String seed1 = "asdf:8001";
|
||||
String seed2 = "fdsa:6001";
|
||||
String seedNodes = seed1 + "," + seed2;
|
||||
DefaultSeedNodeRepository DUT = new DefaultSeedNodeRepository(new TestConfig(), seedNodes);
|
||||
String seedNodes = format("--%s=%s,%s", Config.SEED_NODES, seed1, seed2);
|
||||
DefaultSeedNodeRepository DUT = new DefaultSeedNodeRepository(new TestConfig(seedNodes));
|
||||
Assert.assertFalse(DUT.getSeedNodeAddresses().isEmpty());
|
||||
Assert.assertEquals(2, DUT.getSeedNodeAddresses().size());
|
||||
Assert.assertTrue(DUT.getSeedNodeAddresses().contains(new NodeAddress(seed1)));
|
||||
|
@ -135,7 +135,7 @@ public class P2PNetworkLoad extends Metric implements MessageListener, SetupList
|
||||
NetworkProtoResolver networkProtoResolver = new CoreNetworkProtoResolver(Clock.systemDefaultZone());
|
||||
CorePersistenceProtoResolver persistenceProtoResolver = new CorePersistenceProtoResolver(null,
|
||||
networkProtoResolver, storageDir, corruptedDatabaseFilesHandler);
|
||||
DefaultSeedNodeRepository seedNodeRepository = new DefaultSeedNodeRepository(config, null);
|
||||
DefaultSeedNodeRepository seedNodeRepository = new DefaultSeedNodeRepository(config);
|
||||
PeerManager peerManager = new PeerManager(networkNode, seedNodeRepository, new ClockWatcher(),
|
||||
maxConnections, new Storage<PeerList>(storageDir, persistenceProtoResolver, corruptedDatabaseFilesHandler));
|
||||
|
||||
|
@ -22,7 +22,6 @@ public class NetworkOptionKeys {
|
||||
public static final String MAX_CONNECTIONS = "maxConnections";
|
||||
public static final String PORT_KEY = "nodePort";
|
||||
public static final String NETWORK_ID = "networkId";
|
||||
public static final String SEED_NODES_KEY = "seedNodes";
|
||||
public static final String BAN_LIST = "banList";
|
||||
//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";
|
||||
|
@ -90,7 +90,6 @@ public class P2PModule extends AppModule {
|
||||
|
||||
Integer networkId = environment.getProperty(NetworkOptionKeys.NETWORK_ID, int.class, 1);
|
||||
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.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));
|
||||
|
Loading…
Reference in New Issue
Block a user