Add config file support for seednode selection, Fix resource loading bug with checkpoint file for mainnet

This commit is contained in:
Manfred Karrer 2014-09-29 03:01:01 +02:00
parent a5a04fe72c
commit ba3d04fed1
6 changed files with 57 additions and 31 deletions

View File

@ -17,8 +17,9 @@
# Supported properties:
# networkType=regtest
# networkType=testnet
# networkType=mainnet
# networkType=regtest | testnet | mainnet
networkType=regtest
# defaultSeedNode=localhost | server
networkType=regtest
defaultSeedNode=localhost

View File

@ -147,6 +147,7 @@ public class BitSquare extends Application {
primaryStage.show();
} catch (IOException e) {
e.printStackTrace();
log.error(e.getMessage());
}
}

View File

@ -163,7 +163,12 @@ public class WalletFacade {
// in the checkpoints file and then download the rest from the network. It makes things much faster.
// Checkpoint files are made using the BuildCheckpoints tool and usually we have to download the
// last months worth or more (takes a few seconds).
walletAppKit.setCheckpoints(getClass().getResourceAsStream("checkpoints"));
try {
walletAppKit.setCheckpoints(getClass().getClassLoader().getResourceAsStream("wallet/checkpoints"));
} catch (Exception e) {
e.printStackTrace();
log.error(e.toString());
}
// As an example!
// walletAppKit.useTor();
}
@ -181,9 +186,11 @@ public class WalletFacade {
wallet.allowSpendingUnconfirmedTransactions();
//walletAppKit.peerGroup().setMaxConnections(11);
if (params == RegTestParams.get()) {
if (params == RegTestParams.get())
walletAppKit.peerGroup().setMinBroadcastConnections(1);
}
else
walletAppKit.peerGroup().setMinBroadcastConnections(3);
walletEventListener = new WalletEventListener() {
@Override

View File

@ -48,19 +48,18 @@ import com.google.bitcoin.params.TestNet3Params;
import com.google.inject.AbstractModule;
import com.google.inject.Provider;
import com.google.inject.name.Named;
import com.google.inject.name.Names;
import java.util.Properties;
import javax.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class BitSquareModule extends AbstractModule {
private static final Logger log = LoggerFactory.getLogger(BitSquareModule.class);
static Properties properties;
@Override
protected void configure() {
bind(User.class).asEagerSingleton();
@ -88,40 +87,58 @@ public class BitSquareModule extends AbstractModule {
bind(InputValidator.class).asEagerSingleton();
bind(PasswordValidator.class).asEagerSingleton();
//bind(String.class).annotatedWith(Names.named("networkType")).toInstance(WalletFacade.MAIN_NET);
// how to use reg test see description in the readme file
bind(String.class).annotatedWith(Names.named("networkType")).toInstance(WalletFacade.REG_TEST_NET);
//bind(String.class).annotatedWith(Names.named("networkType")).toInstance(WalletFacade.TEST_NET);
bind(NetworkParameters.class).toProvider(NetworkParametersProvider.class).asEagerSingleton();
// we will probably later disc storage instead of memory storage for TomP2P
// bind(Boolean.class).annotatedWith(Names.named("useDiskStorage")).toInstance(true);
bind(Boolean.class).annotatedWith(Names.named("useDiskStorage")).toInstance(false);
// might be better in a config file?
bind(SeedNodeAddress.StaticSeedNodeAddresses.class).annotatedWith(
Names.named("defaultSeedNode")).toInstance(SeedNodeAddress.StaticSeedNodeAddresses.LOCALHOST);
// bind(SeedNodeAddress.StaticSeedNodeAddresses.class).annotatedWith(Names.named("defaultSeedNode"))
// .toInstance(SeedNodeAddress.StaticSeedNodeAddresses.DIGITAL_OCEAN);
bind(SeedNodeAddress.StaticSeedNodeAddresses.class).annotatedWith(Names.named("defaultSeedNode"))
.toProvider(StaticSeedNodeAddressesProvider.class).asEagerSingleton();
}
}
class StaticSeedNodeAddressesProvider implements Provider<SeedNodeAddress.StaticSeedNodeAddresses> {
private static final Logger log = LoggerFactory.getLogger(StaticSeedNodeAddressesProvider.class);
public SeedNodeAddress.StaticSeedNodeAddresses get() {
if (BitSquareModule.properties == null)
BitSquareModule.properties = ConfigLoader.loadConfig();
log.info("defaultSeedNode = " + BitSquareModule.properties.getProperty("defaultSeedNode"));
String defaultSeedNodeFromConfig = BitSquareModule.properties.getProperty("defaultSeedNode");
// Set default
SeedNodeAddress.StaticSeedNodeAddresses defaultSeedNode = SeedNodeAddress.StaticSeedNodeAddresses.LOCALHOST;
/* SeedNodeAddress.StaticSeedNodeAddresses defaultSeedNode = SeedNodeAddress.StaticSeedNodeAddresses
.DIGITAL_OCEAN;*/
// if defined in config we override the above
if (defaultSeedNodeFromConfig != null)
defaultSeedNode = defaultSeedNodeFromConfig.equals("localhost") ?
SeedNodeAddress.StaticSeedNodeAddresses.LOCALHOST :
SeedNodeAddress.StaticSeedNodeAddresses.DIGITAL_OCEAN;
return defaultSeedNode;
}
}
class NetworkParametersProvider implements Provider<NetworkParameters> {
private static final Logger log = LoggerFactory.getLogger(NetworkParametersProvider.class);
private String networkType;
@Inject
public NetworkParametersProvider(@Named("networkType") String networkType) {
this.networkType = networkType;
}
public NetworkParameters get() {
NetworkParameters result = null;
//If config is available we override the networkType defined in Guice with the one from the config file
Properties properties = ConfigLoader.loadConfig();
log.info("networkType = " + properties.getProperty("networkType"));
String networkTypeFromConfig = properties.getProperty("networkType");
if (BitSquareModule.properties == null)
BitSquareModule.properties = ConfigLoader.loadConfig();
log.info("networkType = " + BitSquareModule.properties.getProperty("networkType"));
String networkTypeFromConfig = BitSquareModule.properties.getProperty("networkType");
// Set default
// String networkType= WalletFacade.MAIN_NET;
// String networkType= WalletFacade.TEST_NET;
String networkType = WalletFacade.REG_TEST_NET;
if (networkTypeFromConfig != null)
networkType = networkTypeFromConfig;
@ -139,4 +156,4 @@ class NetworkParametersProvider implements Provider<NetworkParameters> {
}
return result;
}
}
}

View File

@ -532,7 +532,7 @@ public class MessageFacade implements MessageBroker {
}
else if (getFuture.data() == null) {
// OK as nothing is set at the moment
log.trace("Get invalidationTimestamp from DHT returns null. That is ok for the startup.");
// log.trace("Get invalidationTimestamp from DHT returns null. That is ok for the startup.");
}
else {
log.error("Get invalidationTimestamp from DHT failed with reason:" + getFuture.failedReason());

View File

@ -31,7 +31,7 @@ import lighthouse.files.AppDirectory;
public class ConfigLoader {
private static final Logger log = LoggerFactory.getLogger(ConfigLoader.class);
private static final String configFilePath = AppDirectory.dir() + "/bitsquare.config";
private static final String configFilePath = AppDirectory.dir() + "/bitsquare.conf";
public static Properties loadConfig() {
Properties properties = new Properties();