mirror of
https://github.com/bisq-network/bisq.git
synced 2025-03-13 11:09:10 +01:00
Added command line arguments parser and flag to start app in seed mode. Also added default properties loader, but not using it yet.
This commit is contained in:
parent
d19be95a75
commit
47232eebc2
11 changed files with 165 additions and 73 deletions
9
.idea/copyright/Bitsquare_Affero_GPLv3.xml
generated
9
.idea/copyright/Bitsquare_Affero_GPLv3.xml
generated
|
@ -1,9 +0,0 @@
|
||||||
<component name="CopyrightManager">
|
|
||||||
<copyright>
|
|
||||||
<option name="notice" value="This file is part of Bitsquare. Bitsquare is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Bitsquare is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with Bitsquare. If not, see <http://www.gnu.org/licenses/>." />
|
|
||||||
<option name="keyword" value="GNU Affero General Public License" />
|
|
||||||
<option name="allowReplaceKeyword" value="" />
|
|
||||||
<option name="myName" value="Bitsquare Affero GPLv3" />
|
|
||||||
<option name="myLocal" value="true" />
|
|
||||||
</copyright>
|
|
||||||
</component>
|
|
2
.idea/copyright/profiles_settings.xml
generated
2
.idea/copyright/profiles_settings.xml
generated
|
@ -1,3 +1,3 @@
|
||||||
<component name="CopyrightManager">
|
<component name="CopyrightManager">
|
||||||
<settings default="Bitsquare Affero GPLv3" />
|
<settings default="" />
|
||||||
</component>
|
</component>
|
|
@ -43,6 +43,7 @@ dependencies {
|
||||||
compile 'com.google.code.findbugs:jsr305:2.0.3'
|
compile 'com.google.code.findbugs:jsr305:2.0.3'
|
||||||
compile 'net.jcip:jcip-annotations:1.0'
|
compile 'net.jcip:jcip-annotations:1.0'
|
||||||
compile 'org.jetbrains:annotations:13.0'
|
compile 'org.jetbrains:annotations:13.0'
|
||||||
|
compile 'net.sourceforge.argparse4j:argparse4j:0.4.4'
|
||||||
testCompile 'junit:junit:4.11'
|
testCompile 'junit:junit:4.11'
|
||||||
testCompile 'org.mockito:mockito-all:1.9.5'
|
testCompile 'org.mockito:mockito-all:1.9.5'
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,11 +24,13 @@ import io.bitsquare.gui.Navigation;
|
||||||
import io.bitsquare.gui.components.Popups;
|
import io.bitsquare.gui.components.Popups;
|
||||||
import io.bitsquare.gui.util.ImageUtil;
|
import io.bitsquare.gui.util.ImageUtil;
|
||||||
import io.bitsquare.gui.util.Profiler;
|
import io.bitsquare.gui.util.Profiler;
|
||||||
|
import io.bitsquare.msg.DHTSeedService;
|
||||||
import io.bitsquare.msg.MessageFacade;
|
import io.bitsquare.msg.MessageFacade;
|
||||||
import io.bitsquare.msg.SeedNodeAddress;
|
import io.bitsquare.msg.actor.event.PeerInitialized;
|
||||||
import io.bitsquare.persistence.Persistence;
|
import io.bitsquare.persistence.Persistence;
|
||||||
import io.bitsquare.settings.Settings;
|
import io.bitsquare.settings.Settings;
|
||||||
import io.bitsquare.user.User;
|
import io.bitsquare.user.User;
|
||||||
|
import io.bitsquare.util.BitsquareArgumentParser;
|
||||||
import io.bitsquare.util.ViewLoader;
|
import io.bitsquare.util.ViewLoader;
|
||||||
|
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
|
@ -39,7 +41,6 @@ import com.google.inject.Injector;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
import javafx.scene.*;
|
import javafx.scene.*;
|
||||||
|
@ -52,6 +53,8 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import akka.actor.ActorSystem;
|
import akka.actor.ActorSystem;
|
||||||
import lighthouse.files.AppDirectory;
|
import lighthouse.files.AppDirectory;
|
||||||
|
import net.sourceforge.argparse4j.inf.ArgumentParserException;
|
||||||
|
import net.sourceforge.argparse4j.inf.Namespace;
|
||||||
|
|
||||||
public class BitSquare extends Application {
|
public class BitSquare extends Application {
|
||||||
private static final Logger log = LoggerFactory.getLogger(BitSquare.class);
|
private static final Logger log = LoggerFactory.getLogger(BitSquare.class);
|
||||||
|
@ -59,6 +62,7 @@ public class BitSquare extends Application {
|
||||||
public static final boolean fillFormsWithDummyData = true;
|
public static final boolean fillFormsWithDummyData = true;
|
||||||
|
|
||||||
private static String APP_NAME = "Bitsquare";
|
private static String APP_NAME = "Bitsquare";
|
||||||
|
private static Injector injector;
|
||||||
private static Stage primaryStage;
|
private static Stage primaryStage;
|
||||||
private WalletFacade walletFacade;
|
private WalletFacade walletFacade;
|
||||||
private MessageFacade messageFacade;
|
private MessageFacade messageFacade;
|
||||||
|
@ -67,37 +71,68 @@ public class BitSquare extends Application {
|
||||||
Profiler.init();
|
Profiler.init();
|
||||||
Profiler.printMsgWithTime("BitSquare.main called with args " + Arrays.asList(args).toString());
|
Profiler.printMsgWithTime("BitSquare.main called with args " + Arrays.asList(args).toString());
|
||||||
|
|
||||||
if (args.length > 0)
|
injector = Guice.createInjector(new BitSquareModule());
|
||||||
APP_NAME = APP_NAME + "-" + args[0];
|
|
||||||
|
|
||||||
/*Thread seedNodeThread = new Thread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
startSeedNode();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
seedNodeThread.start();*/
|
|
||||||
|
|
||||||
launch(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void startSeedNode() {
|
|
||||||
List<SeedNodeAddress.StaticSeedNodeAddresses> staticSedNodeAddresses = SeedNodeAddress
|
|
||||||
.StaticSeedNodeAddresses.getAllSeedNodeAddresses();
|
|
||||||
SeedNode seedNode = new SeedNode(new SeedNodeAddress(staticSedNodeAddresses.get(0)));
|
|
||||||
seedNode.setDaemon(true);
|
|
||||||
seedNode.start();
|
|
||||||
|
|
||||||
|
BitsquareArgumentParser parser = new BitsquareArgumentParser();
|
||||||
|
Namespace namespace = null;
|
||||||
try {
|
try {
|
||||||
// keep main thread up
|
//System.out.println(parser.parseArgs(args));
|
||||||
Thread.sleep(Long.MAX_VALUE);
|
namespace = parser.parseArgs(args);
|
||||||
log.debug("Localhost seed node started");
|
} catch (ArgumentParserException e) {
|
||||||
} catch (InterruptedException e) {
|
parser.handleError(e);
|
||||||
log.error(e.toString());
|
System.exit(1);
|
||||||
|
}
|
||||||
|
if (namespace != null) {
|
||||||
|
|
||||||
|
if (namespace.getString(BitsquareArgumentParser.NAME_FLAG) != null) {
|
||||||
|
APP_NAME = APP_NAME + "-" + namespace.getString(BitsquareArgumentParser.NAME_FLAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer port = BitsquareArgumentParser.PORT_DEFAULT;
|
||||||
|
if (namespace.getString(BitsquareArgumentParser.PORT_FLAG) != null) {
|
||||||
|
port = Integer.valueOf(namespace.getString(BitsquareArgumentParser.PORT_FLAG));
|
||||||
|
}
|
||||||
|
if (namespace.getBoolean(BitsquareArgumentParser.SEED_FLAG) == true) {
|
||||||
|
DHTSeedService dhtSeed = injector.getInstance(DHTSeedService.class);
|
||||||
|
dhtSeed.setHandler(m -> {
|
||||||
|
if (m instanceof PeerInitialized) {
|
||||||
|
System.out.println("Seed Peer Initialized on port " + ((PeerInitialized) m).getPort
|
||||||
|
());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dhtSeed.initializePeer("localhost", port);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
launch(args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Thread seedNodeThread = new Thread(new Runnable() {
|
||||||
|
// @Override
|
||||||
|
// public void run() {
|
||||||
|
// startSeedNode();
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// seedNodeThread.start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// private static void startSeedNode() {
|
||||||
|
// List<SeedNodeAddress.StaticSeedNodeAddresses> staticSedNodeAddresses = SeedNodeAddress
|
||||||
|
// .StaticSeedNodeAddresses.getAllSeedNodeAddresses();
|
||||||
|
// SeedNode seedNode = new SeedNode(new SeedNodeAddress(staticSedNodeAddresses.get(0)));
|
||||||
|
// seedNode.setDaemon(true);
|
||||||
|
// seedNode.start();
|
||||||
|
//
|
||||||
|
// try {
|
||||||
|
// // keep main thread up
|
||||||
|
// Thread.sleep(Long.MAX_VALUE);
|
||||||
|
// log.debug("Localhost seed node started");
|
||||||
|
// } catch (InterruptedException e) {
|
||||||
|
// log.error(e.toString());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
public static Stage getPrimaryStage() {
|
public static Stage getPrimaryStage() {
|
||||||
return primaryStage;
|
return primaryStage;
|
||||||
|
@ -121,7 +156,7 @@ public class BitSquare extends Application {
|
||||||
log.error(e.getMessage());
|
log.error(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
final Injector injector = Guice.createInjector(new BitSquareModule());
|
// final Injector injector = Guice.createInjector(new BitSquareModule());
|
||||||
|
|
||||||
// currently there is not SystemTray support for java fx (planned for version 3) so we use the old AWT
|
// currently there is not SystemTray support for java fx (planned for version 3) so we use the old AWT
|
||||||
AWTSystemTray.createSystemTray(primaryStage, injector.getInstance(ActorSystem.class));
|
AWTSystemTray.createSystemTray(primaryStage, injector.getInstance(ActorSystem.class));
|
||||||
|
|
|
@ -104,27 +104,6 @@ class MainModel extends UIModel {
|
||||||
|
|
||||||
// For testing with the serverside seednode we need the BootstrappedPeerFactory which gets started form
|
// For testing with the serverside seednode we need the BootstrappedPeerFactory which gets started form
|
||||||
// messageFacade.init
|
// messageFacade.init
|
||||||
|
|
||||||
/*dhtSeedService.setHandler(m -> {
|
|
||||||
if (m instanceof PeerInitialized) {
|
|
||||||
log.debug("dht seed initialized. ");
|
|
||||||
// init messageFacade after seed node initialized
|
|
||||||
messageFacade.init(new BootstrapListener() {
|
|
||||||
@Override
|
|
||||||
public void onCompleted() {
|
|
||||||
messageFacadeInited = true;
|
|
||||||
if (walletFacadeInited) onFacadesInitialised();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailed(Throwable throwable) {
|
|
||||||
log.error(throwable.toString());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
dhtSeedService.initializePeer();*/
|
|
||||||
|
|
||||||
messageFacade.init(new BootstrapListener() {
|
messageFacade.init(new BootstrapListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -39,9 +39,9 @@ public class DHTSeedService extends ActorService {
|
||||||
super(system, "/user/" + DHTManager.SEED_NAME);
|
super(system, "/user/" + DHTManager.SEED_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initializePeer() {
|
public void initializePeer(String id, Integer port) {
|
||||||
|
|
||||||
// TODO hard coded seed peer config for now, should read from config properties file
|
// TODO hard coded seed peer config for now, should read from config properties file
|
||||||
send(new InitializePeer(new Number160(5001), 5001, null));
|
send(new InitializePeer(Number160.createHash(id), port, null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,12 +67,11 @@ public class DHTManager extends AbstractActor {
|
||||||
.StaticSeedNodeAddresses.getAllSeedNodeAddresses();
|
.StaticSeedNodeAddresses.getAllSeedNodeAddresses();
|
||||||
SeedNodeAddress seedNodeAddress = new SeedNodeAddress(staticSedNodeAddresses.get(0));
|
SeedNodeAddress seedNodeAddress = new SeedNodeAddress(staticSedNodeAddresses.get(0));
|
||||||
|
|
||||||
peer = new PeerBuilder(
|
peer = new PeerBuilder(ip.getPeerId()).ports(ip.getPort())
|
||||||
Number160.createHash(seedNodeAddress.getId())).ports(seedNodeAddress.getPort
|
.start();
|
||||||
()).start();
|
|
||||||
|
|
||||||
// Need to add all features the clients will use (otherwise msg type is UNKNOWN_ID)
|
// Need to add all features the clients will use (otherwise msg type is UNKNOWN_ID)
|
||||||
new PeerBuilderDHT(peer).start();
|
peerDHT = new PeerBuilderDHT(peer).start();
|
||||||
PeerNAT nodeBehindNat = new PeerBuilderNAT(peer).start();
|
PeerNAT nodeBehindNat = new PeerBuilderNAT(peer).start();
|
||||||
new RelayRPC(peer);
|
new RelayRPC(peer);
|
||||||
//new PeerBuilderTracker(peer);
|
//new PeerBuilderTracker(peer);
|
||||||
|
@ -92,11 +91,11 @@ public class DHTManager extends AbstractActor {
|
||||||
.bootstrapTo(ip.getBootstrapPeers()).start();
|
.bootstrapTo(ip.getBootstrapPeers()).start();
|
||||||
futureBootstrap.awaitUninterruptibly(bootstrapTimeout);
|
futureBootstrap.awaitUninterruptibly(bootstrapTimeout);
|
||||||
}*/
|
}*/
|
||||||
sender().tell(new PeerInitialized(peer.peerID()), self());
|
sender().tell(new PeerInitialized(peer.peerID(), ip.getPort()), self());
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
log.info("The second instance has been started. If that happens at the first instance" +
|
log.info("The second instance has been started. If that happens at the first instance" +
|
||||||
" we are in trouble... " + t.getMessage());
|
" we are in trouble... " + t.getMessage());
|
||||||
sender().tell(new PeerInitialized(null), self());
|
sender().tell(new PeerInitialized(null, null), self());
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.matchAny(o -> log.info("received unknown message")).build()
|
.matchAny(o -> log.info("received unknown message")).build()
|
||||||
|
|
|
@ -26,13 +26,18 @@ import net.tomp2p.peers.Number160;
|
||||||
public class PeerInitialized {
|
public class PeerInitialized {
|
||||||
|
|
||||||
private final Number160 peerId;
|
private final Number160 peerId;
|
||||||
|
private final Integer port;
|
||||||
|
|
||||||
public PeerInitialized(Number160 peerId) {
|
public PeerInitialized(Number160 peerId, Integer port) {
|
||||||
this.peerId = peerId;
|
this.peerId = peerId;
|
||||||
|
this.port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Number160 getPeerId() {
|
public Number160 getPeerId() {
|
||||||
return peerId;
|
return peerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getPort() {
|
||||||
|
return port;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
56
src/main/java/io/bitsquare/util/BitsquareArgumentParser.java
Normal file
56
src/main/java/io/bitsquare/util/BitsquareArgumentParser.java
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Bitsquare.
|
||||||
|
*
|
||||||
|
* Bitsquare is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||||
|
* License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.bitsquare.util;
|
||||||
|
|
||||||
|
import net.sourceforge.argparse4j.ArgumentParsers;
|
||||||
|
import net.sourceforge.argparse4j.impl.Arguments;
|
||||||
|
import net.sourceforge.argparse4j.inf.ArgumentParser;
|
||||||
|
import net.sourceforge.argparse4j.inf.ArgumentParserException;
|
||||||
|
import net.sourceforge.argparse4j.inf.Namespace;
|
||||||
|
|
||||||
|
public class BitsquareArgumentParser {
|
||||||
|
|
||||||
|
public static String SEED_FLAG = "seed";
|
||||||
|
public static String PORT_FLAG = "port";
|
||||||
|
public static Integer PORT_DEFAULT = 5000;
|
||||||
|
public static String NAME_FLAG = "name";
|
||||||
|
|
||||||
|
private final ArgumentParser parser;
|
||||||
|
|
||||||
|
public BitsquareArgumentParser() {
|
||||||
|
parser = ArgumentParsers.newArgumentParser("BitSquare")
|
||||||
|
.defaultHelp(true)
|
||||||
|
.description("BitSquare decentralized bitcoin exchange.");
|
||||||
|
parser.addArgument("-s", "--" + SEED_FLAG)
|
||||||
|
.action(Arguments.storeTrue())
|
||||||
|
.help("Start in DHT seed mode, no UI.");
|
||||||
|
parser.addArgument("-p", "--"+PORT_FLAG)
|
||||||
|
.setDefault(PORT_DEFAULT)
|
||||||
|
.help("IP port to listen on.");
|
||||||
|
parser.addArgument("-n", "--"+NAME_FLAG)
|
||||||
|
.help("Append name to application name.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Namespace parseArgs(String... args) throws ArgumentParserException {
|
||||||
|
return parser.parseArgs(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleError(ArgumentParserException e) {
|
||||||
|
parser.handleError(e);
|
||||||
|
}
|
||||||
|
}
|
|
@ -34,20 +34,39 @@ public class ConfigLoader {
|
||||||
private static final String configFilePath = AppDirectory.dir() + "/bitsquare.conf";
|
private static final String configFilePath = AppDirectory.dir() + "/bitsquare.conf";
|
||||||
|
|
||||||
public static Properties loadConfig() {
|
public static Properties loadConfig() {
|
||||||
Properties properties = new Properties();
|
|
||||||
InputStream inputStream = null;
|
InputStream inputStream = null;
|
||||||
|
|
||||||
|
// load default properties from class path
|
||||||
|
Properties defaultProperties = new Properties();
|
||||||
|
try {
|
||||||
|
InputStream is = ConfigLoader.class.getResourceAsStream("/bitsquare.properties");
|
||||||
|
defaultProperties.load(is);
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
ioe.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (inputStream != null) {
|
||||||
|
try {
|
||||||
|
inputStream.close();
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
ioe.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// load properties file from config file path
|
||||||
|
Properties properties = new Properties(defaultProperties);
|
||||||
if (new File(configFilePath).exists()) {
|
if (new File(configFilePath).exists()) {
|
||||||
try {
|
try {
|
||||||
inputStream = new FileInputStream(configFilePath);
|
inputStream = new FileInputStream(configFilePath);
|
||||||
properties.load(inputStream);
|
properties.load(inputStream);
|
||||||
} catch (IOException e) {
|
} catch (IOException ioe) {
|
||||||
e.printStackTrace();
|
ioe.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
if (inputStream != null) {
|
if (inputStream != null) {
|
||||||
try {
|
try {
|
||||||
inputStream.close();
|
inputStream.close();
|
||||||
} catch (IOException e2) {
|
} catch (IOException ioe) {
|
||||||
e2.printStackTrace();
|
ioe.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
seed.0.id=localhost
|
||||||
|
seed.0.address=127.0.0.1
|
||||||
|
seed.0.port=5001
|
||||||
|
|
||||||
|
seed.1.id=digitalocean.bitsquare.io
|
||||||
|
seed.1.address=188.226.179.109
|
||||||
|
seed.1.port=5000
|
Loading…
Add table
Reference in a new issue