mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-04-19 15:26:03 -04:00
Begin separation of JavaFX GUI and seed node CLI
This commit is contained in:
parent
ad1b3ccd1e
commit
f6368754b9
@ -17,7 +17,7 @@ sourceCompatibility = 1.8
|
||||
|
||||
sourceSets.main.resources.srcDirs += 'src/main/java'
|
||||
|
||||
mainClassName = "io.bitsquare.Bitsquare"
|
||||
mainClassName = "io.bitsquare.BitsquareUI"
|
||||
|
||||
run {
|
||||
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.concurrent.TimeoutException;
|
||||
|
||||
import javafx.application.Application;
|
||||
|
||||
import net.tomp2p.connection.Ports;
|
||||
import net.tomp2p.peers.Number160;
|
||||
import net.tomp2p.peers.PeerAddress;
|
||||
|
||||
@ -50,17 +47,12 @@ public class Bitsquare {
|
||||
private static final Logger log = LoggerFactory.getLogger(Bitsquare.class);
|
||||
|
||||
private static String appName = "Bitsquare";
|
||||
private static int clientPort;
|
||||
private static String interfaceHint;
|
||||
|
||||
public static String getAppName() {
|
||||
return appName;
|
||||
}
|
||||
|
||||
public static int getClientPort() {
|
||||
return clientPort;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
BitsquareArgumentParser parser = new BitsquareArgumentParser();
|
||||
@ -73,6 +65,9 @@ public class Bitsquare {
|
||||
}
|
||||
if (namespace != null) {
|
||||
|
||||
//
|
||||
// global args
|
||||
//
|
||||
if (namespace.getString(BitsquareArgumentParser.NAME_FLAG) != null) {
|
||||
appName = appName + "-" + namespace.getString(BitsquareArgumentParser.NAME_FLAG);
|
||||
}
|
||||
@ -86,67 +81,63 @@ public class Bitsquare {
|
||||
port = Integer.valueOf(namespace.getString(BitsquareArgumentParser.PORT_FLAG));
|
||||
}
|
||||
|
||||
if (namespace.getBoolean(BitsquareArgumentParser.SEED_FLAG) == true) {
|
||||
String seedID = SeedNodeAddress.StaticSeedNodeAddresses.DIGITAL_OCEAN1.getId();
|
||||
if (namespace.getString(BitsquareArgumentParser.PEER_ID_FLAG) != null) {
|
||||
seedID = namespace.getString(BitsquareArgumentParser.PEER_ID_FLAG);
|
||||
}
|
||||
//
|
||||
// seed-node only
|
||||
//
|
||||
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 String sid = seedID;
|
||||
SeedNodeAddress.StaticSeedNodeAddresses.getAllSeedNodeAddresses().forEach(a -> {
|
||||
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();
|
||||
final Set<PeerAddress> peerAddresses = new HashSet<PeerAddress>();
|
||||
final String sid = seedID;
|
||||
SeedNodeAddress.StaticSeedNodeAddresses.getAllSeedNodeAddresses().forEach(a -> {
|
||||
if (!a.getId().equals(sid)) {
|
||||
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());
|
||||
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());
|
||||
}
|
||||
});
|
||||
seedNodeThread.start();
|
||||
}
|
||||
else {
|
||||
// We use a random port for the client if no port is passed to the application
|
||||
clientPort = (port == -1) ? new Ports().tcpPort() : port;
|
||||
Application.launch(BitsquareUI.class, args);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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 {
|
||||
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;
|
||||
|
||||
import io.bitsquare.di.BitsquareModule;
|
||||
import io.bitsquare.gui.SystemTray;
|
||||
import io.bitsquare.gui.Navigation;
|
||||
import io.bitsquare.gui.SystemTray;
|
||||
import io.bitsquare.gui.components.Popups;
|
||||
import io.bitsquare.gui.util.ImageUtil;
|
||||
import io.bitsquare.persistence.Persistence;
|
||||
@ -58,6 +58,10 @@ public class BitsquareUI extends Application {
|
||||
this.injector = Guice.createInjector(bitsquareModule);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Application.launch(BitsquareUI.class, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) {
|
||||
BitsquareUI.primaryStage = primaryStage;
|
||||
|
@ -30,9 +30,12 @@ import io.bitsquare.user.User;
|
||||
import io.bitsquare.util.ConfigLoader;
|
||||
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.name.Names;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import net.tomp2p.connection.Ports;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -64,6 +67,9 @@ public class BitsquareModule extends AbstractBitsquareModule {
|
||||
install(guiModule());
|
||||
|
||||
bind(ActorSystem.class).toInstance(ActorSystem.create(Bitsquare.getAppName()));
|
||||
|
||||
int randomPort = new Ports().tcpPort();
|
||||
bindConstant().annotatedWith(Names.named("clientPort")).to(randomPort);
|
||||
}
|
||||
|
||||
protected MessageModule messageModule() {
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
package io.bitsquare.gui.main;
|
||||
|
||||
import io.bitsquare.Bitsquare;
|
||||
import io.bitsquare.bank.BankAccount;
|
||||
import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.gui.UIModel;
|
||||
@ -35,6 +34,8 @@ import com.google.inject.Inject;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.DoubleProperty;
|
||||
@ -57,6 +58,7 @@ class MainModel extends UIModel {
|
||||
private final MessageFacade messageFacade;
|
||||
private final TradeManager tradeManager;
|
||||
private final Persistence persistence;
|
||||
private final int clientPort;
|
||||
|
||||
private boolean messageFacadeInited;
|
||||
private boolean walletFacadeInited;
|
||||
@ -72,12 +74,14 @@ class MainModel extends UIModel {
|
||||
|
||||
@Inject
|
||||
private MainModel(User user, WalletFacade walletFacade, MessageFacade messageFacade,
|
||||
TradeManager tradeManager, Persistence persistence) {
|
||||
TradeManager tradeManager, Persistence persistence,
|
||||
@Named("clientPort") int clientPort) {
|
||||
this.user = user;
|
||||
this.walletFacade = walletFacade;
|
||||
this.messageFacade = messageFacade;
|
||||
this.tradeManager = tradeManager;
|
||||
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
|
||||
// messageFacade.init
|
||||
|
||||
messageFacade.init(Bitsquare.getClientPort(), new BootstrapListener() {
|
||||
messageFacade.init(clientPort, new BootstrapListener() {
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
messageFacadeInited = true;
|
||||
|
@ -20,7 +20,6 @@ package io.bitsquare.util;
|
||||
import io.bitsquare.msg.SeedNodeAddress;
|
||||
|
||||
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;
|
||||
@ -36,7 +35,6 @@ optional arguments:
|
||||
*/
|
||||
public class BitsquareArgumentParser {
|
||||
|
||||
public static String SEED_FLAG = "seed";
|
||||
public static String PEER_ID_FLAG = "peerid";
|
||||
public static String PORT_FLAG = "port";
|
||||
public static Integer PORT_DEFAULT = 5000;
|
||||
@ -49,9 +47,6 @@ public class BitsquareArgumentParser {
|
||||
parser = ArgumentParsers.newArgumentParser("Bitsquare")
|
||||
.defaultHelp(true)
|
||||
.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)
|
||||
.setDefault(SeedNodeAddress.StaticSeedNodeAddresses.DIGITAL_OCEAN1.getId())
|
||||
.help("Seed peer ID.");
|
||||
|
Loading…
x
Reference in New Issue
Block a user