mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-06-20 12:54:37 -04:00
Add config file support for seednode selection, Fix resource loading bug with checkpoint file for mainnet
This commit is contained in:
parent
a5a04fe72c
commit
ba3d04fed1
6 changed files with 57 additions and 31 deletions
|
@ -17,8 +17,9 @@
|
||||||
|
|
||||||
|
|
||||||
# Supported properties:
|
# Supported properties:
|
||||||
# networkType=regtest
|
# networkType=regtest | testnet | mainnet
|
||||||
# networkType=testnet
|
|
||||||
# networkType=mainnet
|
# defaultSeedNode=localhost | server
|
||||||
|
|
||||||
networkType=regtest
|
networkType=regtest
|
||||||
|
defaultSeedNode=localhost
|
|
@ -147,6 +147,7 @@ public class BitSquare extends Application {
|
||||||
|
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
log.error(e.getMessage());
|
log.error(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,7 +163,12 @@ public class WalletFacade {
|
||||||
// in the checkpoints file and then download the rest from the network. It makes things much faster.
|
// 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
|
// Checkpoint files are made using the BuildCheckpoints tool and usually we have to download the
|
||||||
// last months worth or more (takes a few seconds).
|
// 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!
|
// As an example!
|
||||||
// walletAppKit.useTor();
|
// walletAppKit.useTor();
|
||||||
}
|
}
|
||||||
|
@ -181,9 +186,11 @@ public class WalletFacade {
|
||||||
wallet.allowSpendingUnconfirmedTransactions();
|
wallet.allowSpendingUnconfirmedTransactions();
|
||||||
//walletAppKit.peerGroup().setMaxConnections(11);
|
//walletAppKit.peerGroup().setMaxConnections(11);
|
||||||
|
|
||||||
if (params == RegTestParams.get()) {
|
if (params == RegTestParams.get())
|
||||||
walletAppKit.peerGroup().setMinBroadcastConnections(1);
|
walletAppKit.peerGroup().setMinBroadcastConnections(1);
|
||||||
}
|
else
|
||||||
|
walletAppKit.peerGroup().setMinBroadcastConnections(3);
|
||||||
|
|
||||||
|
|
||||||
walletEventListener = new WalletEventListener() {
|
walletEventListener = new WalletEventListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -48,19 +48,18 @@ import com.google.bitcoin.params.TestNet3Params;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
import com.google.inject.name.Named;
|
|
||||||
import com.google.inject.name.Names;
|
import com.google.inject.name.Names;
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class BitSquareModule extends AbstractModule {
|
public class BitSquareModule extends AbstractModule {
|
||||||
private static final Logger log = LoggerFactory.getLogger(BitSquareModule.class);
|
private static final Logger log = LoggerFactory.getLogger(BitSquareModule.class);
|
||||||
|
|
||||||
|
static Properties properties;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(User.class).asEagerSingleton();
|
bind(User.class).asEagerSingleton();
|
||||||
|
@ -88,40 +87,58 @@ public class BitSquareModule extends AbstractModule {
|
||||||
bind(InputValidator.class).asEagerSingleton();
|
bind(InputValidator.class).asEagerSingleton();
|
||||||
bind(PasswordValidator.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();
|
bind(NetworkParameters.class).toProvider(NetworkParametersProvider.class).asEagerSingleton();
|
||||||
|
|
||||||
// we will probably later disc storage instead of memory storage for TomP2P
|
// 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(true);
|
||||||
bind(Boolean.class).annotatedWith(Names.named("useDiskStorage")).toInstance(false);
|
bind(Boolean.class).annotatedWith(Names.named("useDiskStorage")).toInstance(false);
|
||||||
|
|
||||||
// might be better in a config file?
|
bind(SeedNodeAddress.StaticSeedNodeAddresses.class).annotatedWith(Names.named("defaultSeedNode"))
|
||||||
bind(SeedNodeAddress.StaticSeedNodeAddresses.class).annotatedWith(
|
.toProvider(StaticSeedNodeAddressesProvider.class).asEagerSingleton();
|
||||||
Names.named("defaultSeedNode")).toInstance(SeedNodeAddress.StaticSeedNodeAddresses.LOCALHOST);
|
}
|
||||||
// bind(SeedNodeAddress.StaticSeedNodeAddresses.class).annotatedWith(Names.named("defaultSeedNode"))
|
}
|
||||||
// .toInstance(SeedNodeAddress.StaticSeedNodeAddresses.DIGITAL_OCEAN);
|
|
||||||
|
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> {
|
class NetworkParametersProvider implements Provider<NetworkParameters> {
|
||||||
private static final Logger log = LoggerFactory.getLogger(NetworkParametersProvider.class);
|
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() {
|
public NetworkParameters get() {
|
||||||
NetworkParameters result = null;
|
NetworkParameters result = null;
|
||||||
|
|
||||||
//If config is available we override the networkType defined in Guice with the one from the config file
|
//If config is available we override the networkType defined in Guice with the one from the config file
|
||||||
Properties properties = ConfigLoader.loadConfig();
|
if (BitSquareModule.properties == null)
|
||||||
log.info("networkType = " + properties.getProperty("networkType"));
|
BitSquareModule.properties = ConfigLoader.loadConfig();
|
||||||
String networkTypeFromConfig = properties.getProperty("networkType");
|
|
||||||
|
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)
|
if (networkTypeFromConfig != null)
|
||||||
networkType = networkTypeFromConfig;
|
networkType = networkTypeFromConfig;
|
||||||
|
|
|
@ -532,7 +532,7 @@ public class MessageFacade implements MessageBroker {
|
||||||
}
|
}
|
||||||
else if (getFuture.data() == null) {
|
else if (getFuture.data() == null) {
|
||||||
// OK as nothing is set at the moment
|
// 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 {
|
else {
|
||||||
log.error("Get invalidationTimestamp from DHT failed with reason:" + getFuture.failedReason());
|
log.error("Get invalidationTimestamp from DHT failed with reason:" + getFuture.failedReason());
|
||||||
|
|
|
@ -31,7 +31,7 @@ import lighthouse.files.AppDirectory;
|
||||||
|
|
||||||
public class ConfigLoader {
|
public class ConfigLoader {
|
||||||
private static final Logger log = LoggerFactory.getLogger(ConfigLoader.class);
|
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() {
|
public static Properties loadConfig() {
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue