mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-04-19 15:26:03 -04:00
Use Localhost and regtest as default, cleanup seednode
This commit is contained in:
parent
e665c7ebd1
commit
c0524120e2
@ -46,37 +46,26 @@ import scala.concurrent.duration.FiniteDuration;
|
||||
public class SeedNode {
|
||||
private static final Logger log = LoggerFactory.getLogger(SeedNode.class);
|
||||
|
||||
private static String appName = "Bitsquare";
|
||||
private static String interfaceHint;
|
||||
|
||||
public static void main(String[] args) {
|
||||
ArgumentParser parser = new ArgumentParser();
|
||||
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) {
|
||||
interfaceHint = namespace.getString(ArgumentParser.INFHINT_FLAG);
|
||||
}
|
||||
|
||||
int port = -1;
|
||||
if (namespace.getString(ArgumentParser.PORT_FLAG) != null) {
|
||||
port = Integer.valueOf(namespace.getString(ArgumentParser.PORT_FLAG));
|
||||
}
|
||||
int serverPort = 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) {
|
||||
seedID = namespace.getString(ArgumentParser.PEER_ID_FLAG);
|
||||
}
|
||||
|
||||
ActorSystem actorSystem = ActorSystem.create(appName);
|
||||
|
||||
final Set<PeerAddress> peerAddresses = new HashSet<PeerAddress>();
|
||||
final String sid = seedID;
|
||||
final Set<PeerAddress> peerAddresses = new HashSet<>();
|
||||
for (Node node : BootstrapNode.values()) {
|
||||
if (!node.getId().equals(sid)) {
|
||||
if (!node.getId().equals(seedID)) {
|
||||
try {
|
||||
peerAddresses.add(new PeerAddress(Number160.createHash(node.getId()), node.getIp(),
|
||||
node.getPort(), node.getPort()));
|
||||
@ -86,11 +75,10 @@ public class SeedNode {
|
||||
}
|
||||
}
|
||||
|
||||
int serverPort = (port == -1) ? ArgumentParser.PORT_DEFAULT : port;
|
||||
|
||||
ActorRef seedNode = actorSystem.actorOf(DHTManager.getProps(), DHTManager.SEED_NAME);
|
||||
ActorSystem actorSystem = ActorSystem.create("BitsquareSeedNode");
|
||||
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));
|
||||
|
||||
Thread seedNodeThread = new Thread(() -> {
|
||||
|
@ -123,7 +123,7 @@ public class Main extends Application {
|
||||
|
||||
// configure the primary stage
|
||||
|
||||
primaryStage.setTitle("Bitsquare (" + appName + ")");
|
||||
primaryStage.setTitle(appName);
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.setMinWidth(75);
|
||||
primaryStage.setMinHeight(50);
|
||||
|
@ -33,7 +33,7 @@ public class BitcoinModule extends AbstractBitsquareModule {
|
||||
private final BitcoinNetwork defaultNetwork;
|
||||
|
||||
public BitcoinModule(Properties properties) {
|
||||
this(properties, BitcoinNetwork.TESTNET);
|
||||
this(properties, BitcoinNetwork.REGTEST);
|
||||
}
|
||||
|
||||
public BitcoinModule(Properties properties, BitcoinNetwork defaultNetwork) {
|
||||
|
@ -30,7 +30,7 @@ public class DHTSeedService extends ActorService {
|
||||
|
||||
@Inject
|
||||
public DHTSeedService(ActorSystem system) {
|
||||
super(system, "/user/" + DHTManager.SEED_NAME);
|
||||
super(system, "/user/" + DHTManager.SEED_NODE);
|
||||
}
|
||||
|
||||
public void initializePeer(String id, Integer port) {
|
||||
|
@ -44,7 +44,7 @@ public class DefaultMessageModule extends AbstractBitsquareModule implements Mes
|
||||
|
||||
bind(Node.class)
|
||||
.annotatedWith(Names.named("bootstrapNode"))
|
||||
.toInstance(BootstrapNode.DIGITAL_OCEAN1);
|
||||
.toInstance(BootstrapNode.LOCAL_HOST);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,7 +21,6 @@ import io.bitsquare.msg.actor.command.InitializePeer;
|
||||
import io.bitsquare.msg.actor.event.PeerInitialized;
|
||||
|
||||
import net.tomp2p.connection.Bindings;
|
||||
import net.tomp2p.connection.StandardProtocolFamily;
|
||||
import net.tomp2p.dht.PeerBuilderDHT;
|
||||
import net.tomp2p.dht.PeerDHT;
|
||||
import net.tomp2p.nat.PeerBuilderNAT;
|
||||
@ -40,8 +39,8 @@ import akka.japi.pf.ReceiveBuilder;
|
||||
|
||||
public class DHTManager extends AbstractActor {
|
||||
|
||||
public static final String PEER_NAME = "peerDhtManager";
|
||||
public static final String SEED_NAME = "seedDhtManager";
|
||||
public static final String MY_NODE = "myNodeDhtManager";
|
||||
public static final String SEED_NODE = "seedNodeDhtManager";
|
||||
|
||||
private final LoggingAdapter log = Logging.getLogger(context().system(), this);
|
||||
|
||||
@ -60,58 +59,70 @@ public class DHTManager extends AbstractActor {
|
||||
|
||||
public DHTManager() {
|
||||
receive(ReceiveBuilder
|
||||
.match(InitializePeer.class, ip -> {
|
||||
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());
|
||||
}
|
||||
})
|
||||
.match(InitializePeer.class, initializePeer -> doInitializePeer(initializePeer))
|
||||
.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
|
||||
public void postStop() throws Exception {
|
||||
log.debug("postStop");
|
||||
if (peerDHT != null)
|
||||
peerDHT.shutdown();
|
||||
|
||||
if (peerNAT != null)
|
||||
peerNAT.natUtils().shutdown();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user