From 47232eebc2a24f21b2f85330fd8a6939089ea3c0 Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Sun, 5 Oct 2014 23:53:49 -0700 Subject: [PATCH 01/10] Added command line arguments parser and flag to start app in seed mode. Also added default properties loader, but not using it yet. --- .idea/copyright/Bitsquare_Affero_GPLv3.xml | 9 -- .idea/copyright/profiles_settings.xml | 2 +- build.gradle | 1 + src/main/java/io/bitsquare/BitSquare.java | 91 +++++++++++++------ .../java/io/bitsquare/gui/main/MainModel.java | 21 ----- .../java/io/bitsquare/msg/DHTSeedService.java | 4 +- .../io/bitsquare/msg/actor/DHTManager.java | 11 +-- .../msg/actor/event/PeerInitialized.java | 7 +- .../util/BitsquareArgumentParser.java | 56 ++++++++++++ .../java/io/bitsquare/util/ConfigLoader.java | 29 +++++- src/main/resources/bitsquare.properties | 7 ++ 11 files changed, 165 insertions(+), 73 deletions(-) delete mode 100644 .idea/copyright/Bitsquare_Affero_GPLv3.xml create mode 100644 src/main/java/io/bitsquare/util/BitsquareArgumentParser.java diff --git a/.idea/copyright/Bitsquare_Affero_GPLv3.xml b/.idea/copyright/Bitsquare_Affero_GPLv3.xml deleted file mode 100644 index 20bcc836bb..0000000000 --- a/.idea/copyright/Bitsquare_Affero_GPLv3.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml index f6fb94b193..e7bedf3377 100644 --- a/.idea/copyright/profiles_settings.xml +++ b/.idea/copyright/profiles_settings.xml @@ -1,3 +1,3 @@ - + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 21a9af1e84..7857b19d63 100644 --- a/build.gradle +++ b/build.gradle @@ -43,6 +43,7 @@ dependencies { compile 'com.google.code.findbugs:jsr305:2.0.3' compile 'net.jcip:jcip-annotations:1.0' compile 'org.jetbrains:annotations:13.0' + compile 'net.sourceforge.argparse4j:argparse4j:0.4.4' testCompile 'junit:junit:4.11' testCompile 'org.mockito:mockito-all:1.9.5' } diff --git a/src/main/java/io/bitsquare/BitSquare.java b/src/main/java/io/bitsquare/BitSquare.java index fcbb7f0115..56cb6697f2 100644 --- a/src/main/java/io/bitsquare/BitSquare.java +++ b/src/main/java/io/bitsquare/BitSquare.java @@ -24,11 +24,13 @@ import io.bitsquare.gui.Navigation; import io.bitsquare.gui.components.Popups; import io.bitsquare.gui.util.ImageUtil; import io.bitsquare.gui.util.Profiler; +import io.bitsquare.msg.DHTSeedService; 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.settings.Settings; import io.bitsquare.user.User; +import io.bitsquare.util.BitsquareArgumentParser; import io.bitsquare.util.ViewLoader; import com.google.common.base.Throwables; @@ -39,7 +41,6 @@ import com.google.inject.Injector; import java.io.IOException; import java.util.Arrays; -import java.util.List; import javafx.application.Application; import javafx.scene.*; @@ -52,6 +53,8 @@ import org.slf4j.LoggerFactory; import akka.actor.ActorSystem; import lighthouse.files.AppDirectory; +import net.sourceforge.argparse4j.inf.ArgumentParserException; +import net.sourceforge.argparse4j.inf.Namespace; public class BitSquare extends Application { private static final Logger log = LoggerFactory.getLogger(BitSquare.class); @@ -59,6 +62,7 @@ public class BitSquare extends Application { public static final boolean fillFormsWithDummyData = true; private static String APP_NAME = "Bitsquare"; + private static Injector injector; private static Stage primaryStage; private WalletFacade walletFacade; private MessageFacade messageFacade; @@ -67,37 +71,68 @@ public class BitSquare extends Application { Profiler.init(); Profiler.printMsgWithTime("BitSquare.main called with args " + Arrays.asList(args).toString()); - if (args.length > 0) - 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 staticSedNodeAddresses = SeedNodeAddress - .StaticSeedNodeAddresses.getAllSeedNodeAddresses(); - SeedNode seedNode = new SeedNode(new SeedNodeAddress(staticSedNodeAddresses.get(0))); - seedNode.setDaemon(true); - seedNode.start(); + injector = Guice.createInjector(new BitSquareModule()); + BitsquareArgumentParser parser = new BitsquareArgumentParser(); + Namespace namespace = null; try { - // keep main thread up - Thread.sleep(Long.MAX_VALUE); - log.debug("Localhost seed node started"); - } catch (InterruptedException e) { - log.error(e.toString()); + //System.out.println(parser.parseArgs(args)); + namespace = parser.parseArgs(args); + } catch (ArgumentParserException e) { + parser.handleError(e); + 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 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() { return primaryStage; @@ -121,7 +156,7 @@ public class BitSquare extends Application { 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 AWTSystemTray.createSystemTray(primaryStage, injector.getInstance(ActorSystem.class)); diff --git a/src/main/java/io/bitsquare/gui/main/MainModel.java b/src/main/java/io/bitsquare/gui/main/MainModel.java index 2291611195..a49e223dd7 100644 --- a/src/main/java/io/bitsquare/gui/main/MainModel.java +++ b/src/main/java/io/bitsquare/gui/main/MainModel.java @@ -104,27 +104,6 @@ class MainModel extends UIModel { // For testing with the serverside seednode we need the BootstrappedPeerFactory which gets started form // 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() { @Override diff --git a/src/main/java/io/bitsquare/msg/DHTSeedService.java b/src/main/java/io/bitsquare/msg/DHTSeedService.java index c54d62d5a4..f13b223756 100644 --- a/src/main/java/io/bitsquare/msg/DHTSeedService.java +++ b/src/main/java/io/bitsquare/msg/DHTSeedService.java @@ -39,9 +39,9 @@ public class DHTSeedService extends ActorService { 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 - send(new InitializePeer(new Number160(5001), 5001, null)); + send(new InitializePeer(Number160.createHash(id), port, null)); } } diff --git a/src/main/java/io/bitsquare/msg/actor/DHTManager.java b/src/main/java/io/bitsquare/msg/actor/DHTManager.java index 4495306242..2b97595f6f 100644 --- a/src/main/java/io/bitsquare/msg/actor/DHTManager.java +++ b/src/main/java/io/bitsquare/msg/actor/DHTManager.java @@ -67,12 +67,11 @@ public class DHTManager extends AbstractActor { .StaticSeedNodeAddresses.getAllSeedNodeAddresses(); SeedNodeAddress seedNodeAddress = new SeedNodeAddress(staticSedNodeAddresses.get(0)); - peer = new PeerBuilder( - Number160.createHash(seedNodeAddress.getId())).ports(seedNodeAddress.getPort - ()).start(); + peer = new PeerBuilder(ip.getPeerId()).ports(ip.getPort()) + .start(); // 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(); new RelayRPC(peer); //new PeerBuilderTracker(peer); @@ -92,11 +91,11 @@ public class DHTManager extends AbstractActor { .bootstrapTo(ip.getBootstrapPeers()).start(); futureBootstrap.awaitUninterruptibly(bootstrapTimeout); }*/ - sender().tell(new PeerInitialized(peer.peerID()), self()); + sender().tell(new PeerInitialized(peer.peerID(), ip.getPort()), self()); } catch (Throwable t) { log.info("The second instance has been started. If that happens at the first instance" + " 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() diff --git a/src/main/java/io/bitsquare/msg/actor/event/PeerInitialized.java b/src/main/java/io/bitsquare/msg/actor/event/PeerInitialized.java index 8f27f1a535..82c4dd0cd0 100644 --- a/src/main/java/io/bitsquare/msg/actor/event/PeerInitialized.java +++ b/src/main/java/io/bitsquare/msg/actor/event/PeerInitialized.java @@ -26,13 +26,18 @@ import net.tomp2p.peers.Number160; public class PeerInitialized { private final Number160 peerId; + private final Integer port; - public PeerInitialized(Number160 peerId) { + public PeerInitialized(Number160 peerId, Integer port) { this.peerId = peerId; + this.port = port; } public Number160 getPeerId() { return peerId; } + public Integer getPort() { + return port; + } } diff --git a/src/main/java/io/bitsquare/util/BitsquareArgumentParser.java b/src/main/java/io/bitsquare/util/BitsquareArgumentParser.java new file mode 100644 index 0000000000..593e581fdb --- /dev/null +++ b/src/main/java/io/bitsquare/util/BitsquareArgumentParser.java @@ -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 . + */ + +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); + } +} diff --git a/src/main/java/io/bitsquare/util/ConfigLoader.java b/src/main/java/io/bitsquare/util/ConfigLoader.java index a4cc284790..0cde807aa3 100644 --- a/src/main/java/io/bitsquare/util/ConfigLoader.java +++ b/src/main/java/io/bitsquare/util/ConfigLoader.java @@ -34,20 +34,39 @@ public class ConfigLoader { private static final String configFilePath = AppDirectory.dir() + "/bitsquare.conf"; public static Properties loadConfig() { - Properties properties = new Properties(); 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()) { try { inputStream = new FileInputStream(configFilePath); properties.load(inputStream); - } catch (IOException e) { - e.printStackTrace(); + } catch (IOException ioe) { + ioe.printStackTrace(); } finally { if (inputStream != null) { try { inputStream.close(); - } catch (IOException e2) { - e2.printStackTrace(); + } catch (IOException ioe) { + ioe.printStackTrace(); } } } diff --git a/src/main/resources/bitsquare.properties b/src/main/resources/bitsquare.properties index e69de29bb2..75bbb382d4 100644 --- a/src/main/resources/bitsquare.properties +++ b/src/main/resources/bitsquare.properties @@ -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 From f2e4110235974513c34d264fff1ff38224fc6d8a Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Mon, 6 Oct 2014 00:30:08 -0700 Subject: [PATCH 02/10] fixing copyright, removed again somehow --- .idea/copyright/profiles_settings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml index e7bedf3377..f6fb94b193 100644 --- a/.idea/copyright/profiles_settings.xml +++ b/.idea/copyright/profiles_settings.xml @@ -1,3 +1,3 @@ - + \ No newline at end of file From df97e3d696630d3680fb92f02b0f08c718c0f2c8 Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Mon, 6 Oct 2014 00:46:06 -0700 Subject: [PATCH 03/10] fixing copyright, removed again somehow --- .idea/copyright/Bitsquare_Affero_GPLv3.xml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .idea/copyright/Bitsquare_Affero_GPLv3.xml diff --git a/.idea/copyright/Bitsquare_Affero_GPLv3.xml b/.idea/copyright/Bitsquare_Affero_GPLv3.xml new file mode 100644 index 0000000000..20bcc836bb --- /dev/null +++ b/.idea/copyright/Bitsquare_Affero_GPLv3.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file From ce1b57d87ad3222a65da3d9d065837a2584a5e6b Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Mon, 6 Oct 2014 11:33:24 -0700 Subject: [PATCH 04/10] Remove JFx service from seed node startup --- src/main/java/io/bitsquare/BitSquare.java | 62 +++++++++---------- .../java/io/bitsquare/di/BitSquareModule.java | 2 +- 2 files changed, 29 insertions(+), 35 deletions(-) diff --git a/src/main/java/io/bitsquare/BitSquare.java b/src/main/java/io/bitsquare/BitSquare.java index 56cb6697f2..3d197da79d 100644 --- a/src/main/java/io/bitsquare/BitSquare.java +++ b/src/main/java/io/bitsquare/BitSquare.java @@ -24,8 +24,9 @@ import io.bitsquare.gui.Navigation; import io.bitsquare.gui.components.Popups; import io.bitsquare.gui.util.ImageUtil; import io.bitsquare.gui.util.Profiler; -import io.bitsquare.msg.DHTSeedService; import io.bitsquare.msg.MessageFacade; +import io.bitsquare.msg.actor.DHTManager; +import io.bitsquare.msg.actor.command.InitializePeer; import io.bitsquare.msg.actor.event.PeerInitialized; import io.bitsquare.persistence.Persistence; import io.bitsquare.settings.Settings; @@ -48,13 +49,18 @@ import javafx.scene.image.*; import javafx.scene.input.*; import javafx.stage.Stage; +import net.tomp2p.peers.Number160; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import akka.actor.ActorRef; import akka.actor.ActorSystem; +import akka.actor.Inbox; import lighthouse.files.AppDirectory; import net.sourceforge.argparse4j.inf.ArgumentParserException; import net.sourceforge.argparse4j.inf.Namespace; +import scala.concurrent.duration.FiniteDuration; public class BitSquare extends Application { private static final Logger log = LoggerFactory.getLogger(BitSquare.class); @@ -76,7 +82,6 @@ public class BitSquare extends Application { BitsquareArgumentParser parser = new BitsquareArgumentParser(); Namespace namespace = null; try { - //System.out.println(parser.parseArgs(args)); namespace = parser.parseArgs(args); } catch (ArgumentParserException e) { parser.handleError(e); @@ -93,47 +98,36 @@ public class BitSquare extends Application { 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 - ()); + ActorSystem system = injector.getInstance(ActorSystem.class); + ActorRef seedNode = system.actorOf(DHTManager.getProps(), DHTManager.SEED_NAME); + Inbox inbox = Inbox.create(system); + inbox.send(seedNode, new InitializePeer(Number160.createHash("localhost"), port, null)); + //dhtManager.tell(new InitializePeer(Number160.createHash("localhost"), port, null), null); + Boolean quit = false; + Thread seedNodeThread = new Thread(new Runnable() { + @Override + public void run() { + while (!quit) { + try { + Object m = inbox.receive(FiniteDuration.create(5L, "seconds")); + if (m instanceof PeerInitialized) { + System.out.println("Seed Peer Initialized on port " + ((PeerInitialized) m) + .getPort()); + } + } catch (Exception e) { + // do nothing + } + } } }); - dhtSeed.initializePeer("localhost", port); + seedNodeThread.start(); } else { launch(args); } } - -// Thread seedNodeThread = new Thread(new Runnable() { -// @Override -// public void run() { -// startSeedNode(); -// } -// }); -// seedNodeThread.start(); - } -// private static void startSeedNode() { -// List 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() { return primaryStage; } diff --git a/src/main/java/io/bitsquare/di/BitSquareModule.java b/src/main/java/io/bitsquare/di/BitSquareModule.java index 93849519be..7dd98a1e9c 100644 --- a/src/main/java/io/bitsquare/di/BitSquareModule.java +++ b/src/main/java/io/bitsquare/di/BitSquareModule.java @@ -174,7 +174,7 @@ class ActorSystemProvider implements Provider { ActorSystem system = ActorSystem.create(BitSquare.getAppName()); // create top level actors - system.actorOf(DHTManager.getProps(), DHTManager.SEED_NAME); + //system.actorOf(DHTManager.getProps(), DHTManager.SEED_NAME); return system; } From b4cd7467b2215e728b222291f2c0bb27e748a50d Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Tue, 7 Oct 2014 09:24:44 -0700 Subject: [PATCH 05/10] moved UI Application to BitSquareUI class so BitSquare class can startup as seed peer on headless server. --- build.gradle | 2 +- src/main/java/io/bitsquare/BitSquare.java | 191 ++++-------------- src/main/java/io/bitsquare/BitSquareUI.java | 161 +++++++++++++++ .../io/bitsquare/gui/components/Popups.java | 11 +- .../arbitrator/ArbitratorSettingsViewCB.java | 3 +- .../restrictions/RestrictionsViewCB.java | 3 +- .../java/io/bitsquare/gui/main/help/Help.java | 3 +- 7 files changed, 209 insertions(+), 165 deletions(-) create mode 100644 src/main/java/io/bitsquare/BitSquareUI.java diff --git a/build.gradle b/build.gradle index 7857b19d63..782a8a041d 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ sourceSets.main.resources.srcDirs += 'src/main/java' javafx { appID 'Bitsquare' appName 'Bitsquare' - mainClass 'io.bitsquare.BitSquare' + mainClass 'io.bitsquare.BitSquareUI' profiles { windows { diff --git a/src/main/java/io/bitsquare/BitSquare.java b/src/main/java/io/bitsquare/BitSquare.java index 3d197da79d..e3801fb7ec 100644 --- a/src/main/java/io/bitsquare/BitSquare.java +++ b/src/main/java/io/bitsquare/BitSquare.java @@ -17,37 +17,14 @@ package io.bitsquare; -import io.bitsquare.btc.WalletFacade; -import io.bitsquare.di.BitSquareModule; -import io.bitsquare.gui.AWTSystemTray; -import io.bitsquare.gui.Navigation; -import io.bitsquare.gui.components.Popups; -import io.bitsquare.gui.util.ImageUtil; -import io.bitsquare.gui.util.Profiler; -import io.bitsquare.msg.MessageFacade; import io.bitsquare.msg.actor.DHTManager; import io.bitsquare.msg.actor.command.InitializePeer; import io.bitsquare.msg.actor.event.PeerInitialized; -import io.bitsquare.persistence.Persistence; -import io.bitsquare.settings.Settings; -import io.bitsquare.user.User; import io.bitsquare.util.BitsquareArgumentParser; -import io.bitsquare.util.ViewLoader; -import com.google.common.base.Throwables; - -import com.google.inject.Guice; -import com.google.inject.Injector; - -import java.io.IOException; - -import java.util.Arrays; +import java.util.concurrent.TimeoutException; import javafx.application.Application; -import javafx.scene.*; -import javafx.scene.image.*; -import javafx.scene.input.*; -import javafx.stage.Stage; import net.tomp2p.peers.Number160; @@ -57,27 +34,20 @@ import org.slf4j.LoggerFactory; import akka.actor.ActorRef; import akka.actor.ActorSystem; import akka.actor.Inbox; -import lighthouse.files.AppDirectory; import net.sourceforge.argparse4j.inf.ArgumentParserException; import net.sourceforge.argparse4j.inf.Namespace; +import scala.concurrent.duration.Duration; import scala.concurrent.duration.FiniteDuration; -public class BitSquare extends Application { - private static final Logger log = LoggerFactory.getLogger(BitSquare.class); +public class BitSquare { - public static final boolean fillFormsWithDummyData = true; + private static String appName = "Bitsquare"; - private static String APP_NAME = "Bitsquare"; - private static Injector injector; - private static Stage primaryStage; - private WalletFacade walletFacade; - private MessageFacade messageFacade; + public static String getAppName() { + return appName; + } public static void main(String[] args) { - Profiler.init(); - Profiler.printMsgWithTime("BitSquare.main called with args " + Arrays.asList(args).toString()); - - injector = Guice.createInjector(new BitSquareModule()); BitsquareArgumentParser parser = new BitsquareArgumentParser(); Namespace namespace = null; @@ -90,7 +60,7 @@ public class BitSquare extends Application { if (namespace != null) { if (namespace.getString(BitsquareArgumentParser.NAME_FLAG) != null) { - APP_NAME = APP_NAME + "-" + namespace.getString(BitsquareArgumentParser.NAME_FLAG); + appName = appName + "-" + namespace.getString(BitsquareArgumentParser.NAME_FLAG); } Integer port = BitsquareArgumentParser.PORT_DEFAULT; @@ -98,133 +68,42 @@ public class BitSquare extends Application { port = Integer.valueOf(namespace.getString(BitsquareArgumentParser.PORT_FLAG)); } if (namespace.getBoolean(BitsquareArgumentParser.SEED_FLAG) == true) { - ActorSystem system = injector.getInstance(ActorSystem.class); - ActorRef seedNode = system.actorOf(DHTManager.getProps(), DHTManager.SEED_NAME); - Inbox inbox = Inbox.create(system); + ActorSystem actorSystem = ActorSystem.create(getAppName()); + + ActorRef seedNode = actorSystem.actorOf(DHTManager.getProps(), DHTManager.SEED_NAME); + Inbox inbox = Inbox.create(actorSystem); inbox.send(seedNode, new InitializePeer(Number160.createHash("localhost"), port, null)); - //dhtManager.tell(new InitializePeer(Number160.createHash("localhost"), port, null), null); - Boolean quit = false; - Thread seedNodeThread = new Thread(new Runnable() { - @Override - public void run() { - while (!quit) { - try { - Object m = inbox.receive(FiniteDuration.create(5L, "seconds")); - if (m instanceof PeerInitialized) { - System.out.println("Seed Peer Initialized on port " + ((PeerInitialized) m) - .getPort()); - } - } catch (Exception e) { - // do nothing + + Thread seedNodeThread = new Thread(() -> { + Boolean quit = false; + while (!quit) { + try { + Object m = inbox.receive(FiniteDuration.create(5L, "seconds")); + if (m instanceof PeerInitialized) { + System.out.println("Seed Peer Initialized on port " + ((PeerInitialized) m).getPort + ()); + } + } catch (Exception e) { + if (!(e instanceof TimeoutException)) { + quit = true; } } } + actorSystem.shutdown(); + try { + actorSystem.awaitTermination(Duration.create(5L, "seconds")); + } catch (Exception ex) { + if (ex instanceof TimeoutException) + System.out.println("ActorSystem did not shutdown properly."); + else + System.out.println(ex.getMessage()); + } }); seedNodeThread.start(); } else { - launch(args); + Application.launch(BitSquareUI.class, args); } } } - - public static Stage getPrimaryStage() { - return primaryStage; - } - - public static String getAppName() { - return APP_NAME; - } - - @Override - public void start(Stage primaryStage) { - Profiler.printMsgWithTime("BitSquare.start called"); - BitSquare.primaryStage = primaryStage; - - Thread.currentThread().setUncaughtExceptionHandler((thread, throwable) -> Popups.handleUncaughtExceptions - (Throwables.getRootCause(throwable))); - - try { - AppDirectory.initAppDir(APP_NAME); - } catch (IOException e) { - log.error(e.getMessage()); - } - -// 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 - AWTSystemTray.createSystemTray(primaryStage, injector.getInstance(ActorSystem.class)); - - walletFacade = injector.getInstance(WalletFacade.class); - messageFacade = injector.getInstance(MessageFacade.class); - Profiler.printMsgWithTime("BitSquare: messageFacade, walletFacade created"); - - // apply stored data - final User user = injector.getInstance(User.class); - final Settings settings = injector.getInstance(Settings.class); - final Persistence persistence = injector.getInstance(Persistence.class); - persistence.init(); - - User persistedUser = (User) persistence.read(user); - user.applyPersistedUser(persistedUser); - - settings.applyPersistedSettings((Settings) persistence.read(settings.getClass().getName())); - - primaryStage.setTitle("BitSquare (" + APP_NAME + ")"); - - // sometimes there is a rendering bug, see https://github.com/bitsquare/bitsquare/issues/160 - if (ImageUtil.isRetina()) - primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("/images/window_icon@2x.png"))); - else - primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("/images/window_icon.png"))); - - ViewLoader.setInjector(injector); - - final ViewLoader loader = - new ViewLoader(getClass().getResource(Navigation.Item.MAIN.getFxmlUrl()), false); - try { - final Parent view = loader.load(); - - final Scene scene = new Scene(view, 1000, 900); - scene.getStylesheets().setAll(getClass().getResource("/io/bitsquare/gui/bitsquare.css").toExternalForm(), - getClass().getResource("/io/bitsquare/gui/images.css").toExternalForm()); - - setupCloseHandlers(primaryStage, scene); - - primaryStage.setScene(scene); - - // TODO resizing not fully supported yet - - primaryStage.setMinWidth(75); - primaryStage.setMinHeight(50); - - /* primaryStage.setMinWidth(1000); - primaryStage.setMinHeight(750);*/ - - Profiler.initScene(primaryStage.getScene()); - - primaryStage.show(); - } catch (IOException e) { - e.printStackTrace(); - log.error(e.getMessage()); - } - } - - private void setupCloseHandlers(Stage primaryStage, Scene scene) { - primaryStage.setOnCloseRequest(e -> AWTSystemTray.setStageHidden()); - - KeyCodeCombination keyCodeCombination = new KeyCodeCombination(KeyCode.W, KeyCombination.SHORTCUT_DOWN); - scene.setOnKeyReleased(keyEvent -> { - if (keyCodeCombination.match(keyEvent)) AWTSystemTray.setStageHidden(); - }); - } - - @Override - public void stop() throws Exception { - walletFacade.shutDown(); - messageFacade.shutDown(); - - super.stop(); - System.exit(0); - } } diff --git a/src/main/java/io/bitsquare/BitSquareUI.java b/src/main/java/io/bitsquare/BitSquareUI.java new file mode 100644 index 0000000000..046a1c7c5f --- /dev/null +++ b/src/main/java/io/bitsquare/BitSquareUI.java @@ -0,0 +1,161 @@ +/* + * 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 . + */ + +package io.bitsquare; + +import io.bitsquare.btc.WalletFacade; +import io.bitsquare.di.BitSquareModule; +import io.bitsquare.gui.AWTSystemTray; +import io.bitsquare.gui.Navigation; +import io.bitsquare.gui.components.Popups; +import io.bitsquare.gui.util.ImageUtil; +import io.bitsquare.gui.util.Profiler; +import io.bitsquare.msg.MessageFacade; +import io.bitsquare.persistence.Persistence; +import io.bitsquare.settings.Settings; +import io.bitsquare.user.User; +import io.bitsquare.util.ViewLoader; + +import com.google.common.base.Throwables; + +import com.google.inject.Guice; +import com.google.inject.Injector; + +import java.io.IOException; + +import javafx.application.Application; +import javafx.scene.*; +import javafx.scene.image.*; +import javafx.scene.input.*; +import javafx.stage.Stage; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import akka.actor.ActorSystem; +import lighthouse.files.AppDirectory; + +public class BitSquareUI extends Application { + private static final Logger log = LoggerFactory.getLogger(BitSquareUI.class); + + public static final boolean fillFormsWithDummyData = true; + + private static Injector injector; + private static Stage primaryStage; + private WalletFacade walletFacade; + private MessageFacade messageFacade; + + public void BitSquareUI() { + Profiler.init(); + } + + public static Stage getPrimaryStage() { + return primaryStage; + } + + @Override + public void start(Stage primaryStage) { + Profiler.printMsgWithTime("BitSquare.start called"); + BitSquareUI.primaryStage = primaryStage; + + Thread.currentThread().setUncaughtExceptionHandler((thread, throwable) -> Popups.handleUncaughtExceptions + (Throwables.getRootCause(throwable))); + + try { + AppDirectory.initAppDir(BitSquare.getAppName()); + } catch (IOException e) { + log.error(e.getMessage()); + } + + 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 + AWTSystemTray.createSystemTray(primaryStage, injector.getInstance(ActorSystem.class)); + + walletFacade = injector.getInstance(WalletFacade.class); + messageFacade = injector.getInstance(MessageFacade.class); + Profiler.printMsgWithTime("BitSquare: messageFacade, walletFacade created"); + + // apply stored data + final User user = injector.getInstance(User.class); + final Settings settings = injector.getInstance(Settings.class); + final Persistence persistence = injector.getInstance(Persistence.class); + persistence.init(); + + User persistedUser = (User) persistence.read(user); + user.applyPersistedUser(persistedUser); + + settings.applyPersistedSettings((Settings) persistence.read(settings.getClass().getName())); + + primaryStage.setTitle("BitSquare (" + BitSquare.getAppName() + ")"); + + // sometimes there is a rendering bug, see https://github.com/bitsquare/bitsquare/issues/160 + if (ImageUtil.isRetina()) + primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("/images/window_icon@2x.png"))); + else + primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("/images/window_icon.png"))); + + ViewLoader.setInjector(injector); + + final ViewLoader loader = + new ViewLoader(getClass().getResource(Navigation.Item.MAIN.getFxmlUrl()), false); + try { + final Parent view = loader.load(); + + final Scene scene = new Scene(view, 1000, 900); + scene.getStylesheets().setAll(getClass().getResource("/io/bitsquare/gui/bitsquare.css").toExternalForm(), + getClass().getResource("/io/bitsquare/gui/images.css").toExternalForm()); + + setupCloseHandlers(primaryStage, scene); + + primaryStage.setScene(scene); + + // TODO resizing not fully supported yet + + primaryStage.setMinWidth(75); + primaryStage.setMinHeight(50); + + /* primaryStage.setMinWidth(1000); + primaryStage.setMinHeight(750);*/ + + Profiler.initScene(primaryStage.getScene()); + + primaryStage.show(); + } catch (IOException e) { + e.printStackTrace(); + log.error(e.getMessage()); + } + } + + private void setupCloseHandlers(Stage primaryStage, Scene scene) { + primaryStage.setOnCloseRequest(e -> AWTSystemTray.setStageHidden()); + + KeyCodeCombination keyCodeCombination = new KeyCodeCombination(KeyCode.W, KeyCombination.SHORTCUT_DOWN); + scene.setOnKeyReleased(keyEvent -> { + if (keyCodeCombination.match(keyEvent)) AWTSystemTray.setStageHidden(); + }); + } + + @Override + public void stop() throws Exception { + walletFacade.shutDown(); + messageFacade.shutDown(); + + super.stop(); + System.exit(0); + } +} diff --git a/src/main/java/io/bitsquare/gui/components/Popups.java b/src/main/java/io/bitsquare/gui/components/Popups.java index 0b2215ec08..1696087907 100644 --- a/src/main/java/io/bitsquare/gui/components/Popups.java +++ b/src/main/java/io/bitsquare/gui/components/Popups.java @@ -18,6 +18,7 @@ package io.bitsquare.gui.components; import io.bitsquare.BitSquare; +import io.bitsquare.BitSquareUI; import io.bitsquare.gui.OverlayManager; import io.bitsquare.locale.BSResources; @@ -69,7 +70,7 @@ public class Popups { public static void openInfo(String masthead, String message, List actions) { Dialogs.create() - .owner(BitSquare.getPrimaryStage()) + .owner(BitSquareUI.getPrimaryStage()) .message(message) .masthead(masthead) .actions(actions) @@ -103,7 +104,7 @@ public class Popups { public static Action openConfirmPopup(String title, String masthead, String message, List actions) { return Dialogs.create() - .owner(BitSquare.getPrimaryStage()) + .owner(BitSquareUI.getPrimaryStage()) .title(title) .message(message) .masthead(masthead) @@ -135,7 +136,7 @@ public class Popups { private static void openWarningPopup(String title, String masthead, String message, List actions) { Dialogs.create() - .owner(BitSquare.getPrimaryStage()) + .owner(BitSquareUI.getPrimaryStage()) .title(title) .message(message) .masthead(masthead) @@ -167,7 +168,7 @@ public class Popups { private static Action openErrorPopup(String title, String masthead, String message, List actions) { return Dialogs.create() - .owner(BitSquare.getPrimaryStage()) + .owner(BitSquareUI.getPrimaryStage()) .title(title) .message(message) .masthead(masthead) @@ -195,7 +196,7 @@ public class Popups { } }); return Dialogs.create() - .owner(BitSquare.getPrimaryStage()) + .owner(BitSquareUI.getPrimaryStage()) .title(title) .message(message) .masthead(masthead) diff --git a/src/main/java/io/bitsquare/gui/main/account/arbitrator/ArbitratorSettingsViewCB.java b/src/main/java/io/bitsquare/gui/main/account/arbitrator/ArbitratorSettingsViewCB.java index 9dc40f1061..8b6b814817 100644 --- a/src/main/java/io/bitsquare/gui/main/account/arbitrator/ArbitratorSettingsViewCB.java +++ b/src/main/java/io/bitsquare/gui/main/account/arbitrator/ArbitratorSettingsViewCB.java @@ -18,6 +18,7 @@ package io.bitsquare.gui.main.account.arbitrator; import io.bitsquare.BitSquare; +import io.bitsquare.BitSquareUI; import io.bitsquare.gui.CachedViewCB; import io.bitsquare.gui.Navigation; import io.bitsquare.gui.main.account.arbitrator.registration.ArbitratorRegistrationViewCB; @@ -102,7 +103,7 @@ public class ArbitratorSettingsViewCB extends CachedViewCB { final Parent view = loader.load(); arbitratorRegistrationViewCB = loader.getController(); - final Stage rootStage = BitSquare.getPrimaryStage(); + final Stage rootStage = BitSquareUI.getPrimaryStage(); final Stage stage = new Stage(); stage.setTitle("Arbitrator"); stage.setMinWidth(800); diff --git a/src/main/java/io/bitsquare/gui/main/account/content/restrictions/RestrictionsViewCB.java b/src/main/java/io/bitsquare/gui/main/account/content/restrictions/RestrictionsViewCB.java index c0cc8e1f76..8b65c1f90a 100644 --- a/src/main/java/io/bitsquare/gui/main/account/content/restrictions/RestrictionsViewCB.java +++ b/src/main/java/io/bitsquare/gui/main/account/content/restrictions/RestrictionsViewCB.java @@ -18,6 +18,7 @@ package io.bitsquare.gui.main.account.content.restrictions; import io.bitsquare.BitSquare; +import io.bitsquare.BitSquareUI; import io.bitsquare.arbitrator.Arbitrator; import io.bitsquare.gui.CachedViewCB; import io.bitsquare.gui.Navigation; @@ -196,7 +197,7 @@ public class RestrictionsViewCB extends CachedViewCB implements Initializable childController = loader.getController(); //childController.setParentController(this); - final Stage rootStage = BitSquare.getPrimaryStage(); + final Stage rootStage = BitSquareUI.getPrimaryStage(); final Stage stage = new Stage(); stage.setTitle("Arbitrator selection"); stage.setMinWidth(800); diff --git a/src/main/java/io/bitsquare/gui/main/help/Help.java b/src/main/java/io/bitsquare/gui/main/help/Help.java index 8cc64e7b91..d7d9263b52 100644 --- a/src/main/java/io/bitsquare/gui/main/help/Help.java +++ b/src/main/java/io/bitsquare/gui/main/help/Help.java @@ -18,6 +18,7 @@ package io.bitsquare.gui.main.help; import io.bitsquare.BitSquare; +import io.bitsquare.BitSquareUI; import java.net.MalformedURLException; import java.net.URL; @@ -49,7 +50,7 @@ public class Help { if (helpWindow == null) { helpWindow = new Stage(); helpWindow.initModality(Modality.NONE); - helpWindow.initOwner(BitSquare.getPrimaryStage()); + helpWindow.initOwner(BitSquareUI.getPrimaryStage()); webView = new WebView(); helpWindow.setScene(new Scene(webView, 800, 600)); } From bec9a6875083908dc4ec6a9a4ed4ce602f1e19e6 Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Sun, 12 Oct 2014 14:56:52 -0700 Subject: [PATCH 06/10] Merged seedpeer branch with master branch, cleanup --- .../java/io/bitsquare/di/BitSquareModule.java | 13 ++++----- .../java/io/bitsquare/gui/main/MainModel.java | 27 ++++--------------- .../io/bitsquare/msg/SeedNodeAddress.java | 5 ++-- 3 files changed, 15 insertions(+), 30 deletions(-) diff --git a/src/main/java/io/bitsquare/di/BitSquareModule.java b/src/main/java/io/bitsquare/di/BitSquareModule.java index 2ac1ce63df..eacc591a28 100644 --- a/src/main/java/io/bitsquare/di/BitSquareModule.java +++ b/src/main/java/io/bitsquare/di/BitSquareModule.java @@ -119,14 +119,15 @@ class StaticSeedNodeAddressesProvider implements Provider) change -> updateNumPendingTrades()); updateNumPendingTrades(); - backendInited.set(true); + facadesInitialised = true; + + if (networkSyncProgress.get() >= 1.0) + backendReady.set(true); } private void updateNumPendingTrades() { numPendingTrades.set(tradeManager.getPendingTrades().size()); } - /* private void updateBalance(Coin balance) { - this.balance.set(balance); - }*/ } diff --git a/src/main/java/io/bitsquare/msg/SeedNodeAddress.java b/src/main/java/io/bitsquare/msg/SeedNodeAddress.java index 0469c59a84..02374a885b 100644 --- a/src/main/java/io/bitsquare/msg/SeedNodeAddress.java +++ b/src/main/java/io/bitsquare/msg/SeedNodeAddress.java @@ -55,8 +55,9 @@ public class SeedNodeAddress { /////////////////////////////////////////////////////////////////////////////////////////// public enum StaticSeedNodeAddresses { - LOCALHOST("localhost", "127.0.0.1", 5001), - DIGITAL_OCEAN("digitalocean.bitsquare.io", "188.226.179.109", 5000); + DIGITAL_OCEAN1("digitalocean1.bitsquare.io", "188.226.179.109", 5000), + DIGITAL_OCEAN2("digitalocean2.bitsquare.io", "128.199.251.106", 5000), + LOCALHOST("localhost", "127.0.0.1", 5001); private final String id; private final String ip; From 7c823714b45182492f266ca27a9627eb80935476 Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Sun, 12 Oct 2014 15:21:23 -0700 Subject: [PATCH 07/10] Merged seedpeer branch with master branch, cleanup --- .../io/bitsquare/btc/AddressBasedCoinSelector.java | 13 ++++--------- src/main/resources/bitsquare.properties | 14 +++++++++----- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/main/java/io/bitsquare/btc/AddressBasedCoinSelector.java b/src/main/java/io/bitsquare/btc/AddressBasedCoinSelector.java index 3b228a8028..b1260cd2fc 100644 --- a/src/main/java/io/bitsquare/btc/AddressBasedCoinSelector.java +++ b/src/main/java/io/bitsquare/btc/AddressBasedCoinSelector.java @@ -23,6 +23,7 @@ import org.bitcoinj.core.NetworkParameters; import org.bitcoinj.core.Transaction; import org.bitcoinj.core.TransactionConfidence; import org.bitcoinj.core.TransactionOutput; +import org.bitcoinj.params.RegTestParams; import org.bitcoinj.wallet.CoinSelection; import org.bitcoinj.wallet.DefaultCoinSelector; @@ -94,20 +95,14 @@ class AddressBasedCoinSelector extends DefaultCoinSelector { // TODO It might be risky to accept 0 confirmation tx from the network with only > 1 numBroadcastPeers // Need to be tested in testnet and mainnet // We need to handle cases when malleability happens or tx get lost and have not been successful propagated - /* return type.equals(TransactionConfidence.ConfidenceType.BUILDING) || + return type.equals(TransactionConfidence.ConfidenceType.BUILDING) || type.equals(TransactionConfidence.ConfidenceType.PENDING) && // we accept network tx without confirmations and numBroadcastPeers > 0 - //confidence.getSource().equals(TransactionConfidence.Source.SELF) && + /*confidence.getSource().equals(TransactionConfidence.Source.SELF) &&*/ // In regtest mode we expect to have only one peer, so we won't see transactions propagate. // TODO: The value 1 below dates from a time when transactions we broadcast *to* were // counted, set to 0 - (confidence.numBroadcastPeers() > 1 || tx.getParams() == RegTestParams.get());*/ - - log.debug("numBroadcastPeers = " + confidence.numBroadcastPeers()); - // TODO at testnet we got confidence.numBroadcastPeers()=0 -> probably because we use chained unconfirmed tx - // investigate further - return type.equals(TransactionConfidence.ConfidenceType.BUILDING) || - type.equals(TransactionConfidence.ConfidenceType.PENDING); + (confidence.numBroadcastPeers() > 1 || tx.getParams() == RegTestParams.get()); } private static boolean isInBlockChain(Transaction tx) { diff --git a/src/main/resources/bitsquare.properties b/src/main/resources/bitsquare.properties index 75bbb382d4..416874c054 100644 --- a/src/main/resources/bitsquare.properties +++ b/src/main/resources/bitsquare.properties @@ -1,7 +1,11 @@ -seed.0.id=localhost -seed.0.address=127.0.0.1 -seed.0.port=5001 +seed.0.id=digitalocean1.bitsquare.io +seed.0.address=188.226.179.109 +seed.0.port=5000 -seed.1.id=digitalocean.bitsquare.io -seed.1.address=188.226.179.109 +seed.1.id=digitalocean2.bitsquare.io +seed.1.address=128.199.251.106 seed.1.port=5000 + +seed.2.id=localhost +seed.2.address=127.0.0.1 +seed.2.port=5001 From 5a3cd72b8001ec61d9f68e3837de6759efefc658 Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Sun, 12 Oct 2014 15:43:45 -0700 Subject: [PATCH 08/10] Merged seedpeer branch with master branch, cleanup --- .../io/bitsquare/btc/AddressBasedCoinSelector.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/bitsquare/btc/AddressBasedCoinSelector.java b/src/main/java/io/bitsquare/btc/AddressBasedCoinSelector.java index b1260cd2fc..3b228a8028 100644 --- a/src/main/java/io/bitsquare/btc/AddressBasedCoinSelector.java +++ b/src/main/java/io/bitsquare/btc/AddressBasedCoinSelector.java @@ -23,7 +23,6 @@ import org.bitcoinj.core.NetworkParameters; import org.bitcoinj.core.Transaction; import org.bitcoinj.core.TransactionConfidence; import org.bitcoinj.core.TransactionOutput; -import org.bitcoinj.params.RegTestParams; import org.bitcoinj.wallet.CoinSelection; import org.bitcoinj.wallet.DefaultCoinSelector; @@ -95,14 +94,20 @@ class AddressBasedCoinSelector extends DefaultCoinSelector { // TODO It might be risky to accept 0 confirmation tx from the network with only > 1 numBroadcastPeers // Need to be tested in testnet and mainnet // We need to handle cases when malleability happens or tx get lost and have not been successful propagated - return type.equals(TransactionConfidence.ConfidenceType.BUILDING) || + /* return type.equals(TransactionConfidence.ConfidenceType.BUILDING) || type.equals(TransactionConfidence.ConfidenceType.PENDING) && // we accept network tx without confirmations and numBroadcastPeers > 0 - /*confidence.getSource().equals(TransactionConfidence.Source.SELF) &&*/ + //confidence.getSource().equals(TransactionConfidence.Source.SELF) && // In regtest mode we expect to have only one peer, so we won't see transactions propagate. // TODO: The value 1 below dates from a time when transactions we broadcast *to* were // counted, set to 0 - (confidence.numBroadcastPeers() > 1 || tx.getParams() == RegTestParams.get()); + (confidence.numBroadcastPeers() > 1 || tx.getParams() == RegTestParams.get());*/ + + log.debug("numBroadcastPeers = " + confidence.numBroadcastPeers()); + // TODO at testnet we got confidence.numBroadcastPeers()=0 -> probably because we use chained unconfirmed tx + // investigate further + return type.equals(TransactionConfidence.ConfidenceType.BUILDING) || + type.equals(TransactionConfidence.ConfidenceType.PENDING); } private static boolean isInBlockChain(Transaction tx) { From 5f53fea190dc88c1c4272a42ec5b9c3260efa377 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Mon, 13 Oct 2014 11:06:40 +0200 Subject: [PATCH 09/10] Remove use of Gradle JavaFX plugin As documented at [1], version 8.1.1 of the Gradle JavaFX plugin has disappeared from bintray. This causes Travis CI build failures. Version 8.1.0 is still in place [2], but downgrading to it causes further build errors. This commit removes use of the plugin entirely in order to fix the CI problem immediately. In the meantime, the Bitsquare UI must be launched directly from within IDEA. Resolves #221 See #66 [1]: https://bitbucket.org/shemnon/javafx-gradle/issue/46/received-status-code-401-from-server [2]: http://dl.bintray.com/content/shemnon/javafx-gradle/org/bitbucket/shemnon/javafxplugin/gradle-javafx-plugin/ --- build.gradle | 17 +------- gradle/javafx.gradle | 95 -------------------------------------------- 2 files changed, 1 insertion(+), 111 deletions(-) delete mode 100644 gradle/javafx.gradle diff --git a/build.gradle b/build.gradle index 41e6267681..2e264f571a 100644 --- a/build.gradle +++ b/build.gradle @@ -1,25 +1,10 @@ -apply from: 'gradle/javafx.gradle' +apply plugin: 'java' version = '0.1.0-SNAPSHOT' sourceCompatibility = 1.8 sourceSets.main.resources.srcDirs += 'src/main/java' -javafx { - appID 'Bitsquare' - appName 'Bitsquare' - mainClass 'io.bitsquare.BitSquareUI' - - profiles { - windows { - javaRuntime = 'C:/Program Files/Java/jdk1.8.0_20/jre' - bundleArguments = [ - 'win.msi.productVersion' : '0.1.0' - ] - } - } -} - repositories { jcenter() maven { url 'http://partnerdemo.artifactoryonline.com/partnerdemo/libs-snapshots-local' } diff --git a/gradle/javafx.gradle b/gradle/javafx.gradle deleted file mode 100644 index ee41360af8..0000000000 --- a/gradle/javafx.gradle +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Bootstrap script for the Gradle JavaFX Plugin. - * (based on http://plugins.jasoft.fi/vaadin.plugin) - * - * The script will add the plugin to the build script - * dependencies and apply the plugin to the project. If you do not want - * this behavior you can copy and paste the below configuration into your - * own build script and define your own repository and version for the plugin. - */ - -import org.gradle.api.GradleException; - -buildscript { - repositories { - maven { - name = 'JavaFX Gradle plugin' - url = 'http://dl.bintray.com/content/shemnon/javafx-gradle/' - } - maven { - name = 'CloudBees snapshots' - url = 'http://repository-javafx-gradle-plugin.forge.cloudbees.com/snapshot' - } - ivy { - name = 'CloudBees snapshots' - url = 'http://repository-javafx-gradle-plugin.forge.cloudbees.com/snapshot' - } - jcenter() - } - dependencies { - try { - assert (jfxrtDir != null) - } catch (RuntimeException re) { - ext.jfxrtDir = "." - } - - ext.searchFile = {Map places, List searchPaths, String searchID -> - File result = null; - places.each { k, v -> - if (result != null) return; - project.logger.debug("Looking for $searchID in $k") - def dir = v() - if (dir == null) { - project.logger.debug("$k not set") - } else { - project.logger.debug("$k is $dir") - searchPaths.each { s -> - if (result != null) return; - File f = new File(dir, s); - project.logger.debug("Trying $f.path") - if (f.exists() && f.file) { - project.logger.debug("found $searchID as $result") - result = f; - } - } - } - } - if (!result?.file) { - throw new GradleException("Could not find $searchID, please set one of ${places.keySet()}"); - } else { - project.logger.info("$searchID: ${result}") - return result - } - } - ext.findJFXJar = { - return searchFile([ - 'jfxrtDir in Gradle Properties': {jfxrtDir}, - 'JFXRT_HOME in System Environment': {System.env['JFXRT_HOME']}, - 'JAVA_HOME in System Environment': {System.env['JAVA_HOME']}, - 'java.home in JVM properties': {System.properties['java.home']} - ], - ['jfxrt.jar', 'lib/jfxrt.jar', 'lib/ext/jfxrt.jar', 'jre/lib/jfxrt.jar', 'jre/lib/ext/jfxrt.jar'], - 'JavaFX Runtime Jar') - } - - ext.findAntJavaFXJar = { - return searchFile([ - 'jfxrtDir in Gradle Properties': {jfxrtDir}, - 'JFXRT_HOME in System Environment': {System.env['JFXRT_HOME']}, - 'JAVA_HOME in System Environment': {System.env['JAVA_HOME']}, - 'java.home in JVM properties': {System.properties['java.home']} - ], - ['ant-javafx.jar', 'lib/ant-javafx.jar', '../lib/ant-javafx.jar'], - 'JavaFX Packager Tools') - } - - - classpath 'org.bitbucket.shemnon.javafxplugin:gradle-javafx-plugin:8.1.1' - classpath project.files(findAntJavaFXJar()) - classpath project.files(findJFXJar()) - } -} - -if (!project.plugins.findPlugin(org.bitbucket.shemnon.javafxplugin.JavaFXPlugin)) { - project.apply(plugin: org.bitbucket.shemnon.javafxplugin.JavaFXPlugin) -} From f135873f581c4eaf4c821755496d4c957d216b09 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Mon, 13 Oct 2014 12:02:43 +0200 Subject: [PATCH 10/10] Enable Gradle Eclipse project metadata generation This commit applies the 'eclipse' Gradle plugin, such that .classpath, .project and .settings files can be generated using: ./gradlew eclipse Once the above is complete, import the project into Eclipse with the following command: File->Import->Existing projects into workspace The .gitignore file has been updated accordingly. Resolves #222 --- .gitignore | 3 +++ build.gradle | 1 + 2 files changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 88b552d11f..d08ba465ed 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ bitsquare.iml .DS_Store .gradle build +.classpath +.project +.settings diff --git a/build.gradle b/build.gradle index 2e264f571a..c936a989be 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,5 @@ apply plugin: 'java' +apply plugin: 'eclipse' version = '0.1.0-SNAPSHOT' sourceCompatibility = 1.8