From 20db54e87ba42b4663cb77d1b2d92a5fb8031a80 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Sun, 9 Nov 2014 23:53:59 +0100 Subject: [PATCH 1/6] Remove Akka-based seed node infrastructure (for now) In favor of using the simplified app.cli.SeedNode class while we continue to debug basic UPnP functionality. --- build.gradle | 1 - src/main/java/io/bitsquare/app/AppModule.java | 15 -- .../java/io/bitsquare/app/ArgumentParser.java | 3 - .../bitsquare/app/cli/SeedNodeUsingAkka.java | 111 -------------- .../java/io/bitsquare/btc/WalletFacade.java | 1 - .../java/io/bitsquare/msg/ActorService.java | 86 ----------- .../java/io/bitsquare/msg/DHTSeedService.java | 41 ------ .../java/io/bitsquare/msg/MessageModule.java | 3 - .../io/bitsquare/msg/actor/DHTManager.java | 135 ------------------ .../msg/actor/command/InitializePeer.java | 60 -------- .../msg/actor/event/PeerInitialized.java | 43 ------ .../trade/taker/SellerTakesOfferProtocol.java | 2 +- src/main/resources/application.conf | 17 --- 13 files changed, 1 insertion(+), 517 deletions(-) delete mode 100644 src/main/java/io/bitsquare/app/cli/SeedNodeUsingAkka.java delete mode 100644 src/main/java/io/bitsquare/msg/ActorService.java delete mode 100644 src/main/java/io/bitsquare/msg/DHTSeedService.java delete mode 100644 src/main/java/io/bitsquare/msg/actor/DHTManager.java delete mode 100644 src/main/java/io/bitsquare/msg/actor/command/InitializePeer.java delete mode 100644 src/main/java/io/bitsquare/msg/actor/event/PeerInitialized.java delete mode 100644 src/main/resources/application.conf diff --git a/build.gradle b/build.gradle index 1f79bce7c1..c221fd02d7 100644 --- a/build.gradle +++ b/build.gradle @@ -33,7 +33,6 @@ repositories { dependencies { compile 'org.bitcoinj:bitcoinj-core:0.12' compile 'net.tomp2p:tomp2p-all:5.0-Alpha.32cd9f9-SNAPSHOT' - compile 'com.typesafe.akka:akka-actor_2.10:2.3.4' compile 'org.slf4j:slf4j-api:1.7.7' compile 'ch.qos.logback:logback-core:1.1.2' compile 'ch.qos.logback:logback-classic:1.1.2' diff --git a/src/main/java/io/bitsquare/app/AppModule.java b/src/main/java/io/bitsquare/app/AppModule.java index a293be984d..025e23c2ac 100644 --- a/src/main/java/io/bitsquare/app/AppModule.java +++ b/src/main/java/io/bitsquare/app/AppModule.java @@ -38,17 +38,10 @@ import java.util.Properties; import net.tomp2p.connection.Ports; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import akka.actor.ActorSystem; -import scala.concurrent.duration.Duration; - /** * Configures all non-UI modules necessary to run a Bitsquare application. */ public class AppModule extends BitsquareModule { - private static final Logger log = LoggerFactory.getLogger(AppModule.class); public AppModule(Properties properties) { super(properties); @@ -70,7 +63,6 @@ public class AppModule extends BitsquareModule { Preconditions.checkArgument(appName != null, "App name must be non-null"); bindConstant().annotatedWith(Names.named("appName")).to(appName); - bind(ActorSystem.class).toInstance(ActorSystem.create(appName)); int randomPort = new Ports().tcpPort(); bindConstant().annotatedWith(Names.named("clientPort")).to(randomPort); @@ -98,13 +90,6 @@ public class AppModule extends BitsquareModule { @Override protected void doClose(Injector injector) { - ActorSystem actorSystem = injector.getInstance(ActorSystem.class); - actorSystem.shutdown(); - try { - actorSystem.awaitTermination(Duration.create(5L, "seconds")); - } catch (Exception ex) { - log.error("Actor system failed to shut down properly", ex); - } } } diff --git a/src/main/java/io/bitsquare/app/ArgumentParser.java b/src/main/java/io/bitsquare/app/ArgumentParser.java index e24caff2aa..49f1d1896a 100644 --- a/src/main/java/io/bitsquare/app/ArgumentParser.java +++ b/src/main/java/io/bitsquare/app/ArgumentParser.java @@ -26,7 +26,6 @@ public class ArgumentParser { public static final String SEED_ID_FLAG = "id"; public static final String SEED_IP_FLAG = "ip"; public static final String SEED_PORT_FLAG = "port"; - public static final String INTERFACE_HINT_FLAG = "interface"; public static final String NAME_FLAG = "name"; private final net.sourceforge.argparse4j.inf.ArgumentParser parser; @@ -43,8 +42,6 @@ public class ArgumentParser { .help("Seed node IP"); parser.addArgument("-p", "--" + SEED_PORT_FLAG) .help("Seed node port"); - parser.addArgument("-i", "--" + INTERFACE_HINT_FLAG) - .help("Network interface to listen on"); // Args for app config parser.addArgument("-n", "--" + NAME_FLAG) diff --git a/src/main/java/io/bitsquare/app/cli/SeedNodeUsingAkka.java b/src/main/java/io/bitsquare/app/cli/SeedNodeUsingAkka.java deleted file mode 100644 index 881ecd6a9b..0000000000 --- a/src/main/java/io/bitsquare/app/cli/SeedNodeUsingAkka.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * 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.app.cli; - -import io.bitsquare.app.ArgumentParser; -import io.bitsquare.msg.actor.DHTManager; -import io.bitsquare.msg.actor.command.InitializePeer; -import io.bitsquare.msg.actor.event.PeerInitialized; -import io.bitsquare.network.BootstrapNodes; -import io.bitsquare.network.Node; - -import java.net.UnknownHostException; - -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.TimeoutException; - -import net.tomp2p.peers.Number160; -import net.tomp2p.peers.PeerAddress; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import akka.actor.ActorRef; -import akka.actor.ActorSystem; -import akka.actor.Inbox; -import net.sourceforge.argparse4j.inf.Namespace; -import scala.concurrent.duration.Duration; -import scala.concurrent.duration.FiniteDuration; - -public class SeedNodeUsingAkka { - private static final Logger log = LoggerFactory.getLogger(SeedNodeUsingAkka.class); - - private static String interfaceHint; - - public static void main(String[] args) { - ArgumentParser parser = new ArgumentParser(); - Namespace namespace = parser.parseArgs(args); - - if (namespace.getString(ArgumentParser.INTERFACE_HINT_FLAG) != null) - interfaceHint = namespace.getString(ArgumentParser.INTERFACE_HINT_FLAG); - - int serverPort = Integer.valueOf(namespace.getString(ArgumentParser.SEED_PORT_FLAG)); - String seedID = BootstrapNodes.LOCALHOST.getId(); - if (namespace.getString(ArgumentParser.SEED_ID_FLAG) != null) { - seedID = namespace.getString(ArgumentParser.SEED_ID_FLAG); - } - - final Set peerAddresses = new HashSet<>(); - for (Node node : BootstrapNodes.all()) { - if (!node.getId().equals(seedID)) { - try { - peerAddresses.add(new PeerAddress(Number160.createHash(node.getId()), node.getIp(), - node.getPort(), node.getPort())); - } catch (UnknownHostException uhe) { - log.error("Unknown Host [" + node.getIp() + "]: " + uhe.getMessage()); - } - } - } - - ActorSystem actorSystem = ActorSystem.create("BitsquareSeedNode"); - Inbox inbox = Inbox.create(actorSystem); - ActorRef seedNode = actorSystem.actorOf(DHTManager.getProps(), DHTManager.SEED_NODE); - inbox.send(seedNode, new InitializePeer(Number160.createHash(seedID), serverPort, interfaceHint, - peerAddresses)); - - final String _seedID = seedID; - 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 with ID " + _seedID + - " 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(); - } -} diff --git a/src/main/java/io/bitsquare/btc/WalletFacade.java b/src/main/java/io/bitsquare/btc/WalletFacade.java index e403024df1..91e5ead604 100644 --- a/src/main/java/io/bitsquare/btc/WalletFacade.java +++ b/src/main/java/io/bitsquare/btc/WalletFacade.java @@ -91,7 +91,6 @@ import static org.bitcoinj.script.ScriptOpCodes.OP_RETURN; /** * TODO: use walletextension (with protobuffer) instead of saving addressEntryList via storage * TODO: break that class up. maybe a bitsquarewallet - * Wait until steve's akka version to see how to continue here */ public class WalletFacade { private static final Logger log = LoggerFactory.getLogger(WalletFacade.class); diff --git a/src/main/java/io/bitsquare/msg/ActorService.java b/src/main/java/io/bitsquare/msg/ActorService.java deleted file mode 100644 index e4f6ea4654..0000000000 --- a/src/main/java/io/bitsquare/msg/ActorService.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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.msg; - -import io.bitsquare.util.MessageHandler; - -import javafx.concurrent.Service; -import javafx.concurrent.Task; - -import akka.actor.ActorSelection; -import akka.actor.ActorSystem; -import akka.actor.Inbox; -import akka.event.Logging; -import akka.event.LoggingAdapter; -import com.sun.glass.ui.Application; -import scala.concurrent.duration.FiniteDuration; - -public abstract class ActorService extends Service { - - private final LoggingAdapter log; - - private final ActorSystem system; - private final Inbox inbox; - private final ActorSelection actor; - - private MessageHandler handler; - - protected ActorService(ActorSystem system, String actorPath) { - this.log = Logging.getLogger(system, this); - this.system = system; - this.inbox = Inbox.create(system); - this.actor = system.actorSelection(actorPath); - log.debug(actor.pathString()); - this.start(); - } - - public void setHandler(MessageHandler handler) { - this.handler = handler; - } - - public void send(Object command) { - if (actor != null) { - actor.tell(command, inbox.getRef()); - } - } - - protected Task createTask() { - - return new Task() { - protected String call() throws Exception { - - while (!isCancelled()) { - if (inbox != null) { - try { - Object result = inbox.receive(FiniteDuration.create(1l, "minute")); - if (result != null) { - System.out.println(result.toString()); - if (handler != null) { - Application.invokeLater(() -> handler.handle(result)); - } - } - } catch (Exception e) { - //System.out.println(e.toString()); - } - } - } - return null; - } - }; - } -} diff --git a/src/main/java/io/bitsquare/msg/DHTSeedService.java b/src/main/java/io/bitsquare/msg/DHTSeedService.java deleted file mode 100644 index 7ee0b10999..0000000000 --- a/src/main/java/io/bitsquare/msg/DHTSeedService.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.msg; - -import io.bitsquare.msg.actor.DHTManager; -import io.bitsquare.msg.actor.command.InitializePeer; - -import com.google.inject.Inject; - -import net.tomp2p.peers.Number160; - -import akka.actor.ActorSystem; - -public class DHTSeedService extends ActorService { - - @Inject - public DHTSeedService(ActorSystem system) { - super(system, "/user/" + DHTManager.SEED_NODE); - } - - public void initializePeer(String id, Integer port) { - - // TODO hard coded seed peer config for now, should read from config properties file - send(new InitializePeer(Number160.createHash(id), port, null, null)); - } -} diff --git a/src/main/java/io/bitsquare/msg/MessageModule.java b/src/main/java/io/bitsquare/msg/MessageModule.java index d86e448d6c..8fb8b26d55 100644 --- a/src/main/java/io/bitsquare/msg/MessageModule.java +++ b/src/main/java/io/bitsquare/msg/MessageModule.java @@ -18,8 +18,6 @@ package io.bitsquare.msg; import io.bitsquare.BitsquareModule; -import io.bitsquare.app.ArgumentParser; -import io.bitsquare.network.BootstrapNodes; import io.bitsquare.network.Node; import com.google.inject.Injector; @@ -39,7 +37,6 @@ public abstract class MessageModule extends BitsquareModule { @Override protected final void configure() { bind(MessageFacade.class).to(messageFacade()).asEagerSingleton(); - bind(DHTSeedService.class); // we will probably later use disk storage instead of memory storage for TomP2P bind(Boolean.class).annotatedWith(Names.named("useDiskStorage")).toInstance(false); diff --git a/src/main/java/io/bitsquare/msg/actor/DHTManager.java b/src/main/java/io/bitsquare/msg/actor/DHTManager.java deleted file mode 100644 index ad7355677d..0000000000 --- a/src/main/java/io/bitsquare/msg/actor/DHTManager.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * 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.msg.actor; - -import io.bitsquare.msg.actor.command.InitializePeer; -import io.bitsquare.msg.actor.event.PeerInitialized; - -import net.tomp2p.connection.Bindings; -import net.tomp2p.connection.StandardProtocolFamily; -import net.tomp2p.dht.PeerBuilderDHT; -import net.tomp2p.dht.PeerDHT; -import net.tomp2p.nat.PeerBuilderNAT; -import net.tomp2p.nat.PeerNAT; -import net.tomp2p.p2p.Peer; -import net.tomp2p.p2p.PeerBuilder; -import net.tomp2p.peers.PeerAddress; -import net.tomp2p.peers.PeerMapChangeListener; -import net.tomp2p.peers.PeerStatistic; - -import akka.actor.AbstractActor; -import akka.actor.Props; -import akka.event.Logging; -import akka.event.LoggingAdapter; -import akka.japi.pf.ReceiveBuilder; - -public class DHTManager extends AbstractActor { - - public static final String MY_NODE = "myNodeDhtManager"; - public static final String SEED_NODE = "seedNodeDhtManager"; - - private final LoggingAdapter log = Logging.getLogger(context().system(), this); - - // TODO move into app setup - // timeout in ms - private final Long bootstrapTimeout = 10000L; - - public static Props getProps() { - return Props.create(DHTManager.class); - } - - private PeerDHT peerDHT; - private PeerNAT peerNAT; - - public DHTManager() { - receive(ReceiveBuilder - .match(InitializePeer.class, this::doInitializePeer) - .matchAny(o -> log.info("received unknown message")).build() - ); - } - - private void doInitializePeer(InitializePeer initializePeer) { - log.debug("Received message: {}", initializePeer); - - try { - Bindings bindings = new Bindings(); - bindings.addProtocol(StandardProtocolFamily.INET); - - if (initializePeer.getInterfaceHint() != null) { - bindings.addInterface(initializePeer.getInterfaceHint()); - } - - Peer peer = new PeerBuilder(initializePeer.getPeerId()).ports(initializePeer.getPort()).bindings(bindings) - .start(); - peer.objectDataReply((sender, request) -> { - log.debug("received request: ", request.toString()); - return "pong"; - }); - - // For the moment we want not to bootstrap to other seed nodes to keep test scenarios - // simple - /* if (ip.getBootstrapPeers() != null && ip.getBootstrapPeers().size() > 0) { - peer.bootstrap().bootstrapTo(ip.getBootstrapPeers()).start(); - }*/ - - // Needed for DHT support - peerDHT = new PeerBuilderDHT(peer).start(); - // Needed for NAT support - peerNAT = new PeerBuilderNAT(peer).start(); - - new PeerBuilderNAT(peer).start(); - peer.peerBean().peerMap().addPeerMapChangeListener(new PeerMapChangeListener() { - @Override - public void peerInserted(PeerAddress peerAddress, boolean verified) { - log.debug("Peer inserted: peerAddress=" + peerAddress + ", " + - "verified=" + verified); - } - - @Override - public void peerRemoved(PeerAddress peerAddress, PeerStatistic peerStatistics) { - log.debug("Peer removed: peerAddress=" + peerAddress + ", " + - "peerStatistics=" + peerStatistics); - } - - @Override - public void peerUpdated(PeerAddress peerAddress, PeerStatistic peerStatistics) { - // log.debug("Peer updated: peerAddress=" + peerAddress + ", - // peerStatistics=" + peerStatistics); - } - }); - - sender().tell(new PeerInitialized(peer.peerID(), initializePeer.getPort()), self()); - } catch (Throwable t) { - log.error(t.getMessage()); - } - } - - - @Override - public void postStop() throws Exception { - log.debug("postStop"); - if (peerDHT != null) - peerDHT.shutdown(); - - if (peerNAT != null) - peerNAT.natUtils().shutdown(); - - super.postStop(); - } -} - diff --git a/src/main/java/io/bitsquare/msg/actor/command/InitializePeer.java b/src/main/java/io/bitsquare/msg/actor/command/InitializePeer.java deleted file mode 100644 index 38f70ac393..0000000000 --- a/src/main/java/io/bitsquare/msg/actor/command/InitializePeer.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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.msg.actor.command; - - -import java.util.Collection; - -import net.tomp2p.peers.Number160; -import net.tomp2p.peers.PeerAddress; - -/** - *

Command to initialize TomP2P Peer.

- */ -public class InitializePeer { - - private final Number160 peerId; - private final Integer port; - private final String interfaceHint; - - private final Collection bootstrapPeers; - - public InitializePeer(Number160 peerId, Integer port, String interfaceHint, - Collection bootstrapPeers) { - this.peerId = peerId; - this.port = port; - this.interfaceHint = interfaceHint; - this.bootstrapPeers = bootstrapPeers; - } - - public Number160 getPeerId() { - return peerId; - } - - public Integer getPort() { - return port; - } - - public String getInterfaceHint() { - return interfaceHint; - } - - public Collection getBootstrapPeers() { - return bootstrapPeers; - } -} diff --git a/src/main/java/io/bitsquare/msg/actor/event/PeerInitialized.java b/src/main/java/io/bitsquare/msg/actor/event/PeerInitialized.java deleted file mode 100644 index 82c4dd0cd0..0000000000 --- a/src/main/java/io/bitsquare/msg/actor/event/PeerInitialized.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.msg.actor.event; - - -import net.tomp2p.peers.Number160; - -/** - *

TomP2P Peer Initialized event.

- */ -public class PeerInitialized { - - private final Number160 peerId; - private final Integer port; - - 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/trade/protocol/trade/taker/SellerTakesOfferProtocol.java b/src/main/java/io/bitsquare/trade/protocol/trade/taker/SellerTakesOfferProtocol.java index 431cf2415a..0bb005a9e9 100644 --- a/src/main/java/io/bitsquare/trade/protocol/trade/taker/SellerTakesOfferProtocol.java +++ b/src/main/java/io/bitsquare/trade/protocol/trade/taker/SellerTakesOfferProtocol.java @@ -319,7 +319,7 @@ public class SellerTakesOfferProtocol { log.debug("state " + state); checkState(state.ordinal() >= State.SendSignedTakerDepositTxAsHex.ordinal()); checkArgument(tradeId.equals(message.getTradeId())); - //TODO takerCommitDepositTx should be in task as well, but will be probably changed anyway when akka is used... + //TODO takerCommitDepositTx should be in task as well Transaction tx = walletFacade.takerCommitDepositTx(message.getDepositTxAsHex()); listener.onDepositTxPublished(tx); } diff --git a/src/main/resources/application.conf b/src/main/resources/application.conf deleted file mode 100644 index ce3f33cf7c..0000000000 --- a/src/main/resources/application.conf +++ /dev/null @@ -1,17 +0,0 @@ -akka { - - # Loggers to register at boot time (akka.event.Logging$DefaultLogger logs - # to STDOUT) - #loggers = ["akka.event.slf4j.Slf4jLogger"] - - # Log level used by the configured loggers (see "loggers") as soon - # as they have been started; before that, see "stdout-loglevel" - # Options: OFF, ERROR, WARNING, INFO, DEBUG - loglevel = "DEBUG" - - # Log level for the very basic logger activated during ActorSystem startup. - # This logger prints the log messages to stdout (System.out). - # Options: OFF, ERROR, WARNING, INFO, DEBUG - stdout-loglevel = "DEBUG" - -} \ No newline at end of file From 18c399b30c891ab44160064641c7571514eb2773 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Mon, 10 Nov 2014 00:40:33 +0100 Subject: [PATCH 2/6] Move bootstrap node config property keys to MessageModule --- .../java/io/bitsquare/app/ArgumentParser.java | 11 +++++------ src/main/java/io/bitsquare/app/cli/SeedNode.java | 10 ++++++---- src/main/java/io/bitsquare/app/gui/Main.java | 15 ++++++++------- src/main/java/io/bitsquare/msg/MessageModule.java | 11 +++++++---- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/main/java/io/bitsquare/app/ArgumentParser.java b/src/main/java/io/bitsquare/app/ArgumentParser.java index 49f1d1896a..ebac781b87 100644 --- a/src/main/java/io/bitsquare/app/ArgumentParser.java +++ b/src/main/java/io/bitsquare/app/ArgumentParser.java @@ -21,11 +21,10 @@ import net.sourceforge.argparse4j.ArgumentParsers; import net.sourceforge.argparse4j.inf.ArgumentParserException; import net.sourceforge.argparse4j.inf.Namespace; +import static io.bitsquare.msg.MessageModule.*; + public class ArgumentParser { - public static final String SEED_ID_FLAG = "id"; - public static final String SEED_IP_FLAG = "ip"; - public static final String SEED_PORT_FLAG = "port"; public static final String NAME_FLAG = "name"; private final net.sourceforge.argparse4j.inf.ArgumentParser parser; @@ -36,11 +35,11 @@ public class ArgumentParser { .description("Bitsquare - The decentralized bitcoin exchange"); // Args for seed node config - parser.addArgument("-d", "--" + SEED_ID_FLAG) + parser.addArgument("-d", "--" + BOOTSTRAP_NODE_ID_KEY) .help("Seed node ID"); - parser.addArgument("-s", "--" + SEED_IP_FLAG) + parser.addArgument("-s", "--" + BOOTSTRAP_NODE_IP_KEY) .help("Seed node IP"); - parser.addArgument("-p", "--" + SEED_PORT_FLAG) + parser.addArgument("-p", "--" + BOOTSTRAP_NODE_PORT_KEY) .help("Seed node port"); // Args for app config diff --git a/src/main/java/io/bitsquare/app/cli/SeedNode.java b/src/main/java/io/bitsquare/app/cli/SeedNode.java index 38a5d4ac09..d148f91d56 100644 --- a/src/main/java/io/bitsquare/app/cli/SeedNode.java +++ b/src/main/java/io/bitsquare/app/cli/SeedNode.java @@ -36,6 +36,8 @@ import org.slf4j.LoggerFactory; import net.sourceforge.argparse4j.inf.Namespace; +import static io.bitsquare.msg.MessageModule.*; + public class SeedNode { private static final Logger log = LoggerFactory.getLogger(SeedNode.class); @@ -53,11 +55,11 @@ public class SeedNode { // Passed program args will override the properties of the default bootstrapNode // So you can use the same id but different ports (e.g. running several nodes on one server with // different ports) - if (namespace.getString(ArgumentParser.SEED_ID_FLAG) != null) - id = namespace.getString(ArgumentParser.SEED_ID_FLAG); + if (namespace.getString(BOOTSTRAP_NODE_ID_KEY) != null) + id = namespace.getString(BOOTSTRAP_NODE_ID_KEY); - if (namespace.getString(ArgumentParser.SEED_PORT_FLAG) != null) - port = Integer.valueOf(namespace.getString(ArgumentParser.SEED_PORT_FLAG)); + if (namespace.getString(BOOTSTRAP_NODE_PORT_KEY) != null) + port = Integer.valueOf(namespace.getString(BOOTSTRAP_NODE_PORT_KEY)); try { Number160 peerId = Number160.createHash(id); diff --git a/src/main/java/io/bitsquare/app/gui/Main.java b/src/main/java/io/bitsquare/app/gui/Main.java index 3936c107cf..a40c4f5d2d 100644 --- a/src/main/java/io/bitsquare/app/gui/Main.java +++ b/src/main/java/io/bitsquare/app/gui/Main.java @@ -49,7 +49,8 @@ import org.slf4j.LoggerFactory; import lighthouse.files.AppDirectory; import net.sourceforge.argparse4j.inf.Namespace; -import static io.bitsquare.app.ArgumentParser.*; +import static io.bitsquare.app.ArgumentParser.NAME_FLAG; +import static io.bitsquare.msg.MessageModule.*; public class Main extends Application { private static final Logger log = LoggerFactory.getLogger(Main.class); @@ -69,14 +70,14 @@ public class Main extends Application { properties.setProperty(NAME_FLAG, appName); - if (argumentsNamespace.getString(SEED_ID_FLAG) != null) - properties.setProperty(SEED_ID_FLAG, argumentsNamespace.getString(SEED_ID_FLAG)); + if (argumentsNamespace.getString(BOOTSTRAP_NODE_ID_KEY) != null) + properties.setProperty(BOOTSTRAP_NODE_ID_KEY, argumentsNamespace.getString(BOOTSTRAP_NODE_ID_KEY)); - if (argumentsNamespace.getString(SEED_IP_FLAG) != null) - properties.setProperty(SEED_IP_FLAG, argumentsNamespace.getString(SEED_IP_FLAG)); + if (argumentsNamespace.getString(BOOTSTRAP_NODE_IP_KEY) != null) + properties.setProperty(BOOTSTRAP_NODE_IP_KEY, argumentsNamespace.getString(BOOTSTRAP_NODE_IP_KEY)); - if (argumentsNamespace.getString(SEED_PORT_FLAG) != null) - properties.setProperty(SEED_PORT_FLAG, argumentsNamespace.getString(SEED_PORT_FLAG)); + if (argumentsNamespace.getString(BOOTSTRAP_NODE_PORT_KEY) != null) + properties.setProperty(BOOTSTRAP_NODE_PORT_KEY, argumentsNamespace.getString(BOOTSTRAP_NODE_PORT_KEY)); Application.launch(Main.class, args); } diff --git a/src/main/java/io/bitsquare/msg/MessageModule.java b/src/main/java/io/bitsquare/msg/MessageModule.java index 8fb8b26d55..e9d7323279 100644 --- a/src/main/java/io/bitsquare/msg/MessageModule.java +++ b/src/main/java/io/bitsquare/msg/MessageModule.java @@ -25,11 +25,14 @@ import com.google.inject.name.Names; import java.util.Properties; -import static io.bitsquare.app.ArgumentParser.*; import static io.bitsquare.network.BootstrapNodes.DEFAULT_BOOTSTRAP_NODE; public abstract class MessageModule extends BitsquareModule { + public static final String BOOTSTRAP_NODE_ID_KEY = "id"; + public static final String BOOTSTRAP_NODE_IP_KEY = "ip"; + public static final String BOOTSTRAP_NODE_PORT_KEY = "port"; + protected MessageModule(Properties properties) { super(properties); } @@ -42,9 +45,9 @@ public abstract class MessageModule extends BitsquareModule { bind(Boolean.class).annotatedWith(Names.named("useDiskStorage")).toInstance(false); Node bootstrapNode = Node.at( - properties.getProperty(SEED_ID_FLAG, DEFAULT_BOOTSTRAP_NODE.getId()), - properties.getProperty(SEED_IP_FLAG, DEFAULT_BOOTSTRAP_NODE.getIp()), - properties.getProperty(SEED_PORT_FLAG, DEFAULT_BOOTSTRAP_NODE.getPortAsString()) + properties.getProperty(BOOTSTRAP_NODE_ID_KEY, DEFAULT_BOOTSTRAP_NODE.getId()), + properties.getProperty(BOOTSTRAP_NODE_IP_KEY, DEFAULT_BOOTSTRAP_NODE.getIp()), + properties.getProperty(BOOTSTRAP_NODE_PORT_KEY, DEFAULT_BOOTSTRAP_NODE.getPortAsString()) ); bind(Node.class) From a4cf7a0aeb5bff71399f8d329d907ff708bae00e Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Mon, 10 Nov 2014 00:41:36 +0100 Subject: [PATCH 3/6] Polish whitespace --- src/main/java/io/bitsquare/app/cli/SeedNode.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/bitsquare/app/cli/SeedNode.java b/src/main/java/io/bitsquare/app/cli/SeedNode.java index d148f91d56..aebd7b731b 100644 --- a/src/main/java/io/bitsquare/app/cli/SeedNode.java +++ b/src/main/java/io/bitsquare/app/cli/SeedNode.java @@ -53,7 +53,7 @@ public class SeedNode { int port = defaultNode.getPort(); // Passed program args will override the properties of the default bootstrapNode - // So you can use the same id but different ports (e.g. running several nodes on one server with + // So you can use the same id but different ports (e.g. running several nodes on one server with // different ports) if (namespace.getString(BOOTSTRAP_NODE_ID_KEY) != null) id = namespace.getString(BOOTSTRAP_NODE_ID_KEY); @@ -108,8 +108,8 @@ public class SeedNode { } peer = null; } - - + + /*public static void main(String[] args) throws Exception { ArgumentParser parser = new ArgumentParser(); Namespace namespace = parser.parseArgs(args); @@ -119,7 +119,7 @@ public class SeedNode { int port = defaultNode.getPort(); // Passed program args will override the properties of the default bootstrapNode - // So you can use the same id but different ports (e.g. running several nodes on one server with + // So you can use the same id but different ports (e.g. running several nodes on one server with // different ports) if (namespace.getString(ArgumentParser.SEED_ID_FLAG) != null) id = namespace.getString(ArgumentParser.SEED_ID_FLAG); From 935785e611e99a440fbe11e0fa1db8896b40ece6 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Mon, 10 Nov 2014 00:42:27 +0100 Subject: [PATCH 4/6] Organize imports --- src/test/java/io/bitsquare/app/gui/ViewLoaderTests.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/test/java/io/bitsquare/app/gui/ViewLoaderTests.java b/src/test/java/io/bitsquare/app/gui/ViewLoaderTests.java index 8611b91bf2..3285799b6d 100644 --- a/src/test/java/io/bitsquare/app/gui/ViewLoaderTests.java +++ b/src/test/java/io/bitsquare/app/gui/ViewLoaderTests.java @@ -25,7 +25,6 @@ import io.bitsquare.gui.ViewLoader; import com.google.inject.Guice; import com.google.inject.Injector; -import java.util.HashMap; import java.util.Properties; import javafx.application.Application; @@ -36,8 +35,6 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import net.sourceforge.argparse4j.inf.Namespace; - public class ViewLoaderTests { public static class TestApp extends Application { From e8986aa7a29697e907118e9c2889cc223b7beabe Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Mon, 10 Nov 2014 00:50:59 +0100 Subject: [PATCH 5/6] Rename NAME_FLAG => APP_NAME_KEY and move to AppModule --- src/main/java/io/bitsquare/app/AppModule.java | 3 ++- src/main/java/io/bitsquare/app/ArgumentParser.java | 5 ++--- src/main/java/io/bitsquare/app/gui/Main.java | 8 ++++---- src/test/java/io/bitsquare/app/gui/ViewLoaderTests.java | 5 +++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/io/bitsquare/app/AppModule.java b/src/main/java/io/bitsquare/app/AppModule.java index 025e23c2ac..e2d802fa3c 100644 --- a/src/main/java/io/bitsquare/app/AppModule.java +++ b/src/main/java/io/bitsquare/app/AppModule.java @@ -42,6 +42,7 @@ import net.tomp2p.connection.Ports; * Configures all non-UI modules necessary to run a Bitsquare application. */ public class AppModule extends BitsquareModule { + public static final String APP_NAME_KEY = "name"; public AppModule(Properties properties) { super(properties); @@ -59,7 +60,7 @@ public class AppModule extends BitsquareModule { install(tradeModule()); install(offerModule()); - String appName = properties.getProperty(ArgumentParser.NAME_FLAG); + String appName = properties.getProperty(APP_NAME_KEY); Preconditions.checkArgument(appName != null, "App name must be non-null"); bindConstant().annotatedWith(Names.named("appName")).to(appName); diff --git a/src/main/java/io/bitsquare/app/ArgumentParser.java b/src/main/java/io/bitsquare/app/ArgumentParser.java index ebac781b87..506435e7a3 100644 --- a/src/main/java/io/bitsquare/app/ArgumentParser.java +++ b/src/main/java/io/bitsquare/app/ArgumentParser.java @@ -21,12 +21,11 @@ import net.sourceforge.argparse4j.ArgumentParsers; import net.sourceforge.argparse4j.inf.ArgumentParserException; import net.sourceforge.argparse4j.inf.Namespace; +import static io.bitsquare.app.AppModule.APP_NAME_KEY; import static io.bitsquare.msg.MessageModule.*; public class ArgumentParser { - public static final String NAME_FLAG = "name"; - private final net.sourceforge.argparse4j.inf.ArgumentParser parser; public ArgumentParser() { @@ -43,7 +42,7 @@ public class ArgumentParser { .help("Seed node port"); // Args for app config - parser.addArgument("-n", "--" + NAME_FLAG) + parser.addArgument("-n", "--" + APP_NAME_KEY) .help("Name to append to default application name"); } diff --git a/src/main/java/io/bitsquare/app/gui/Main.java b/src/main/java/io/bitsquare/app/gui/Main.java index a40c4f5d2d..2aedf903a9 100644 --- a/src/main/java/io/bitsquare/app/gui/Main.java +++ b/src/main/java/io/bitsquare/app/gui/Main.java @@ -49,7 +49,7 @@ import org.slf4j.LoggerFactory; import lighthouse.files.AppDirectory; import net.sourceforge.argparse4j.inf.Namespace; -import static io.bitsquare.app.ArgumentParser.NAME_FLAG; +import static io.bitsquare.app.AppModule.APP_NAME_KEY; import static io.bitsquare.msg.MessageModule.*; public class Main extends Application { @@ -63,12 +63,12 @@ public class Main extends Application { public static void main(String[] args) { Namespace argumentsNamespace = new ArgumentParser().parseArgs(args); - if (argumentsNamespace.getString(NAME_FLAG) != null) - appName = appName + "-" + argumentsNamespace.getString(NAME_FLAG); + if (argumentsNamespace.getString(APP_NAME_KEY) != null) + appName = appName + "-" + argumentsNamespace.getString(APP_NAME_KEY); properties = ConfigLoader.loadConfig(appName); - properties.setProperty(NAME_FLAG, appName); + properties.setProperty(APP_NAME_KEY, appName); if (argumentsNamespace.getString(BOOTSTRAP_NODE_ID_KEY) != null) properties.setProperty(BOOTSTRAP_NODE_ID_KEY, argumentsNamespace.getString(BOOTSTRAP_NODE_ID_KEY)); diff --git a/src/test/java/io/bitsquare/app/gui/ViewLoaderTests.java b/src/test/java/io/bitsquare/app/gui/ViewLoaderTests.java index 3285799b6d..b766d5aab0 100644 --- a/src/test/java/io/bitsquare/app/gui/ViewLoaderTests.java +++ b/src/test/java/io/bitsquare/app/gui/ViewLoaderTests.java @@ -17,7 +17,6 @@ package io.bitsquare.app.gui; -import io.bitsquare.app.ArgumentParser; import io.bitsquare.gui.FatalException; import io.bitsquare.gui.Navigation; import io.bitsquare.gui.ViewLoader; @@ -35,6 +34,8 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import static io.bitsquare.app.AppModule.APP_NAME_KEY; + public class ViewLoaderTests { public static class TestApp extends Application { @@ -63,7 +64,7 @@ public class ViewLoaderTests { @Before public void setUp() { Properties properties = new Properties(); - properties.setProperty(ArgumentParser.NAME_FLAG, "testApp"); + properties.setProperty(APP_NAME_KEY, "testApp"); Injector injector = Guice.createInjector(new MainModule(properties, TestApp.primaryStage)); ViewLoader.setInjector(injector); } From ccc369307cffa7564e6c3dbd76dcc7cbb70f987b Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Mon, 10 Nov 2014 01:08:34 +0100 Subject: [PATCH 6/6] Use explicit "appName" vs. "name" property i.e. when running the app, pass java -jar bitsquare.jar --appName Alice vs. java -jar bitsquare.jar --name Alice --- src/main/java/io/bitsquare/app/AppModule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/bitsquare/app/AppModule.java b/src/main/java/io/bitsquare/app/AppModule.java index e2d802fa3c..e7f34d289a 100644 --- a/src/main/java/io/bitsquare/app/AppModule.java +++ b/src/main/java/io/bitsquare/app/AppModule.java @@ -42,7 +42,7 @@ import net.tomp2p.connection.Ports; * Configures all non-UI modules necessary to run a Bitsquare application. */ public class AppModule extends BitsquareModule { - public static final String APP_NAME_KEY = "name"; + public static final String APP_NAME_KEY = "appName"; public AppModule(Properties properties) { super(properties);