diff --git a/doc/bitsquare.config b/doc/bitsquare.conf similarity index 81% rename from doc/bitsquare.config rename to doc/bitsquare.conf index 1efd45eb5c..0f15d3e90e 100644 --- a/doc/bitsquare.config +++ b/doc/bitsquare.conf @@ -17,8 +17,9 @@ # Supported properties: -# networkType=regtest -# networkType=testnet -# networkType=mainnet +# networkType=regtest | testnet | mainnet -networkType=regtest \ No newline at end of file +# defaultSeedNode=localhost | server + +networkType=regtest +defaultSeedNode=localhost \ No newline at end of file diff --git a/src/main/java/io/bitsquare/BitSquare.java b/src/main/java/io/bitsquare/BitSquare.java index d3188af218..c3c807cd9c 100644 --- a/src/main/java/io/bitsquare/BitSquare.java +++ b/src/main/java/io/bitsquare/BitSquare.java @@ -147,6 +147,7 @@ public class BitSquare extends Application { primaryStage.show(); } catch (IOException e) { + e.printStackTrace(); log.error(e.getMessage()); } } diff --git a/src/main/java/io/bitsquare/btc/WalletFacade.java b/src/main/java/io/bitsquare/btc/WalletFacade.java index f648a586b5..2380fb1250 100644 --- a/src/main/java/io/bitsquare/btc/WalletFacade.java +++ b/src/main/java/io/bitsquare/btc/WalletFacade.java @@ -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 diff --git a/src/main/java/io/bitsquare/di/BitSquareModule.java b/src/main/java/io/bitsquare/di/BitSquareModule.java index e1fc27461c..ccd22f2a8a 100644 --- a/src/main/java/io/bitsquare/di/BitSquareModule.java +++ b/src/main/java/io/bitsquare/di/BitSquareModule.java @@ -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 { + 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 { 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 { } return result; } -} +} \ No newline at end of file diff --git a/src/main/java/io/bitsquare/msg/MessageFacade.java b/src/main/java/io/bitsquare/msg/MessageFacade.java index d962edf68f..8b795aa9d0 100644 --- a/src/main/java/io/bitsquare/msg/MessageFacade.java +++ b/src/main/java/io/bitsquare/msg/MessageFacade.java @@ -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()); diff --git a/src/main/java/io/bitsquare/util/ConfigLoader.java b/src/main/java/io/bitsquare/util/ConfigLoader.java index de5eb1cb75..a4cc284790 100644 --- a/src/main/java/io/bitsquare/util/ConfigLoader.java +++ b/src/main/java/io/bitsquare/util/ConfigLoader.java @@ -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();