mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-06-29 09:07:27 -04:00
Begin separation of JavaFX GUI and seed node CLI
This commit is contained in:
parent
ad1b3ccd1e
commit
f6368754b9
7 changed files with 76 additions and 76 deletions
|
@ -17,7 +17,7 @@ sourceCompatibility = 1.8
|
||||||
|
|
||||||
sourceSets.main.resources.srcDirs += 'src/main/java'
|
sourceSets.main.resources.srcDirs += 'src/main/java'
|
||||||
|
|
||||||
mainClassName = "io.bitsquare.Bitsquare"
|
mainClassName = "io.bitsquare.BitsquareUI"
|
||||||
|
|
||||||
run {
|
run {
|
||||||
if ( project.hasProperty('args') ) {
|
if ( project.hasProperty('args') ) {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
C:\Progra~1\Java\jdk1.8.0_20\bin\javapackager.exe -deploy -BappVersion=0.1.0 -native exe -name Bitsquare -title Bitsquare -vendor Bitsquare -outdir build -appclass io.bitsquare.Bitsquare -srcfiles .\build\libs\bitsquare-0.1.0-SNAPSHOT-all.jar -outfile Bitsquare -Bruntime="c:\Program Files\Java\jdk1.8.0_20\jre"
|
C:\Progra~1\Java\jdk1.8.0_20\bin\javapackager.exe -deploy -BappVersion=0.1.0 -native exe -name Bitsquare -title Bitsquare -vendor Bitsquare -outdir build -appclass io.bitsquare.BitsquareUI -srcfiles .\build\libs\bitsquare-0.1.0-SNAPSHOT-all.jar -outfile Bitsquare -Bruntime="c:\Program Files\Java\jdk1.8.0_20\jre"
|
||||||
|
|
|
@ -29,9 +29,6 @@ import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import javafx.application.Application;
|
|
||||||
|
|
||||||
import net.tomp2p.connection.Ports;
|
|
||||||
import net.tomp2p.peers.Number160;
|
import net.tomp2p.peers.Number160;
|
||||||
import net.tomp2p.peers.PeerAddress;
|
import net.tomp2p.peers.PeerAddress;
|
||||||
|
|
||||||
|
@ -50,17 +47,12 @@ public class Bitsquare {
|
||||||
private static final Logger log = LoggerFactory.getLogger(Bitsquare.class);
|
private static final Logger log = LoggerFactory.getLogger(Bitsquare.class);
|
||||||
|
|
||||||
private static String appName = "Bitsquare";
|
private static String appName = "Bitsquare";
|
||||||
private static int clientPort;
|
|
||||||
private static String interfaceHint;
|
private static String interfaceHint;
|
||||||
|
|
||||||
public static String getAppName() {
|
public static String getAppName() {
|
||||||
return appName;
|
return appName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getClientPort() {
|
|
||||||
return clientPort;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
BitsquareArgumentParser parser = new BitsquareArgumentParser();
|
BitsquareArgumentParser parser = new BitsquareArgumentParser();
|
||||||
|
@ -73,6 +65,9 @@ public class Bitsquare {
|
||||||
}
|
}
|
||||||
if (namespace != null) {
|
if (namespace != null) {
|
||||||
|
|
||||||
|
//
|
||||||
|
// global args
|
||||||
|
//
|
||||||
if (namespace.getString(BitsquareArgumentParser.NAME_FLAG) != null) {
|
if (namespace.getString(BitsquareArgumentParser.NAME_FLAG) != null) {
|
||||||
appName = appName + "-" + namespace.getString(BitsquareArgumentParser.NAME_FLAG);
|
appName = appName + "-" + namespace.getString(BitsquareArgumentParser.NAME_FLAG);
|
||||||
}
|
}
|
||||||
|
@ -86,67 +81,63 @@ public class Bitsquare {
|
||||||
port = Integer.valueOf(namespace.getString(BitsquareArgumentParser.PORT_FLAG));
|
port = Integer.valueOf(namespace.getString(BitsquareArgumentParser.PORT_FLAG));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (namespace.getBoolean(BitsquareArgumentParser.SEED_FLAG) == true) {
|
//
|
||||||
String seedID = SeedNodeAddress.StaticSeedNodeAddresses.DIGITAL_OCEAN1.getId();
|
// seed-node only
|
||||||
if (namespace.getString(BitsquareArgumentParser.PEER_ID_FLAG) != null) {
|
//
|
||||||
seedID = namespace.getString(BitsquareArgumentParser.PEER_ID_FLAG);
|
String seedID = SeedNodeAddress.StaticSeedNodeAddresses.DIGITAL_OCEAN1.getId();
|
||||||
}
|
if (namespace.getString(BitsquareArgumentParser.PEER_ID_FLAG) != null) {
|
||||||
|
seedID = namespace.getString(BitsquareArgumentParser.PEER_ID_FLAG);
|
||||||
|
}
|
||||||
|
|
||||||
ActorSystem actorSystem = ActorSystem.create(getAppName());
|
ActorSystem actorSystem = ActorSystem.create(getAppName());
|
||||||
|
|
||||||
final Set<PeerAddress> peerAddresses = new HashSet<PeerAddress>();
|
final Set<PeerAddress> peerAddresses = new HashSet<PeerAddress>();
|
||||||
final String sid = seedID;
|
final String sid = seedID;
|
||||||
SeedNodeAddress.StaticSeedNodeAddresses.getAllSeedNodeAddresses().forEach(a -> {
|
SeedNodeAddress.StaticSeedNodeAddresses.getAllSeedNodeAddresses().forEach(a -> {
|
||||||
if (!a.getId().equals(sid)) {
|
if (!a.getId().equals(sid)) {
|
||||||
try {
|
|
||||||
peerAddresses.add(new PeerAddress(Number160.createHash(a.getId()), a.getIp(),
|
|
||||||
a.getPort(), a.getPort()));
|
|
||||||
} catch (UnknownHostException uhe) {
|
|
||||||
log.error("Unknown Host [" + a.getIp() + "]: " + uhe.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
int serverPort = (port == -1) ? BitsquareArgumentParser.PORT_DEFAULT : port;
|
|
||||||
|
|
||||||
ActorRef seedNode = actorSystem.actorOf(DHTManager.getProps(), DHTManager.SEED_NAME);
|
|
||||||
Inbox inbox = Inbox.create(actorSystem);
|
|
||||||
inbox.send(seedNode, new InitializePeer(Number160.createHash(sid), serverPort, interfaceHint,
|
|
||||||
peerAddresses));
|
|
||||||
|
|
||||||
Thread seedNodeThread = new Thread(() -> {
|
|
||||||
Boolean quit = false;
|
|
||||||
while (!quit) {
|
|
||||||
try {
|
|
||||||
Object m = inbox.receive(FiniteDuration.create(5L, "seconds"));
|
|
||||||
if (m instanceof PeerInitialized) {
|
|
||||||
log.debug("Seed Peer Initialized on port " + ((PeerInitialized) m).getPort
|
|
||||||
());
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
if (!(e instanceof TimeoutException)) {
|
|
||||||
quit = true;
|
|
||||||
log.error(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
actorSystem.shutdown();
|
|
||||||
try {
|
try {
|
||||||
actorSystem.awaitTermination(Duration.create(5L, "seconds"));
|
peerAddresses.add(new PeerAddress(Number160.createHash(a.getId()), a.getIp(),
|
||||||
} catch (Exception ex) {
|
a.getPort(), a.getPort()));
|
||||||
if (ex instanceof TimeoutException)
|
} catch (UnknownHostException uhe) {
|
||||||
log.error("ActorSystem did not shutdown properly.");
|
log.error("Unknown Host [" + a.getIp() + "]: " + uhe.getMessage());
|
||||||
else
|
|
||||||
log.error(ex.getMessage());
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
seedNodeThread.start();
|
});
|
||||||
}
|
|
||||||
else {
|
int serverPort = (port == -1) ? BitsquareArgumentParser.PORT_DEFAULT : port;
|
||||||
// We use a random port for the client if no port is passed to the application
|
|
||||||
clientPort = (port == -1) ? new Ports().tcpPort() : port;
|
ActorRef seedNode = actorSystem.actorOf(DHTManager.getProps(), DHTManager.SEED_NAME);
|
||||||
Application.launch(BitsquareUI.class, args);
|
Inbox inbox = Inbox.create(actorSystem);
|
||||||
}
|
inbox.send(seedNode, new InitializePeer(Number160.createHash(sid), serverPort, interfaceHint,
|
||||||
|
peerAddresses));
|
||||||
|
|
||||||
|
Thread seedNodeThread = new Thread(() -> {
|
||||||
|
Boolean quit = false;
|
||||||
|
while (!quit) {
|
||||||
|
try {
|
||||||
|
Object m = inbox.receive(FiniteDuration.create(5L, "seconds"));
|
||||||
|
if (m instanceof PeerInitialized) {
|
||||||
|
log.debug("Seed Peer Initialized on port " + ((PeerInitialized) m).getPort
|
||||||
|
());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (!(e instanceof TimeoutException)) {
|
||||||
|
quit = true;
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
actorSystem.shutdown();
|
||||||
|
try {
|
||||||
|
actorSystem.awaitTermination(Duration.create(5L, "seconds"));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (ex instanceof TimeoutException)
|
||||||
|
log.error("ActorSystem did not shutdown properly.");
|
||||||
|
else
|
||||||
|
log.error(ex.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
seedNodeThread.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
package io.bitsquare;
|
package io.bitsquare;
|
||||||
|
|
||||||
import io.bitsquare.di.BitsquareModule;
|
import io.bitsquare.di.BitsquareModule;
|
||||||
import io.bitsquare.gui.SystemTray;
|
|
||||||
import io.bitsquare.gui.Navigation;
|
import io.bitsquare.gui.Navigation;
|
||||||
|
import io.bitsquare.gui.SystemTray;
|
||||||
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.persistence.Persistence;
|
import io.bitsquare.persistence.Persistence;
|
||||||
|
@ -58,6 +58,10 @@ public class BitsquareUI extends Application {
|
||||||
this.injector = Guice.createInjector(bitsquareModule);
|
this.injector = Guice.createInjector(bitsquareModule);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Application.launch(BitsquareUI.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) {
|
public void start(Stage primaryStage) {
|
||||||
BitsquareUI.primaryStage = primaryStage;
|
BitsquareUI.primaryStage = primaryStage;
|
||||||
|
|
|
@ -30,9 +30,12 @@ import io.bitsquare.user.User;
|
||||||
import io.bitsquare.util.ConfigLoader;
|
import io.bitsquare.util.ConfigLoader;
|
||||||
|
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
|
import com.google.inject.name.Names;
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import net.tomp2p.connection.Ports;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -64,6 +67,9 @@ public class BitsquareModule extends AbstractBitsquareModule {
|
||||||
install(guiModule());
|
install(guiModule());
|
||||||
|
|
||||||
bind(ActorSystem.class).toInstance(ActorSystem.create(Bitsquare.getAppName()));
|
bind(ActorSystem.class).toInstance(ActorSystem.create(Bitsquare.getAppName()));
|
||||||
|
|
||||||
|
int randomPort = new Ports().tcpPort();
|
||||||
|
bindConstant().annotatedWith(Names.named("clientPort")).to(randomPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MessageModule messageModule() {
|
protected MessageModule messageModule() {
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
package io.bitsquare.gui.main;
|
package io.bitsquare.gui.main;
|
||||||
|
|
||||||
import io.bitsquare.Bitsquare;
|
|
||||||
import io.bitsquare.bank.BankAccount;
|
import io.bitsquare.bank.BankAccount;
|
||||||
import io.bitsquare.btc.WalletFacade;
|
import io.bitsquare.btc.WalletFacade;
|
||||||
import io.bitsquare.gui.UIModel;
|
import io.bitsquare.gui.UIModel;
|
||||||
|
@ -35,6 +34,8 @@ import com.google.inject.Inject;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.beans.property.BooleanProperty;
|
import javafx.beans.property.BooleanProperty;
|
||||||
import javafx.beans.property.DoubleProperty;
|
import javafx.beans.property.DoubleProperty;
|
||||||
|
@ -57,6 +58,7 @@ class MainModel extends UIModel {
|
||||||
private final MessageFacade messageFacade;
|
private final MessageFacade messageFacade;
|
||||||
private final TradeManager tradeManager;
|
private final TradeManager tradeManager;
|
||||||
private final Persistence persistence;
|
private final Persistence persistence;
|
||||||
|
private final int clientPort;
|
||||||
|
|
||||||
private boolean messageFacadeInited;
|
private boolean messageFacadeInited;
|
||||||
private boolean walletFacadeInited;
|
private boolean walletFacadeInited;
|
||||||
|
@ -72,12 +74,14 @@ class MainModel extends UIModel {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private MainModel(User user, WalletFacade walletFacade, MessageFacade messageFacade,
|
private MainModel(User user, WalletFacade walletFacade, MessageFacade messageFacade,
|
||||||
TradeManager tradeManager, Persistence persistence) {
|
TradeManager tradeManager, Persistence persistence,
|
||||||
|
@Named("clientPort") int clientPort) {
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.walletFacade = walletFacade;
|
this.walletFacade = walletFacade;
|
||||||
this.messageFacade = messageFacade;
|
this.messageFacade = messageFacade;
|
||||||
this.tradeManager = tradeManager;
|
this.tradeManager = tradeManager;
|
||||||
this.persistence = persistence;
|
this.persistence = persistence;
|
||||||
|
this.clientPort = clientPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -107,7 +111,7 @@ 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
|
||||||
|
|
||||||
messageFacade.init(Bitsquare.getClientPort(), new BootstrapListener() {
|
messageFacade.init(clientPort, new BootstrapListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCompleted() {
|
public void onCompleted() {
|
||||||
messageFacadeInited = true;
|
messageFacadeInited = true;
|
||||||
|
|
|
@ -20,7 +20,6 @@ package io.bitsquare.util;
|
||||||
import io.bitsquare.msg.SeedNodeAddress;
|
import io.bitsquare.msg.SeedNodeAddress;
|
||||||
|
|
||||||
import net.sourceforge.argparse4j.ArgumentParsers;
|
import net.sourceforge.argparse4j.ArgumentParsers;
|
||||||
import net.sourceforge.argparse4j.impl.Arguments;
|
|
||||||
import net.sourceforge.argparse4j.inf.ArgumentParser;
|
import net.sourceforge.argparse4j.inf.ArgumentParser;
|
||||||
import net.sourceforge.argparse4j.inf.ArgumentParserException;
|
import net.sourceforge.argparse4j.inf.ArgumentParserException;
|
||||||
import net.sourceforge.argparse4j.inf.Namespace;
|
import net.sourceforge.argparse4j.inf.Namespace;
|
||||||
|
@ -36,7 +35,6 @@ optional arguments:
|
||||||
*/
|
*/
|
||||||
public class BitsquareArgumentParser {
|
public class BitsquareArgumentParser {
|
||||||
|
|
||||||
public static String SEED_FLAG = "seed";
|
|
||||||
public static String PEER_ID_FLAG = "peerid";
|
public static String PEER_ID_FLAG = "peerid";
|
||||||
public static String PORT_FLAG = "port";
|
public static String PORT_FLAG = "port";
|
||||||
public static Integer PORT_DEFAULT = 5000;
|
public static Integer PORT_DEFAULT = 5000;
|
||||||
|
@ -49,9 +47,6 @@ public class BitsquareArgumentParser {
|
||||||
parser = ArgumentParsers.newArgumentParser("Bitsquare")
|
parser = ArgumentParsers.newArgumentParser("Bitsquare")
|
||||||
.defaultHelp(true)
|
.defaultHelp(true)
|
||||||
.description("Bitsquare - The decentralized bitcoin exchange.");
|
.description("Bitsquare - The decentralized bitcoin exchange.");
|
||||||
parser.addArgument("-s", "--" + SEED_FLAG)
|
|
||||||
.action(Arguments.storeTrue())
|
|
||||||
.help("Start as DHT seed peer, no UI.");
|
|
||||||
parser.addArgument("-d", "--" + PEER_ID_FLAG)
|
parser.addArgument("-d", "--" + PEER_ID_FLAG)
|
||||||
.setDefault(SeedNodeAddress.StaticSeedNodeAddresses.DIGITAL_OCEAN1.getId())
|
.setDefault(SeedNodeAddress.StaticSeedNodeAddresses.DIGITAL_OCEAN1.getId())
|
||||||
.help("Seed peer ID.");
|
.help("Seed peer ID.");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue