mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-04-19 23:36:00 -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
@ -23,12 +23,16 @@ import io.bitsquare.msg.actor.command.InitializePeer;
|
||||
import io.bitsquare.msg.actor.event.PeerInitialized;
|
||||
import io.bitsquare.util.BitsquareArgumentParser;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import javafx.application.Application;
|
||||
|
||||
import net.tomp2p.connection.Ports;
|
||||
import net.tomp2p.peers.Number160;
|
||||
import net.tomp2p.peers.PeerAddress;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -45,15 +49,15 @@ public class BitSquare {
|
||||
private static final Logger log = LoggerFactory.getLogger(BitSquare.class);
|
||||
|
||||
private static String appName = "Bitsquare";
|
||||
private static int clientPort;
|
||||
private static int port;
|
||||
private static String interfaceHint;
|
||||
|
||||
public static String getAppName() {
|
||||
return appName;
|
||||
}
|
||||
|
||||
public static int getClientPort() {
|
||||
return clientPort;
|
||||
public static int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
@ -72,26 +76,39 @@ public class BitSquare {
|
||||
appName = appName + "-" + namespace.getString(BitsquareArgumentParser.NAME_FLAG);
|
||||
}
|
||||
|
||||
port = BitsquareArgumentParser.PORT_DEFAULT;
|
||||
if (namespace.getString(BitsquareArgumentParser.PORT_FLAG) != null) {
|
||||
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.SEED_FLAG) == true) {
|
||||
if (namespace.getBoolean(BitsquareArgumentParser.BOOTSTRAP_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) {
|
||||
port = Integer.valueOf(namespace.getString(BitsquareArgumentParser.PORT_FLAG));
|
||||
if (namespace.getString(BitsquareArgumentParser.PEER_ID_FLAG) != null) {
|
||||
seedID = namespace.getString(BitsquareArgumentParser.PEER_ID_FLAG);
|
||||
}
|
||||
|
||||
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);
|
||||
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(() -> {
|
||||
Boolean quit = false;
|
||||
@ -122,9 +139,6 @@ public class BitSquare {
|
||||
seedNodeThread.start();
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ class MainModel extends UIModel {
|
||||
// For testing with the serverside seednode we need the BootstrappedPeerFactory which gets started form
|
||||
// messageFacade.init
|
||||
|
||||
messageFacade.init(BitSquare.getClientPort(), new BootstrapListener() {
|
||||
messageFacade.init(BitSquare.getPort(), new BootstrapListener() {
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
messageFacadeInited = true;
|
||||
|
@ -67,7 +67,9 @@ public class DHTManager extends AbstractActor {
|
||||
bindings.addInterface(ip.getInterfaceHint());
|
||||
}
|
||||
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();
|
||||
peerNAT = new PeerBuilderNAT(peer).start();
|
||||
|
||||
|
@ -27,8 +27,8 @@ import net.sourceforge.argparse4j.inf.Namespace;
|
||||
|
||||
public class BitsquareArgumentParser {
|
||||
|
||||
public static String SEED_FLAG = "seed";
|
||||
public static String SEED_ID_FLAG = "seedid";
|
||||
public static String BOOTSTRAP_FLAG = "bootstrap";
|
||||
public static String PEER_ID_FLAG = "peerid";
|
||||
public static String PORT_FLAG = "port";
|
||||
public static Integer PORT_DEFAULT = 5000;
|
||||
public static String INFHINT_FLAG = "interface";
|
||||
@ -40,12 +40,12 @@ public class BitsquareArgumentParser {
|
||||
parser = ArgumentParsers.newArgumentParser("BitSquare")
|
||||
.defaultHelp(true)
|
||||
.description("BitSquare decentralized bitcoin exchange.");
|
||||
parser.addArgument("-s", "--" + SEED_FLAG)
|
||||
parser.addArgument("-b", "--" + BOOTSTRAP_FLAG)
|
||||
.action(Arguments.storeTrue())
|
||||
.help("Start as DHT seed node, no UI.");
|
||||
parser.addArgument("-d", "--" + SEED_ID_FLAG)
|
||||
.help("Start as DHT bootstrap peer, no UI.");
|
||||
parser.addArgument("-d", "--" + PEER_ID_FLAG)
|
||||
.setDefault(SeedNodeAddress.StaticSeedNodeAddresses.DIGITAL_OCEAN1.getId())
|
||||
.help("Seed node peer ID.");
|
||||
.help("Bootstrap peer ID.");
|
||||
parser.addArgument("-p", "--"+PORT_FLAG)
|
||||
.setDefault(PORT_DEFAULT)
|
||||
.help("IP port to listen on.");
|
||||
|
@ -77,7 +77,7 @@ public class DHTTestController implements Initializable {
|
||||
|
||||
@Override
|
||||
public void initialize(URL url, ResourceBundle rb) {
|
||||
messageFacade.init(BitSquare.getClientPort(), new BootstrapListener() {
|
||||
messageFacade.init(BitSquare.getPort(), new BootstrapListener() {
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
onMessageFacadeInitialised();
|
||||
|
Loading…
x
Reference in New Issue
Block a user