From 05a86f251f589b7e395cfa5747893dddc4d68fa2 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Mon, 10 Nov 2014 02:08:54 +0100 Subject: [PATCH] Add interface argument --- src/main/java/io/bitsquare/app/ArgumentParser.java | 4 ++++ src/main/java/io/bitsquare/app/gui/Main.java | 3 +++ src/main/java/io/bitsquare/msg/MessageModule.java | 5 +++++ .../msg/tomp2p/BootstrappedPeerFactory.java | 13 +++++++++++-- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/bitsquare/app/ArgumentParser.java b/src/main/java/io/bitsquare/app/ArgumentParser.java index 506435e7a3..a685c7ef72 100644 --- a/src/main/java/io/bitsquare/app/ArgumentParser.java +++ b/src/main/java/io/bitsquare/app/ArgumentParser.java @@ -41,6 +41,10 @@ public class ArgumentParser { parser.addArgument("-p", "--" + BOOTSTRAP_NODE_PORT_KEY) .help("Seed node port"); + // A custom network interface (needed at the moment for windows, but might be useful also later) + parser.addArgument("-i", "--" + NETWORK_INTERFACE_KEY) + .help("Network interface"); + // Args for app config 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 2aedf903a9..7d11f36d06 100644 --- a/src/main/java/io/bitsquare/app/gui/Main.java +++ b/src/main/java/io/bitsquare/app/gui/Main.java @@ -79,6 +79,9 @@ public class Main extends Application { if (argumentsNamespace.getString(BOOTSTRAP_NODE_PORT_KEY) != null) properties.setProperty(BOOTSTRAP_NODE_PORT_KEY, argumentsNamespace.getString(BOOTSTRAP_NODE_PORT_KEY)); + if (argumentsNamespace.getString(NETWORK_INTERFACE_KEY) != null) + properties.setProperty(NETWORK_INTERFACE_KEY, argumentsNamespace.getString(NETWORK_INTERFACE_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 e9d7323279..d2f7976d11 100644 --- a/src/main/java/io/bitsquare/msg/MessageModule.java +++ b/src/main/java/io/bitsquare/msg/MessageModule.java @@ -32,6 +32,7 @@ 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"; + public static final String NETWORK_INTERFACE_KEY = "networkInterface"; protected MessageModule(Properties properties) { super(properties); @@ -54,6 +55,10 @@ public abstract class MessageModule extends BitsquareModule { .annotatedWith(Names.named("bootstrapNode")) .toInstance(bootstrapNode); + bind(String.class) + .annotatedWith(Names.named("networkInterface")) + .toInstance(properties.getProperty(NETWORK_INTERFACE_KEY, "")); + doConfigure(); } diff --git a/src/main/java/io/bitsquare/msg/tomp2p/BootstrappedPeerFactory.java b/src/main/java/io/bitsquare/msg/tomp2p/BootstrappedPeerFactory.java index d5da3da64c..a13a12856e 100644 --- a/src/main/java/io/bitsquare/msg/tomp2p/BootstrappedPeerFactory.java +++ b/src/main/java/io/bitsquare/msg/tomp2p/BootstrappedPeerFactory.java @@ -39,6 +39,7 @@ import javafx.application.Platform; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleObjectProperty; +import net.tomp2p.connection.Bindings; import net.tomp2p.connection.ChannelClientConfiguration; import net.tomp2p.dht.PeerBuilderDHT; import net.tomp2p.dht.PeerDHT; @@ -76,6 +77,7 @@ class BootstrappedPeerFactory { private KeyPair keyPair; private Storage storage; private final Node bootstrapNode; + private String networkInterface; private final Persistence persistence; private final SettableFuture settableFuture = SettableFuture.create(); @@ -89,9 +91,11 @@ class BootstrappedPeerFactory { /////////////////////////////////////////////////////////////////////////////////////////// @Inject - public BootstrappedPeerFactory(Persistence persistence, @Named("bootstrapNode") Node bootstrapNode) { + public BootstrappedPeerFactory(Persistence persistence, @Named("bootstrapNode") Node bootstrapNode, + @Named("networkInterface") String networkInterface) { this.persistence = persistence; this.bootstrapNode = bootstrapNode; + this.networkInterface = networkInterface; } @@ -122,7 +126,12 @@ class BootstrappedPeerFactory { ChannelClientConfiguration cc = PeerBuilder.createDefaultChannelClientConfiguration(); cc.maxPermitsTCP(100); cc.maxPermitsUDP(100); - peer = new PeerBuilder(keyPair).ports(port).peerMap(pm).channelClientConfiguration(cc).start(); + Bindings bindings = new Bindings(); + if (!networkInterface.equals("")) + bindings.addInterface(networkInterface); + + peer = new PeerBuilder(keyPair).ports(port).peerMap(pm).bindings(bindings) + .channelClientConfiguration(cc).start(); peerDHT = new PeerBuilderDHT(peer).storageLayer(new StorageLayer(storage)).start(); peer.peerBean().peerMap().addPeerMapChangeListener(new PeerMapChangeListener() {