Move 'maxConnections' option handling to Config

This commit is contained in:
Chris Beams 2019-12-13 21:05:12 +01:00
parent 0e48a3ef2c
commit 8d6dbad484
No known key found for this signature in database
GPG Key ID: 3D214F8F5BC5ED73
7 changed files with 19 additions and 17 deletions

View File

@ -43,6 +43,7 @@ public class Config {
public static final String BAN_LIST = "banList";
public static final String NODE_PORT = "nodePort";
public static final String USE_LOCALHOST_FOR_P2P = "useLocalhostForP2P";
public static final String MAX_CONNECTIONS = "maxConnections";
static final String DEFAULT_CONFIG_FILE_NAME = "bisq.properties";
@ -80,6 +81,7 @@ public class Config {
private final List<String> seedNodes;
private final List<String> banList;
private final boolean useLocalhostForP2P;
private final int maxConnections;
// properties derived from cli options, but not exposed as cli options themselves
private boolean localBitcoinNodeIsRunning = false; // FIXME: eliminate mutable state
@ -269,6 +271,12 @@ public class Config {
.withRequiredArg()
.ofType(boolean.class)
.defaultsTo(false);
ArgumentAcceptingOptionSpec<Integer> maxConnectionsOpt =
parser.accepts(MAX_CONNECTIONS, "Max. connections a peer will try to keep")
.withRequiredArg()
.ofType(int.class)
.defaultsTo(12);
try {
OptionSet cliOpts = parser.parse(args);
@ -330,6 +338,7 @@ public class Config {
this.seedNodes = options.valuesOf(seedNodesOpt);
this.banList = options.valuesOf(banListOpt);
this.useLocalhostForP2P = options.valueOf(useLocalhostForP2POpt);
this.maxConnections = options.valueOf(maxConnectionsOpt);
} catch (OptionException ex) {
throw new ConfigException(format("problem parsing option '%s': %s",
ex.options().get(0),
@ -513,4 +522,8 @@ public class Config {
public boolean isUseLocalhostForP2P() {
return useLocalhostForP2P;
}
public int getMaxConnections() {
return maxConnections;
}
}

View File

@ -276,11 +276,6 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet
protected void customizeOptionParsing(OptionParser parser) {
//NetworkOptionKeys
parser.accepts(NetworkOptionKeys.MAX_CONNECTIONS,
format("Max. connections a peer will try to keep (default: %s)", P2PService.MAX_CONNECTIONS_DEFAULT))
.withRequiredArg()
.ofType(int.class);
parser.accepts(NetworkOptionKeys.SOCKS_5_PROXY_BTC_ADDRESS,
"A proxy address to be used for Bitcoin network.")
.withRequiredArg()

View File

@ -18,7 +18,6 @@
package bisq.network;
public class NetworkOptionKeys {
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
public static final String SOCKS_5_PROXY_BTC_ADDRESS = "socks5ProxyBtcAddress";

View File

@ -49,10 +49,7 @@ import java.io.File;
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 bisq.common.config.Config.*;
import static com.google.inject.name.Names.named;
public class P2PModule extends AppModule {
@ -88,8 +85,7 @@ public class P2PModule extends AppModule {
bind(int.class).annotatedWith(Names.named(NODE_PORT)).toInstance(config.getNodePort());
Integer maxConnections = environment.getProperty(NetworkOptionKeys.MAX_CONNECTIONS, int.class, P2PService.MAX_CONNECTIONS_DEFAULT);
bind(int.class).annotatedWith(Names.named(NetworkOptionKeys.MAX_CONNECTIONS)).toInstance(maxConnections);
bindConstant().annotatedWith(named(MAX_CONNECTIONS)).to(config.getMaxConnections());
Integer networkId = environment.getProperty(NetworkOptionKeys.NETWORK_ID, int.class, 1);
bind(int.class).annotatedWith(Names.named(NetworkOptionKeys.NETWORK_ID)).toInstance(networkId);

View File

@ -98,7 +98,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
public class P2PService implements SetupListener, MessageListener, ConnectionListener, RequestDataManager.Listener,
HashMapChangedListener, PersistedDataHost {
private static final Logger log = LoggerFactory.getLogger(P2PService.class);
public static final int MAX_CONNECTIONS_DEFAULT = 12;
private final SeedNodeRepository seedNodeRepository;
private final EncryptionService encryptionService;

View File

@ -17,7 +17,6 @@
package bisq.network.p2p.peers;
import bisq.network.NetworkOptionKeys;
import bisq.network.p2p.NodeAddress;
import bisq.network.p2p.network.CloseConnectionReason;
import bisq.network.p2p.network.Connection;
@ -33,6 +32,7 @@ import bisq.common.ClockWatcher;
import bisq.common.Timer;
import bisq.common.UserThread;
import bisq.common.app.Capabilities;
import bisq.common.config.Config;
import bisq.common.proto.persistable.PersistedDataHost;
import bisq.common.storage.Storage;
@ -131,7 +131,7 @@ public class PeerManager implements ConnectionListener, PersistedDataHost {
public PeerManager(NetworkNode networkNode,
SeedNodeRepository seedNodeRepository,
ClockWatcher clockWatcher,
@Named(NetworkOptionKeys.MAX_CONNECTIONS) int maxConnections,
@Named(Config.MAX_CONNECTIONS) int maxConnections,
Storage<PeerList> storage) {
this.networkNode = networkNode;
this.seedNodeAddresses = new HashSet<>(seedNodeRepository.getSeedNodeAddresses());

View File

@ -106,8 +106,8 @@ public class DummySeedNode {
checkArgument(networkId > -1 && networkId < 3,
"networkId out of scope (Mainnet = 0, TestNet = 1, Regtest = 2)");
Version.setBaseCryptoNetworkId(networkId);
} else if (arg.startsWith(NetworkOptionKeys.MAX_CONNECTIONS)) {
arg = arg.substring(NetworkOptionKeys.MAX_CONNECTIONS.length() + 1);
} else if (arg.startsWith(Config.MAX_CONNECTIONS)) {
arg = arg.substring(Config.MAX_CONNECTIONS.length() + 1);
maxConnections = Integer.parseInt(arg);
log.debug("From processArgs: maxConnections=" + maxConnections);
checkArgument(maxConnections < MAX_CONNECTIONS_LIMIT, "maxConnections seems to be a bit too high...");