mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-06-27 08:10:45 -04:00
Add bootstrap
This commit is contained in:
parent
501a3ccbc2
commit
954fb7727c
1 changed files with 28 additions and 7 deletions
|
@ -44,6 +44,7 @@ import net.tomp2p.dht.PeerDHT;
|
||||||
import net.tomp2p.dht.StorageLayer;
|
import net.tomp2p.dht.StorageLayer;
|
||||||
import net.tomp2p.futures.BaseFuture;
|
import net.tomp2p.futures.BaseFuture;
|
||||||
import net.tomp2p.futures.BaseFutureListener;
|
import net.tomp2p.futures.BaseFutureListener;
|
||||||
|
import net.tomp2p.futures.FutureBootstrap;
|
||||||
import net.tomp2p.futures.FutureDiscover;
|
import net.tomp2p.futures.FutureDiscover;
|
||||||
import net.tomp2p.nat.FutureNAT;
|
import net.tomp2p.nat.FutureNAT;
|
||||||
import net.tomp2p.nat.FutureRelayNAT;
|
import net.tomp2p.nat.FutureRelayNAT;
|
||||||
|
@ -188,13 +189,11 @@ class BootstrappedPeerFactory {
|
||||||
public void operationComplete(BaseFuture future) throws Exception {
|
public void operationComplete(BaseFuture future) throws Exception {
|
||||||
if (future.isSuccess()) {
|
if (future.isSuccess()) {
|
||||||
setState(BootstrapState.DIRECT_SUCCESS, "We are directly connected and visible to other peers.");
|
setState(BootstrapState.DIRECT_SUCCESS, "We are directly connected and visible to other peers.");
|
||||||
persistence.write(BootstrappedPeerFactory.this, "lastSuccessfulBootstrap", "default");
|
bootstrap("default");
|
||||||
settableFuture.set(peerDHT);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
setState(BootstrapState.DIRECT_NOT_SUCCEEDED, "We are probably behind a NAT and not reachable to " +
|
setState(BootstrapState.DIRECT_NOT_SUCCEEDED, "We are probably behind a NAT and not reachable to " +
|
||||||
"other peers. We try to setup automatic port forwarding.");
|
"other peers. We try to setup automatic port forwarding.");
|
||||||
|
|
||||||
tryPortForwarding();
|
tryPortForwarding();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -247,8 +246,7 @@ class BootstrappedPeerFactory {
|
||||||
public void operationComplete(BaseFuture future) throws Exception {
|
public void operationComplete(BaseFuture future) throws Exception {
|
||||||
if (future.isSuccess()) {
|
if (future.isSuccess()) {
|
||||||
setState(BootstrapState.NAT_SUCCESS, "Discover with automatic port forwarding was successful.");
|
setState(BootstrapState.NAT_SUCCESS, "Discover with automatic port forwarding was successful.");
|
||||||
persistence.write(BootstrappedPeerFactory.this, "lastSuccessfulBootstrap", "portForwarding");
|
bootstrap("portForwarding");
|
||||||
settableFuture.set(peerDHT);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
setState(BootstrapState.NAT_FAILED, "Discover with automatic port forwarding has failed " +
|
setState(BootstrapState.NAT_FAILED, "Discover with automatic port forwarding has failed " +
|
||||||
|
@ -282,8 +280,7 @@ class BootstrappedPeerFactory {
|
||||||
public void operationComplete(BaseFuture future) throws Exception {
|
public void operationComplete(BaseFuture future) throws Exception {
|
||||||
if (future.isSuccess()) {
|
if (future.isSuccess()) {
|
||||||
setState(BootstrapState.RELAY_SUCCESS, "Bootstrap using relay was successful.");
|
setState(BootstrapState.RELAY_SUCCESS, "Bootstrap using relay was successful.");
|
||||||
persistence.write(BootstrappedPeerFactory.this, "lastSuccessfulBootstrap", "relay");
|
bootstrap("relay");
|
||||||
settableFuture.set(peerDHT);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
setState(BootstrapState.RELAY_FAILED, "Bootstrap using relay has failed " + futureRelayNAT
|
setState(BootstrapState.RELAY_FAILED, "Bootstrap using relay has failed " + futureRelayNAT
|
||||||
|
@ -307,6 +304,30 @@ class BootstrappedPeerFactory {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void bootstrap(String state) {
|
||||||
|
FutureBootstrap futureBootstrap = peer.bootstrap().peerAddress(getBootstrapAddress()).start();
|
||||||
|
futureBootstrap.addListener(new BaseFutureListener<BaseFuture>() {
|
||||||
|
@Override
|
||||||
|
public void operationComplete(BaseFuture future) throws Exception {
|
||||||
|
if (futureBootstrap.isSuccess()) {
|
||||||
|
setState(BootstrapState.DIRECT_SUCCESS, "Bootstrap successful.");
|
||||||
|
persistence.write(BootstrappedPeerFactory.this, "lastSuccessfulBootstrap", state);
|
||||||
|
settableFuture.set(peerDHT);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setState(BootstrapState.DIRECT_NOT_SUCCEEDED, "Bootstrapping failed.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void exceptionCaught(Throwable t) throws Exception {
|
||||||
|
setState(BootstrapState.DIRECT_FAILED, "Exception at bootstrap: " + t.getMessage(), false);
|
||||||
|
peerDHT.shutdown();
|
||||||
|
settableFuture.setException(t);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private PeerAddress getBootstrapAddress() {
|
private PeerAddress getBootstrapAddress() {
|
||||||
try {
|
try {
|
||||||
return new PeerAddress(Number160.createHash(bootstrapNode.getId()),
|
return new PeerAddress(Number160.createHash(bootstrapNode.getId()),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue