mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-06-17 03:19:26 -04:00
Added command line option to set listening interface for DHTManager seed peer
This commit is contained in:
parent
61508ae501
commit
a35eb7cb6e
5 changed files with 26 additions and 4 deletions
|
@ -45,6 +45,7 @@ public class BitSquare {
|
||||||
|
|
||||||
private static String appName = "Bitsquare";
|
private static String appName = "Bitsquare";
|
||||||
private static int clientPort;
|
private static int clientPort;
|
||||||
|
private static String interfaceHint;
|
||||||
|
|
||||||
public static String getAppName() {
|
public static String getAppName() {
|
||||||
return appName;
|
return appName;
|
||||||
|
@ -70,6 +71,10 @@ public class BitSquare {
|
||||||
appName = appName + "-" + namespace.getString(BitsquareArgumentParser.NAME_FLAG);
|
appName = appName + "-" + namespace.getString(BitsquareArgumentParser.NAME_FLAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (namespace.getString(BitsquareArgumentParser.INFHINT_FLAG) != null) {
|
||||||
|
interfaceHint = namespace.getString(BitsquareArgumentParser.INFHINT_FLAG);
|
||||||
|
}
|
||||||
|
|
||||||
if (namespace.getBoolean(BitsquareArgumentParser.SEED_FLAG) == true) {
|
if (namespace.getBoolean(BitsquareArgumentParser.SEED_FLAG) == true) {
|
||||||
Integer port = BitsquareArgumentParser.PORT_DEFAULT;
|
Integer port = BitsquareArgumentParser.PORT_DEFAULT;
|
||||||
if (namespace.getString(BitsquareArgumentParser.PORT_FLAG) != null) {
|
if (namespace.getString(BitsquareArgumentParser.PORT_FLAG) != null) {
|
||||||
|
@ -80,7 +85,7 @@ public class BitSquare {
|
||||||
|
|
||||||
ActorRef seedNode = actorSystem.actorOf(DHTManager.getProps(), DHTManager.SEED_NAME);
|
ActorRef seedNode = actorSystem.actorOf(DHTManager.getProps(), DHTManager.SEED_NAME);
|
||||||
Inbox inbox = Inbox.create(actorSystem);
|
Inbox inbox = Inbox.create(actorSystem);
|
||||||
inbox.send(seedNode, new InitializePeer(Number160.createHash("localhost"), port, null));
|
inbox.send(seedNode, new InitializePeer(Number160.createHash("localhost"), port, interfaceHint, null));
|
||||||
|
|
||||||
Thread seedNodeThread = new Thread(() -> {
|
Thread seedNodeThread = new Thread(() -> {
|
||||||
Boolean quit = false;
|
Boolean quit = false;
|
||||||
|
|
|
@ -42,6 +42,6 @@ public class DHTSeedService extends ActorService {
|
||||||
public void initializePeer(String id, Integer port) {
|
public void initializePeer(String id, Integer port) {
|
||||||
|
|
||||||
// TODO hard coded seed peer config for now, should read from config properties file
|
// TODO hard coded seed peer config for now, should read from config properties file
|
||||||
send(new InitializePeer(Number160.createHash(id), port, null));
|
send(new InitializePeer(Number160.createHash(id), port, null, null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ package io.bitsquare.msg.actor;
|
||||||
import io.bitsquare.msg.actor.command.InitializePeer;
|
import io.bitsquare.msg.actor.command.InitializePeer;
|
||||||
import io.bitsquare.msg.actor.event.PeerInitialized;
|
import io.bitsquare.msg.actor.event.PeerInitialized;
|
||||||
|
|
||||||
|
import net.tomp2p.connection.Bindings;
|
||||||
import net.tomp2p.dht.PeerBuilderDHT;
|
import net.tomp2p.dht.PeerBuilderDHT;
|
||||||
import net.tomp2p.dht.PeerDHT;
|
import net.tomp2p.dht.PeerDHT;
|
||||||
import net.tomp2p.nat.PeerBuilderNAT;
|
import net.tomp2p.nat.PeerBuilderNAT;
|
||||||
|
@ -48,6 +49,7 @@ public class DHTManager extends AbstractActor {
|
||||||
return Props.create(DHTManager.class);
|
return Props.create(DHTManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Bindings bindings;
|
||||||
private Peer peer;
|
private Peer peer;
|
||||||
private PeerDHT peerDHT;
|
private PeerDHT peerDHT;
|
||||||
private PeerNAT peerNAT;
|
private PeerNAT peerNAT;
|
||||||
|
@ -58,7 +60,11 @@ public class DHTManager extends AbstractActor {
|
||||||
log.debug("Received message: {}", ip);
|
log.debug("Received message: {}", ip);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
peer = new PeerBuilder(ip.getPeerId()).ports(ip.getPort()).start();
|
bindings = new Bindings();
|
||||||
|
if (ip.getInterfaceHint() != null) {
|
||||||
|
bindings.addInterface(ip.getInterfaceHint());
|
||||||
|
}
|
||||||
|
peer = new PeerBuilder(ip.getPeerId()).ports(ip.getPort()).bindings(bindings).start();
|
||||||
|
|
||||||
peerDHT = new PeerBuilderDHT(peer).start();
|
peerDHT = new PeerBuilderDHT(peer).start();
|
||||||
peerNAT = new PeerBuilderNAT(peer).start();
|
peerNAT = new PeerBuilderNAT(peer).start();
|
||||||
|
|
|
@ -30,11 +30,15 @@ public class InitializePeer {
|
||||||
|
|
||||||
private final Number160 peerId;
|
private final Number160 peerId;
|
||||||
private final Integer port;
|
private final Integer port;
|
||||||
|
private final String interfaceHint;
|
||||||
|
|
||||||
private final Collection<PeerAddress> bootstrapPeers;
|
private final Collection<PeerAddress> bootstrapPeers;
|
||||||
|
|
||||||
public InitializePeer(Number160 peerId, Integer port, Collection<PeerAddress> bootstrapPeers) {
|
public InitializePeer(Number160 peerId, Integer port, String interfaceHint,
|
||||||
|
Collection<PeerAddress> bootstrapPeers) {
|
||||||
this.peerId = peerId;
|
this.peerId = peerId;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
|
this.interfaceHint = interfaceHint;
|
||||||
this.bootstrapPeers = bootstrapPeers;
|
this.bootstrapPeers = bootstrapPeers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +50,10 @@ public class InitializePeer {
|
||||||
return port;
|
return port;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getInterfaceHint() {
|
||||||
|
return interfaceHint;
|
||||||
|
}
|
||||||
|
|
||||||
public Collection<PeerAddress> getBootstrapPeers() {
|
public Collection<PeerAddress> getBootstrapPeers() {
|
||||||
return bootstrapPeers;
|
return bootstrapPeers;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ public class BitsquareArgumentParser {
|
||||||
public static String SEED_FLAG = "seed";
|
public static String SEED_FLAG = "seed";
|
||||||
public static String PORT_FLAG = "port";
|
public static String PORT_FLAG = "port";
|
||||||
public static Integer PORT_DEFAULT = 5000;
|
public static Integer PORT_DEFAULT = 5000;
|
||||||
|
public static String INFHINT_FLAG = "interface";
|
||||||
public static String NAME_FLAG = "name";
|
public static String NAME_FLAG = "name";
|
||||||
|
|
||||||
private final ArgumentParser parser;
|
private final ArgumentParser parser;
|
||||||
|
@ -42,6 +43,8 @@ public class BitsquareArgumentParser {
|
||||||
parser.addArgument("-p", "--"+PORT_FLAG)
|
parser.addArgument("-p", "--"+PORT_FLAG)
|
||||||
.setDefault(PORT_DEFAULT)
|
.setDefault(PORT_DEFAULT)
|
||||||
.help("IP port to listen on.");
|
.help("IP port to listen on.");
|
||||||
|
parser.addArgument("-i", "--"+INFHINT_FLAG)
|
||||||
|
.help("interface to listen on.");
|
||||||
parser.addArgument("-n", "--"+NAME_FLAG)
|
parser.addArgument("-n", "--"+NAME_FLAG)
|
||||||
.help("Append name to application name.");
|
.help("Append name to application name.");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue