mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-26 16:35:18 -04:00
updated seed peer mode to add all other seed peers with a different peerID
This commit is contained in:
parent
08f1a73bf5
commit
fd9024f6ea
5 changed files with 41 additions and 25 deletions
|
@ -23,12 +23,16 @@ import io.bitsquare.msg.actor.command.InitializePeer;
|
||||||
import io.bitsquare.msg.actor.event.PeerInitialized;
|
import io.bitsquare.msg.actor.event.PeerInitialized;
|
||||||
import io.bitsquare.util.BitsquareArgumentParser;
|
import io.bitsquare.util.BitsquareArgumentParser;
|
||||||
|
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
|
|
||||||
import net.tomp2p.connection.Ports;
|
|
||||||
import net.tomp2p.peers.Number160;
|
import net.tomp2p.peers.Number160;
|
||||||
|
import net.tomp2p.peers.PeerAddress;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -45,15 +49,15 @@ public class BitSquare {
|
||||||
private static final Logger log = LoggerFactory.getLogger(BitSquare.class);
|
private static final Logger log = LoggerFactory.getLogger(BitSquare.class);
|
||||||
|
|
||||||
private static String appName = "Bitsquare";
|
private static String appName = "Bitsquare";
|
||||||
private static int clientPort;
|
private static int port;
|
||||||
private static String interfaceHint;
|
private static String interfaceHint;
|
||||||
|
|
||||||
public static String getAppName() {
|
public static String getAppName() {
|
||||||
return appName;
|
return appName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getClientPort() {
|
public static int getPort() {
|
||||||
return clientPort;
|
return port;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -72,26 +76,39 @@ public class BitSquare {
|
||||||
appName = appName + "-" + namespace.getString(BitsquareArgumentParser.NAME_FLAG);
|
appName = appName + "-" + namespace.getString(BitsquareArgumentParser.NAME_FLAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (namespace.getString(BitsquareArgumentParser.INFHINT_FLAG) != null) {
|
port = BitsquareArgumentParser.PORT_DEFAULT;
|
||||||
interfaceHint = namespace.getString(BitsquareArgumentParser.INFHINT_FLAG);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (namespace.getBoolean(BitsquareArgumentParser.SEED_FLAG) == true) {
|
|
||||||
String seedID = SeedNodeAddress.StaticSeedNodeAddresses.DIGITAL_OCEAN1.getId();
|
|
||||||
if (namespace.getString(BitsquareArgumentParser.SEED_ID_FLAG) != null) {
|
|
||||||
seedID = namespace.getString(BitsquareArgumentParser.SEED_ID_FLAG);
|
|
||||||
}
|
|
||||||
|
|
||||||
Integer port = BitsquareArgumentParser.PORT_DEFAULT;
|
|
||||||
if (namespace.getString(BitsquareArgumentParser.PORT_FLAG) != null) {
|
if (namespace.getString(BitsquareArgumentParser.PORT_FLAG) != null) {
|
||||||
port = Integer.valueOf(namespace.getString(BitsquareArgumentParser.PORT_FLAG));
|
port = Integer.valueOf(namespace.getString(BitsquareArgumentParser.PORT_FLAG));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (namespace.getString(BitsquareArgumentParser.INFHINT_FLAG) != null) {
|
||||||
|
interfaceHint = namespace.getString(BitsquareArgumentParser.INFHINT_FLAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (namespace.getBoolean(BitsquareArgumentParser.BOOTSTRAP_FLAG) == true) {
|
||||||
|
String seedID = SeedNodeAddress.StaticSeedNodeAddresses.DIGITAL_OCEAN1.getId();
|
||||||
|
if (namespace.getString(BitsquareArgumentParser.PEER_ID_FLAG) != null) {
|
||||||
|
seedID = namespace.getString(BitsquareArgumentParser.PEER_ID_FLAG);
|
||||||
|
}
|
||||||
|
|
||||||
ActorSystem actorSystem = ActorSystem.create(getAppName());
|
ActorSystem actorSystem = ActorSystem.create(getAppName());
|
||||||
|
|
||||||
|
final Set<PeerAddress> peerAddresses = new HashSet<PeerAddress>();
|
||||||
|
final String sid = seedID;
|
||||||
|
SeedNodeAddress.StaticSeedNodeAddresses.getAllSeedNodeAddresses().forEach(a -> {
|
||||||
|
if (!a.getId().equals(sid)) {
|
||||||
|
try {
|
||||||
|
peerAddresses.add(new PeerAddress(Number160.createHash(a.getId()),a.getIp(),
|
||||||
|
a.getPort(), a.getPort()));
|
||||||
|
} catch (UnknownHostException uhe) {
|
||||||
|
log.error("Unknown Host ["+a.getIp()+"]: "+uhe.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
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(seedID), port, interfaceHint, null));
|
inbox.send(seedNode, new InitializePeer(Number160.createHash(sid), port, interfaceHint, peerAddresses));
|
||||||
|
|
||||||
Thread seedNodeThread = new Thread(() -> {
|
Thread seedNodeThread = new Thread(() -> {
|
||||||
Boolean quit = false;
|
Boolean quit = false;
|
||||||
|
@ -122,9 +139,6 @@ public class BitSquare {
|
||||||
seedNodeThread.start();
|
seedNodeThread.start();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
clientPort = new Ports().tcpPort(); // default we use a random port for the client
|
|
||||||
if (namespace.getString(BitsquareArgumentParser.PORT_FLAG) != null)
|
|
||||||
clientPort = Integer.valueOf(namespace.getString(BitsquareArgumentParser.PORT_FLAG));
|
|
||||||
|
|
||||||
Application.launch(BitSquareUI.class, args);
|
Application.launch(BitSquareUI.class, args);
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,7 @@ class MainModel extends UIModel {
|
||||||
// For testing with the serverside seednode we need the BootstrappedPeerFactory which gets started form
|
// For testing with the serverside seednode we need the BootstrappedPeerFactory which gets started form
|
||||||
// messageFacade.init
|
// messageFacade.init
|
||||||
|
|
||||||
messageFacade.init(BitSquare.getClientPort(), new BootstrapListener() {
|
messageFacade.init(BitSquare.getPort(), new BootstrapListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCompleted() {
|
public void onCompleted() {
|
||||||
messageFacadeInited = true;
|
messageFacadeInited = true;
|
||||||
|
|
|
@ -67,7 +67,9 @@ public class DHTManager extends AbstractActor {
|
||||||
bindings.addInterface(ip.getInterfaceHint());
|
bindings.addInterface(ip.getInterfaceHint());
|
||||||
}
|
}
|
||||||
peer = new PeerBuilder(ip.getPeerId()).ports(ip.getPort()).bindings(bindings).start();
|
peer = new PeerBuilder(ip.getPeerId()).ports(ip.getPort()).bindings(bindings).start();
|
||||||
|
if (ip.getBootstrapPeers() != null && ip.getBootstrapPeers().size() > 0) {
|
||||||
|
peer.bootstrap().bootstrapTo(ip.getBootstrapPeers()).start();
|
||||||
|
}
|
||||||
peerDHT = new PeerBuilderDHT(peer).start();
|
peerDHT = new PeerBuilderDHT(peer).start();
|
||||||
peerNAT = new PeerBuilderNAT(peer).start();
|
peerNAT = new PeerBuilderNAT(peer).start();
|
||||||
|
|
||||||
|
|
|
@ -27,8 +27,8 @@ import net.sourceforge.argparse4j.inf.Namespace;
|
||||||
|
|
||||||
public class BitsquareArgumentParser {
|
public class BitsquareArgumentParser {
|
||||||
|
|
||||||
public static String SEED_FLAG = "seed";
|
public static String BOOTSTRAP_FLAG = "bootstrap";
|
||||||
public static String SEED_ID_FLAG = "seedid";
|
public static String PEER_ID_FLAG = "peerid";
|
||||||
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 INFHINT_FLAG = "interface";
|
||||||
|
@ -40,12 +40,12 @@ public class BitsquareArgumentParser {
|
||||||
parser = ArgumentParsers.newArgumentParser("BitSquare")
|
parser = ArgumentParsers.newArgumentParser("BitSquare")
|
||||||
.defaultHelp(true)
|
.defaultHelp(true)
|
||||||
.description("BitSquare decentralized bitcoin exchange.");
|
.description("BitSquare decentralized bitcoin exchange.");
|
||||||
parser.addArgument("-s", "--" + SEED_FLAG)
|
parser.addArgument("-b", "--" + BOOTSTRAP_FLAG)
|
||||||
.action(Arguments.storeTrue())
|
.action(Arguments.storeTrue())
|
||||||
.help("Start as DHT seed node, no UI.");
|
.help("Start as DHT bootstrap peer, no UI.");
|
||||||
parser.addArgument("-d", "--" + SEED_ID_FLAG)
|
parser.addArgument("-d", "--" + PEER_ID_FLAG)
|
||||||
.setDefault(SeedNodeAddress.StaticSeedNodeAddresses.DIGITAL_OCEAN1.getId())
|
.setDefault(SeedNodeAddress.StaticSeedNodeAddresses.DIGITAL_OCEAN1.getId())
|
||||||
.help("Seed node peer ID.");
|
.help("Bootstrap peer ID.");
|
||||||
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.");
|
||||||
|
|
|
@ -77,7 +77,7 @@ public class DHTTestController implements Initializable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL url, ResourceBundle rb) {
|
public void initialize(URL url, ResourceBundle rb) {
|
||||||
messageFacade.init(BitSquare.getClientPort(), new BootstrapListener() {
|
messageFacade.init(BitSquare.getPort(), new BootstrapListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCompleted() {
|
public void onCompleted() {
|
||||||
onMessageFacadeInitialised();
|
onMessageFacadeInitialised();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue