From 18c399b30c891ab44160064641c7571514eb2773 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Mon, 10 Nov 2014 00:40:33 +0100 Subject: [PATCH] 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)