mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-06-27 16:17:37 -04:00
Use Localhost and regtest as default, cleanup seednode
This commit is contained in:
parent
e665c7ebd1
commit
c0524120e2
6 changed files with 68 additions and 69 deletions
|
@ -46,37 +46,26 @@ import scala.concurrent.duration.FiniteDuration;
|
||||||
public class SeedNode {
|
public class SeedNode {
|
||||||
private static final Logger log = LoggerFactory.getLogger(SeedNode.class);
|
private static final Logger log = LoggerFactory.getLogger(SeedNode.class);
|
||||||
|
|
||||||
private static String appName = "Bitsquare";
|
|
||||||
private static String interfaceHint;
|
private static String interfaceHint;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
ArgumentParser parser = new ArgumentParser();
|
ArgumentParser parser = new ArgumentParser();
|
||||||
Namespace namespace = parser.parseArgs(args);
|
Namespace namespace = parser.parseArgs(args);
|
||||||
|
|
||||||
if (namespace.getString(ArgumentParser.NAME_FLAG) != null) {
|
|
||||||
appName = appName + "-" + namespace.getString(ArgumentParser.NAME_FLAG);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (namespace.getString(ArgumentParser.INFHINT_FLAG) != null) {
|
if (namespace.getString(ArgumentParser.INFHINT_FLAG) != null) {
|
||||||
interfaceHint = namespace.getString(ArgumentParser.INFHINT_FLAG);
|
interfaceHint = namespace.getString(ArgumentParser.INFHINT_FLAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
int port = -1;
|
int serverPort = Integer.valueOf(namespace.getString(ArgumentParser.PORT_FLAG));
|
||||||
if (namespace.getString(ArgumentParser.PORT_FLAG) != null) {
|
|
||||||
port = Integer.valueOf(namespace.getString(ArgumentParser.PORT_FLAG));
|
|
||||||
}
|
|
||||||
|
|
||||||
String seedID = BootstrapNode.DIGITAL_OCEAN1.getId();
|
String seedID = BootstrapNode.LOCAL_HOST.getId();
|
||||||
if (namespace.getString(ArgumentParser.PEER_ID_FLAG) != null) {
|
if (namespace.getString(ArgumentParser.PEER_ID_FLAG) != null) {
|
||||||
seedID = namespace.getString(ArgumentParser.PEER_ID_FLAG);
|
seedID = namespace.getString(ArgumentParser.PEER_ID_FLAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
ActorSystem actorSystem = ActorSystem.create(appName);
|
final Set<PeerAddress> peerAddresses = new HashSet<>();
|
||||||
|
|
||||||
final Set<PeerAddress> peerAddresses = new HashSet<PeerAddress>();
|
|
||||||
final String sid = seedID;
|
|
||||||
for (Node node : BootstrapNode.values()) {
|
for (Node node : BootstrapNode.values()) {
|
||||||
if (!node.getId().equals(sid)) {
|
if (!node.getId().equals(seedID)) {
|
||||||
try {
|
try {
|
||||||
peerAddresses.add(new PeerAddress(Number160.createHash(node.getId()), node.getIp(),
|
peerAddresses.add(new PeerAddress(Number160.createHash(node.getId()), node.getIp(),
|
||||||
node.getPort(), node.getPort()));
|
node.getPort(), node.getPort()));
|
||||||
|
@ -86,11 +75,10 @@ public class SeedNode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int serverPort = (port == -1) ? ArgumentParser.PORT_DEFAULT : port;
|
ActorSystem actorSystem = ActorSystem.create("BitsquareSeedNode");
|
||||||
|
|
||||||
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(sid), serverPort, interfaceHint,
|
ActorRef seedNode = actorSystem.actorOf(DHTManager.getProps(), DHTManager.SEED_NODE);
|
||||||
|
inbox.send(seedNode, new InitializePeer(Number160.createHash(seedID), serverPort, interfaceHint,
|
||||||
peerAddresses));
|
peerAddresses));
|
||||||
|
|
||||||
Thread seedNodeThread = new Thread(() -> {
|
Thread seedNodeThread = new Thread(() -> {
|
||||||
|
|
|
@ -123,7 +123,7 @@ public class Main extends Application {
|
||||||
|
|
||||||
// configure the primary stage
|
// configure the primary stage
|
||||||
|
|
||||||
primaryStage.setTitle("Bitsquare (" + appName + ")");
|
primaryStage.setTitle(appName);
|
||||||
primaryStage.setScene(scene);
|
primaryStage.setScene(scene);
|
||||||
primaryStage.setMinWidth(75);
|
primaryStage.setMinWidth(75);
|
||||||
primaryStage.setMinHeight(50);
|
primaryStage.setMinHeight(50);
|
||||||
|
|
|
@ -33,7 +33,7 @@ public class BitcoinModule extends AbstractBitsquareModule {
|
||||||
private final BitcoinNetwork defaultNetwork;
|
private final BitcoinNetwork defaultNetwork;
|
||||||
|
|
||||||
public BitcoinModule(Properties properties) {
|
public BitcoinModule(Properties properties) {
|
||||||
this(properties, BitcoinNetwork.TESTNET);
|
this(properties, BitcoinNetwork.REGTEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BitcoinModule(Properties properties, BitcoinNetwork defaultNetwork) {
|
public BitcoinModule(Properties properties, BitcoinNetwork defaultNetwork) {
|
||||||
|
|
|
@ -30,7 +30,7 @@ public class DHTSeedService extends ActorService {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public DHTSeedService(ActorSystem system) {
|
public DHTSeedService(ActorSystem system) {
|
||||||
super(system, "/user/" + DHTManager.SEED_NAME);
|
super(system, "/user/" + DHTManager.SEED_NODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initializePeer(String id, Integer port) {
|
public void initializePeer(String id, Integer port) {
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class DefaultMessageModule extends AbstractBitsquareModule implements Mes
|
||||||
|
|
||||||
bind(Node.class)
|
bind(Node.class)
|
||||||
.annotatedWith(Names.named("bootstrapNode"))
|
.annotatedWith(Names.named("bootstrapNode"))
|
||||||
.toInstance(BootstrapNode.DIGITAL_OCEAN1);
|
.toInstance(BootstrapNode.LOCAL_HOST);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -21,7 +21,6 @@ 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.connection.Bindings;
|
||||||
import net.tomp2p.connection.StandardProtocolFamily;
|
|
||||||
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;
|
||||||
|
@ -40,8 +39,8 @@ import akka.japi.pf.ReceiveBuilder;
|
||||||
|
|
||||||
public class DHTManager extends AbstractActor {
|
public class DHTManager extends AbstractActor {
|
||||||
|
|
||||||
public static final String PEER_NAME = "peerDhtManager";
|
public static final String MY_NODE = "myNodeDhtManager";
|
||||||
public static final String SEED_NAME = "seedDhtManager";
|
public static final String SEED_NODE = "seedNodeDhtManager";
|
||||||
|
|
||||||
private final LoggingAdapter log = Logging.getLogger(context().system(), this);
|
private final LoggingAdapter log = Logging.getLogger(context().system(), this);
|
||||||
|
|
||||||
|
@ -60,58 +59,70 @@ public class DHTManager extends AbstractActor {
|
||||||
|
|
||||||
public DHTManager() {
|
public DHTManager() {
|
||||||
receive(ReceiveBuilder
|
receive(ReceiveBuilder
|
||||||
.match(InitializePeer.class, ip -> {
|
.match(InitializePeer.class, initializePeer -> doInitializePeer(initializePeer))
|
||||||
log.debug("Received message: {}", ip);
|
|
||||||
|
|
||||||
try {
|
|
||||||
bindings = new Bindings();
|
|
||||||
bindings.addProtocol(StandardProtocolFamily.INET);
|
|
||||||
if (ip.getInterfaceHint() != null) {
|
|
||||||
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();
|
|
||||||
|
|
||||||
peer.peerBean().peerMap().addPeerMapChangeListener(new PeerMapChangeListener() {
|
|
||||||
@Override
|
|
||||||
public void peerInserted(PeerAddress peerAddress, boolean verified) {
|
|
||||||
log.debug("Peer inserted: peerAddress=" + peerAddress + ", " +
|
|
||||||
"verified=" + verified);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void peerRemoved(PeerAddress peerAddress, PeerStatistic peerStatistics) {
|
|
||||||
log.debug("Peer removed: peerAddress=" + peerAddress + ", " +
|
|
||||||
"peerStatistics=" + peerStatistics);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void peerUpdated(PeerAddress peerAddress, PeerStatistic peerStatistics) {
|
|
||||||
// log.debug("Peer updated: peerAddress=" + peerAddress + ",
|
|
||||||
// peerStatistics=" + peerStatistics);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
sender().tell(new PeerInitialized(peer.peerID(), ip.getPort()), self());
|
|
||||||
} catch (Throwable t) {
|
|
||||||
log.info("The second instance has been started. If that happens at the first instance" +
|
|
||||||
" we are in trouble... " + t.getMessage());
|
|
||||||
sender().tell(new PeerInitialized(null, null), self());
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.matchAny(o -> log.info("received unknown message")).build()
|
.matchAny(o -> log.info("received unknown message")).build()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void doInitializePeer(InitializePeer initializePeer) {
|
||||||
|
log.debug("Received message: {}", initializePeer);
|
||||||
|
|
||||||
|
try {
|
||||||
|
bindings = new Bindings();
|
||||||
|
|
||||||
|
// TODO: @Steve: Is that needed that we restrict to IP4?
|
||||||
|
// bindings.addProtocol(StandardProtocolFamily.INET);
|
||||||
|
|
||||||
|
if (initializePeer.getInterfaceHint() != null) {
|
||||||
|
bindings.addInterface(initializePeer.getInterfaceHint());
|
||||||
|
}
|
||||||
|
|
||||||
|
peer = new PeerBuilder(initializePeer.getPeerId()).ports(initializePeer.getPort()).bindings(bindings)
|
||||||
|
.start();
|
||||||
|
|
||||||
|
// For the moment we want not to bootstrap to other seed nodes to keep test scenarios
|
||||||
|
// simple
|
||||||
|
/* if (ip.getBootstrapPeers() != null && ip.getBootstrapPeers().size() > 0) {
|
||||||
|
peer.bootstrap().bootstrapTo(ip.getBootstrapPeers()).start();
|
||||||
|
}*/
|
||||||
|
peerDHT = new PeerBuilderDHT(peer).start();
|
||||||
|
peerNAT = new PeerBuilderNAT(peer).start();
|
||||||
|
|
||||||
|
peer.peerBean().peerMap().addPeerMapChangeListener(new PeerMapChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void peerInserted(PeerAddress peerAddress, boolean verified) {
|
||||||
|
log.debug("Peer inserted: peerAddress=" + peerAddress + ", " +
|
||||||
|
"verified=" + verified);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void peerRemoved(PeerAddress peerAddress, PeerStatistic peerStatistics) {
|
||||||
|
log.debug("Peer removed: peerAddress=" + peerAddress + ", " +
|
||||||
|
"peerStatistics=" + peerStatistics);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void peerUpdated(PeerAddress peerAddress, PeerStatistic peerStatistics) {
|
||||||
|
// log.debug("Peer updated: peerAddress=" + peerAddress + ",
|
||||||
|
// peerStatistics=" + peerStatistics);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
sender().tell(new PeerInitialized(peer.peerID(), initializePeer.getPort()), self());
|
||||||
|
} catch (Throwable t) {
|
||||||
|
log.info("The second instance has been started. If that happens at the first instance" +
|
||||||
|
" we are in trouble... " + t.getMessage());
|
||||||
|
sender().tell(new PeerInitialized(null, null), self());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postStop() throws Exception {
|
public void postStop() throws Exception {
|
||||||
log.debug("postStop");
|
log.debug("postStop");
|
||||||
if (peerDHT != null)
|
if (peerDHT != null)
|
||||||
peerDHT.shutdown();
|
peerDHT.shutdown();
|
||||||
|
|
||||||
if (peerNAT != null)
|
if (peerNAT != null)
|
||||||
peerNAT.natUtils().shutdown();
|
peerNAT.natUtils().shutdown();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue