mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-24 23:46:00 -04:00
Use separate dirs for version and btc network, bootstrap to all bootstrap nodes, change config of bootstrap node
This commit is contained in:
parent
7a9de65e86
commit
fc3634af7b
29 changed files with 285 additions and 272 deletions
|
@ -18,14 +18,16 @@
|
|||
package io.bitsquare.app.bootstrap;
|
||||
|
||||
import io.bitsquare.app.Logging;
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.p2p.BootstrapNodes;
|
||||
import io.bitsquare.p2p.Node;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.tomp2p.connection.ChannelClientConfiguration;
|
||||
import net.tomp2p.connection.ChannelServerConfiguration;
|
||||
import net.tomp2p.dht.PeerBuilderDHT;
|
||||
import net.tomp2p.dht.PeerDHT;
|
||||
import net.tomp2p.nat.PeerBuilderNAT;
|
||||
import net.tomp2p.p2p.Peer;
|
||||
import net.tomp2p.p2p.PeerBuilder;
|
||||
|
@ -37,13 +39,12 @@ import net.tomp2p.peers.PeerStatistic;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import io.netty.util.concurrent.DefaultEventExecutorGroup;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
public class BootstrapNode {
|
||||
private static final Logger log = LoggerFactory.getLogger(BootstrapNode.class);
|
||||
|
||||
private static final String VERSION = "0.1.3";
|
||||
|
||||
private static Peer peer = null;
|
||||
|
||||
private final Environment env;
|
||||
|
@ -53,29 +54,31 @@ public class BootstrapNode {
|
|||
this.env = env;
|
||||
}
|
||||
|
||||
|
||||
public void start() {
|
||||
String name = env.getProperty(Node.NAME_KEY, BootstrapNodes.getLocalhostNode().getName());
|
||||
int p2pId = env.getProperty(Node.P2P_ID_KEY, Integer.class, BootstrapNodes.getLocalhostNode().getP2pId());
|
||||
int port = env.getProperty(Node.PORT_KEY, Integer.class, BootstrapNodes.getLocalhostNode().getPort());
|
||||
BootstrapNodes bootstrapNodes = new BootstrapNodes();
|
||||
int p2pId = env.getProperty(Node.P2P_ID_KEY, Integer.class, Node.REG_TEST_P2P_ID); // use regtest as default
|
||||
bootstrapNodes.initWithNetworkId(p2pId);
|
||||
String name = env.getProperty(Node.NAME_KEY, bootstrapNodes.getLocalhostNode().getName());
|
||||
int port = env.getProperty(Node.PORT_KEY, Integer.class, bootstrapNodes.getLocalhostNode().getPort());
|
||||
|
||||
Logging.setup(name + "_" + port);
|
||||
|
||||
try {
|
||||
Number160 peerId = Number160.createHash(name);
|
||||
/*
|
||||
|
||||
DefaultEventExecutorGroup eventExecutorGroup = new DefaultEventExecutorGroup(50);
|
||||
ChannelClientConfiguration clientConf = PeerBuilder.createDefaultChannelClientConfiguration();
|
||||
clientConf.pipelineFilter(new PeerBuilder.EventExecutorGroupFilter(eventExecutorGroup));
|
||||
|
||||
ChannelServerConfiguration serverConf = PeerBuilder.createDefaultChannelServerConfiguration();
|
||||
serverConf.pipelineFilter(new PeerBuilder.EventExecutorGroupFilter(eventExecutorGroup));
|
||||
serverConf.connectionTimeoutTCPMillis(5000);*/
|
||||
serverConf.connectionTimeoutTCPMillis(5000);
|
||||
|
||||
peer = new PeerBuilder(peerId)
|
||||
.ports(port)
|
||||
.p2pId(p2pId)
|
||||
/* .channelClientConfiguration(clientConf)
|
||||
.channelServerConfiguration(serverConf)*/
|
||||
.channelClientConfiguration(clientConf)
|
||||
.channelServerConfiguration(serverConf)
|
||||
.start();
|
||||
|
||||
/*peer.objectDataReply((sender, request) -> {
|
||||
|
@ -83,62 +86,49 @@ public class BootstrapNode {
|
|||
return "pong";
|
||||
});*/
|
||||
|
||||
PeerDHT peerDHT = new PeerBuilderDHT(peer).start();
|
||||
new PeerBuilderDHT(peer).start();
|
||||
new PeerBuilderNAT(peer).start();
|
||||
|
||||
final int _port = port;
|
||||
if (!name.equals(BootstrapNodes.getLocalhostNode().getName())) {
|
||||
Collection<PeerAddress> bootstrapNodes = BootstrapNodes.getAllBootstrapNodes(p2pId).stream().filter(e -> !e.getName().equals(name))
|
||||
if (!name.equals(bootstrapNodes.getLocalhostNode().getName())) {
|
||||
List<Node> bootstrapNodesExcludingMyself = bootstrapNodes.getBootstrapNodes().stream().filter(e -> !e.getName().equals
|
||||
(name)).collect(Collectors.toList());
|
||||
log.info("Bootstrapping to bootstrapNodes " + bootstrapNodesExcludingMyself);
|
||||
long ts = System.currentTimeMillis();
|
||||
List<PeerAddress> bootstrapAddressesExcludingMyself = bootstrapNodesExcludingMyself.stream()
|
||||
.map(e -> e.toPeerAddressWithPort(_port)).collect(Collectors.toList());
|
||||
|
||||
log.info("Bootstrapping to " + bootstrapNodes.size() + " bootstrapNode(s)");
|
||||
log.info("Bootstrapping bootstrapNodes " + bootstrapNodes);
|
||||
peer.bootstrap().bootstrapTo(bootstrapNodes).start().awaitUninterruptibly();
|
||||
peer.bootstrap().bootstrapTo(bootstrapAddressesExcludingMyself).start().awaitUninterruptibly();
|
||||
log.info("Bootstrapping done after {} msec", System.currentTimeMillis() - ts);
|
||||
}
|
||||
else {
|
||||
log.info("We are localhost, we do not bootstrap to other nodes");
|
||||
log.info("When using localhost we do not bootstrap to other nodes");
|
||||
}
|
||||
peer.peerBean().peerMap().addPeerMapChangeListener(new PeerMapChangeListener() {
|
||||
@Override
|
||||
public void peerInserted(PeerAddress peerAddress, boolean verified) {
|
||||
try {
|
||||
log.info("Peer inserted: peerAddress=" + peerAddress + ", verified=" + verified);
|
||||
} catch (Throwable t) {
|
||||
log.error("Exception at peerInserted " + t.getMessage());
|
||||
}
|
||||
log.info("Peer inserted: peerAddress=" + peerAddress + ", verified=" + verified);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void peerRemoved(PeerAddress peerAddress, PeerStatistic peerStatistics) {
|
||||
try {
|
||||
log.info("Peer removed: peerAddress=" + peerAddress + ", peerStatistics=" + peerStatistics);
|
||||
} catch (Throwable t) {
|
||||
log.error("Exception at peerRemoved " + t.getMessage());
|
||||
}
|
||||
log.info("Peer removed: peerAddress=" + peerAddress + ", peerStatistics=" + peerStatistics);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void peerUpdated(PeerAddress peerAddress, PeerStatistic peerStatistics) {
|
||||
try {
|
||||
//log.info("Peer updated: peerAddress=" + peerAddress + ", peerStatistics=" + peerStatistics);
|
||||
} catch (Throwable t) {
|
||||
log.error("Exception at peerUpdated " + t.getMessage());
|
||||
}
|
||||
//log.info("Peer updated: peerAddress=" + peerAddress + ", peerStatistics=" + peerStatistics);
|
||||
}
|
||||
});
|
||||
|
||||
log.info("Bootstrap node started with name=" + name + " ,p2pId=" + p2pId + " ,port=" + port + " and version=" + VERSION);
|
||||
log.info("Bootstrap node started with name=" + name + " ,p2pId=" + p2pId + " ,port=" + port +
|
||||
" and network protocol version=" + Version.NETWORK_PROTOCOL_VERSION);
|
||||
new Thread(() -> {
|
||||
while (true) {
|
||||
if (peer.peerBean().peerMap().all().size() > 0) {
|
||||
noPeersInfoPrinted = false;
|
||||
try {
|
||||
log.info("Number of peers online = " + peer.peerBean().peerMap().all().size());
|
||||
for (PeerAddress peerAddress : peer.peerBean().peerMap().all()) {
|
||||
log.info("Peer: " + peerAddress.toString());
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
log.error("Exception at run loop " + t.getMessage());
|
||||
log.info("Number of peers online = " + peer.peerBean().peerMap().all().size());
|
||||
for (PeerAddress peerAddress : peer.peerBean().peerMap().all()) {
|
||||
log.info("Peer: " + peerAddress.toString());
|
||||
}
|
||||
}
|
||||
else if (noPeersInfoPrinted) {
|
||||
|
@ -146,7 +136,7 @@ public class BootstrapNode {
|
|||
noPeersInfoPrinted = true;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
|
|
|
@ -32,14 +32,16 @@ public class BootstrapNodeMain extends BitsquareExecutable {
|
|||
}
|
||||
|
||||
protected void customizeOptionParsing(OptionParser parser) {
|
||||
parser.accepts(Node.NAME_KEY, description("Name of this node", BootstrapNodes.getLocalhostNode().getName()))
|
||||
BootstrapNodes bootstrapNodes = new BootstrapNodes();
|
||||
bootstrapNodes.initWithNetworkId(Node.REG_TEST_P2P_ID); // use regtest as default
|
||||
parser.accepts(Node.NAME_KEY, description("Name of this node", bootstrapNodes.getLocalhostNode().getName()))
|
||||
.withRequiredArg()
|
||||
.ofType(String.class);
|
||||
parser.accepts(Node.P2P_ID_KEY, description("P2P network ID",
|
||||
BootstrapNodes.getLocalhostNode().getP2pId()))
|
||||
bootstrapNodes.getLocalhostNode().getP2pId()))
|
||||
.withRequiredArg()
|
||||
.ofType(int.class);
|
||||
parser.accepts(Node.PORT_KEY, description("Port to listen on", BootstrapNodes.getLocalhostNode().getPort()))
|
||||
parser.accepts(Node.PORT_KEY, description("Port to listen on", bootstrapNodes.getLocalhostNode().getPort()))
|
||||
.withRequiredArg()
|
||||
.ofType(int.class);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue