Add interface argument

This commit is contained in:
Manfred Karrer 2014-11-10 02:08:54 +01:00
parent 775a391be3
commit 05a86f251f
4 changed files with 23 additions and 2 deletions

View File

@ -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");

View File

@ -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);
}

View File

@ -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();
}

View File

@ -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<PeerDHT> 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() {