mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 18:03:12 +01:00
Change discover handling
This commit is contained in:
parent
356b76a21a
commit
1d24a2aa38
@ -20,7 +20,6 @@ package io.bitsquare.app.cli;
|
|||||||
import io.bitsquare.network.Node;
|
import io.bitsquare.network.Node;
|
||||||
|
|
||||||
import net.tomp2p.dht.PeerBuilderDHT;
|
import net.tomp2p.dht.PeerBuilderDHT;
|
||||||
import net.tomp2p.dht.PeerDHT;
|
|
||||||
import net.tomp2p.nat.PeerBuilderNAT;
|
import net.tomp2p.nat.PeerBuilderNAT;
|
||||||
import net.tomp2p.p2p.Peer;
|
import net.tomp2p.p2p.Peer;
|
||||||
import net.tomp2p.p2p.PeerBuilder;
|
import net.tomp2p.p2p.PeerBuilder;
|
||||||
@ -28,7 +27,6 @@ import net.tomp2p.peers.Number160;
|
|||||||
import net.tomp2p.peers.PeerAddress;
|
import net.tomp2p.peers.PeerAddress;
|
||||||
import net.tomp2p.peers.PeerMapChangeListener;
|
import net.tomp2p.peers.PeerMapChangeListener;
|
||||||
import net.tomp2p.peers.PeerStatistic;
|
import net.tomp2p.peers.PeerStatistic;
|
||||||
import net.tomp2p.replication.IndirectReplication;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -54,39 +52,41 @@ public class BootstrapNode {
|
|||||||
try {
|
try {
|
||||||
Number160 peerId = Number160.createHash(name);
|
Number160 peerId = Number160.createHash(name);
|
||||||
peer = new PeerBuilder(peerId).ports(port).start();
|
peer = new PeerBuilder(peerId).ports(port).start();
|
||||||
/* peer.objectDataReply((sender, request) -> {
|
/*peer.objectDataReply((sender, request) -> {
|
||||||
log.trace("received request: " + request.toString());
|
log.trace("received request: " + request.toString());
|
||||||
return "pong";
|
return "pong";
|
||||||
});*/
|
});*/
|
||||||
|
|
||||||
PeerDHT peerDHT = new PeerBuilderDHT(peer).start();
|
new PeerBuilderDHT(peer).start();
|
||||||
new PeerBuilderNAT(peer).start();
|
new PeerBuilderNAT(peer).start();
|
||||||
new IndirectReplication(peerDHT).start();
|
|
||||||
|
|
||||||
peer.peerBean().peerMap().addPeerMapChangeListener(new PeerMapChangeListener() {
|
peer.peerBean().peerMap().addPeerMapChangeListener(new PeerMapChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void peerInserted(PeerAddress peerAddress, boolean verified) {
|
public void peerInserted(PeerAddress peerAddress, boolean verified) {
|
||||||
log.info("peerInserted: " + peerAddress);
|
log.debug("Peer inserted: peerAddress=" + peerAddress + ", verified=" + verified);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void peerRemoved(PeerAddress peerAddress, PeerStatistic storedPeerAddress) {
|
public void peerRemoved(PeerAddress peerAddress, PeerStatistic peerStatistics) {
|
||||||
log.info("peerRemoved: " + peerAddress);
|
log.debug("Peer removed: peerAddress=" + peerAddress + ", peerStatistics=" + peerStatistics);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void peerUpdated(PeerAddress peerAddress, PeerStatistic storedPeerAddress) {
|
public void peerUpdated(PeerAddress peerAddress, PeerStatistic peerStatistics) {
|
||||||
|
// log.debug("Peer updated: peerAddress=" + peerAddress + ", peerStatistics=" + peerStatistics);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
log.info("Bootstrap node started with name " + name + " and port " + port);
|
log.info("Bootstrap node started with name " + name + " and port " + port);
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
while (running) {
|
while (running) {
|
||||||
|
log.info("List of all peers online ----------------------------");
|
||||||
for (PeerAddress peerAddress : peer.peerBean().peerMap().all()) {
|
for (PeerAddress peerAddress : peer.peerBean().peerMap().all()) {
|
||||||
log.info("Peer online: " + peerAddress);
|
log.info(peerAddress.toString());
|
||||||
}
|
}
|
||||||
|
log.info("-----------------------------------------------------");
|
||||||
try {
|
try {
|
||||||
Thread.sleep(60000);
|
Thread.sleep(10000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -87,22 +87,22 @@ class MainPM extends PresentationModel<MainModel> {
|
|||||||
numPendingTrades.bind(model.numPendingTrades);
|
numPendingTrades.bind(model.numPendingTrades);
|
||||||
|
|
||||||
model.bootstrapState.addListener((ov, oldValue, newValue) -> {
|
model.bootstrapState.addListener((ov, oldValue, newValue) -> {
|
||||||
if (newValue == BootstrapState.DIRECT_SUCCESS ||
|
if (newValue == BootstrapState.DISCOVERY_NO_NAT_SUCCEEDED ||
|
||||||
newValue == BootstrapState.AUTO_PORT_FORWARDING_SUCCESS ||
|
newValue == BootstrapState.DISCOVERY_AUTO_PORT_FORWARDING_SUCCEEDED ||
|
||||||
newValue == BootstrapState.RELAY_SUCCESS) {
|
newValue == BootstrapState.RELAY_SUCCEEDED) {
|
||||||
bootstrapState.set("Successfully connected to P2P network: " + newValue.getMessage());
|
bootstrapState.set("Successfully connected to P2P network: " + newValue.getMessage());
|
||||||
bootstrapProgress.set(1);
|
bootstrapProgress.set(1);
|
||||||
|
|
||||||
if (newValue == BootstrapState.DIRECT_SUCCESS)
|
if (newValue == BootstrapState.DISCOVERY_NO_NAT_SUCCEEDED)
|
||||||
bootstrapIconId.set("image-connection-direct");
|
bootstrapIconId.set("image-connection-direct");
|
||||||
else if (newValue == BootstrapState.AUTO_PORT_FORWARDING_SUCCESS)
|
else if (newValue == BootstrapState.DISCOVERY_AUTO_PORT_FORWARDING_SUCCEEDED)
|
||||||
bootstrapIconId.set("image-connection-nat");
|
bootstrapIconId.set("image-connection-nat");
|
||||||
else if (newValue == BootstrapState.RELAY_SUCCESS)
|
else if (newValue == BootstrapState.RELAY_SUCCEEDED)
|
||||||
bootstrapIconId.set("image-connection-relay");
|
bootstrapIconId.set("image-connection-relay");
|
||||||
}
|
}
|
||||||
else if (newValue == BootstrapState.PEER_CREATION_FAILED ||
|
else if (newValue == BootstrapState.PEER_CREATION_FAILED ||
|
||||||
newValue == BootstrapState.DIRECT_FAILED ||
|
newValue == BootstrapState.DISCOVERY_FAILED ||
|
||||||
newValue == BootstrapState.AUTO_PORT_FORWARDING_FAILED ||
|
newValue == BootstrapState.DISCOVERY_AUTO_PORT_FORWARDING_FAILED ||
|
||||||
newValue == BootstrapState.RELAY_FAILED) {
|
newValue == BootstrapState.RELAY_FAILED) {
|
||||||
|
|
||||||
bootstrapErrorMsg.set(newValue.getMessage());
|
bootstrapErrorMsg.set(newValue.getMessage());
|
||||||
|
@ -19,7 +19,6 @@ package io.bitsquare.msg.tomp2p;
|
|||||||
|
|
||||||
import io.bitsquare.network.BootstrapState;
|
import io.bitsquare.network.BootstrapState;
|
||||||
import io.bitsquare.network.Node;
|
import io.bitsquare.network.Node;
|
||||||
import io.bitsquare.persistence.Persistence;
|
|
||||||
|
|
||||||
import com.google.common.util.concurrent.SettableFuture;
|
import com.google.common.util.concurrent.SettableFuture;
|
||||||
|
|
||||||
@ -54,7 +53,6 @@ import net.tomp2p.peers.Number160;
|
|||||||
import net.tomp2p.peers.PeerAddress;
|
import net.tomp2p.peers.PeerAddress;
|
||||||
import net.tomp2p.peers.PeerMapChangeListener;
|
import net.tomp2p.peers.PeerMapChangeListener;
|
||||||
import net.tomp2p.peers.PeerStatistic;
|
import net.tomp2p.peers.PeerStatistic;
|
||||||
import net.tomp2p.replication.IndirectReplication;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@ -78,7 +76,6 @@ class BootstrappedPeerFactory {
|
|||||||
private boolean useManualPortForwarding;
|
private boolean useManualPortForwarding;
|
||||||
private final Node bootstrapNode;
|
private final Node bootstrapNode;
|
||||||
private final String networkInterface;
|
private final String networkInterface;
|
||||||
private final Persistence persistence;
|
|
||||||
|
|
||||||
private final SettableFuture<PeerDHT> settableFuture = SettableFuture.create();
|
private final SettableFuture<PeerDHT> settableFuture = SettableFuture.create();
|
||||||
|
|
||||||
@ -92,12 +89,10 @@ class BootstrappedPeerFactory {
|
|||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public BootstrappedPeerFactory(Persistence persistence,
|
public BootstrappedPeerFactory(@Named(Node.PORT_KEY) int port,
|
||||||
@Named(Node.PORT_KEY) int port,
|
|
||||||
@Named(USE_MANUAL_PORT_FORWARDING_KEY) boolean useManualPortForwarding,
|
@Named(USE_MANUAL_PORT_FORWARDING_KEY) boolean useManualPortForwarding,
|
||||||
@Named(BOOTSTRAP_NODE_KEY) Node bootstrapNode,
|
@Named(BOOTSTRAP_NODE_KEY) Node bootstrapNode,
|
||||||
@Named(NETWORK_INTERFACE_KEY) String networkInterface) {
|
@Named(NETWORK_INTERFACE_KEY) String networkInterface) {
|
||||||
this.persistence = persistence;
|
|
||||||
this.port = port;
|
this.port = port;
|
||||||
this.useManualPortForwarding = useManualPortForwarding;
|
this.useManualPortForwarding = useManualPortForwarding;
|
||||||
this.bootstrapNode = bootstrapNode;
|
this.bootstrapNode = bootstrapNode;
|
||||||
@ -120,8 +115,6 @@ class BootstrappedPeerFactory {
|
|||||||
|
|
||||||
public SettableFuture<PeerDHT> start() {
|
public SettableFuture<PeerDHT> start() {
|
||||||
try {
|
try {
|
||||||
setState(BootstrapState.PEER_CREATION, "We create a P2P node.");
|
|
||||||
|
|
||||||
Bindings bindings = new Bindings();
|
Bindings bindings = new Bindings();
|
||||||
if (!NETWORK_INTERFACE_UNSPECIFIED.equals(networkInterface))
|
if (!NETWORK_INTERFACE_UNSPECIFIED.equals(networkInterface))
|
||||||
bindings.addInterface(networkInterface);
|
bindings.addInterface(networkInterface);
|
||||||
@ -132,19 +125,17 @@ class BootstrappedPeerFactory {
|
|||||||
.bindings(bindings)
|
.bindings(bindings)
|
||||||
.tcpPortForwarding(port)
|
.tcpPortForwarding(port)
|
||||||
.udpPortForwarding(port)
|
.udpPortForwarding(port)
|
||||||
.behindFirewall()
|
|
||||||
.start();
|
.start();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
peer = new PeerBuilder(keyPair)
|
peer = new PeerBuilder(keyPair)
|
||||||
.ports(port)
|
.ports(port)
|
||||||
.bindings(bindings)
|
.bindings(bindings)
|
||||||
.behindFirewall()
|
|
||||||
.start();
|
.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
peerDHT = new PeerBuilderDHT(peer).start();
|
peerDHT = new PeerBuilderDHT(peer).start();
|
||||||
new IndirectReplication(peerDHT).start();
|
setState(BootstrapState.PEER_CREATED, "We created a peerDHT.");
|
||||||
|
|
||||||
peer.peerBean().peerMap().addPeerMapChangeListener(new PeerMapChangeListener() {
|
peer.peerBean().peerMap().addPeerMapChangeListener(new PeerMapChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -163,46 +154,10 @@ class BootstrappedPeerFactory {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// We save last successful bootstrap method.
|
discoverExternalAddress();
|
||||||
// Reset it to BootstrapState.DIRECT_SUCCESS after 5 start ups.
|
|
||||||
Object bootstrapCounterObject = persistence.read(this, "bootstrapCounter");
|
|
||||||
int bootstrapCounter = 0;
|
|
||||||
if (bootstrapCounterObject instanceof Integer)
|
|
||||||
bootstrapCounter = (int) bootstrapCounterObject + 1;
|
|
||||||
|
|
||||||
if (bootstrapCounter > 5) {
|
|
||||||
persistence.write(this, "lastSuccessfulBootstrap", BootstrapState.DIRECT_SUCCESS);
|
|
||||||
bootstrapCounter = 0;
|
|
||||||
}
|
|
||||||
persistence.write(this, "bootstrapCounter", bootstrapCounter);
|
|
||||||
|
|
||||||
BootstrapState lastSuccessfulBootstrap = BootstrapState.DIRECT_SUCCESS;
|
|
||||||
Object lastSuccessfulBootstrapObject = persistence.read(this, "lastSuccessfulBootstrap");
|
|
||||||
if (lastSuccessfulBootstrapObject instanceof BootstrapState)
|
|
||||||
lastSuccessfulBootstrap = (BootstrapState) lastSuccessfulBootstrapObject;
|
|
||||||
else
|
|
||||||
persistence.write(this, "lastSuccessfulBootstrap", lastSuccessfulBootstrap);
|
|
||||||
|
|
||||||
log.debug("lastSuccessfulBootstrap = " + lastSuccessfulBootstrap);
|
|
||||||
|
|
||||||
// just temporary always start with trying direct connection
|
|
||||||
lastSuccessfulBootstrap = BootstrapState.DIRECT_SUCCESS;
|
|
||||||
|
|
||||||
switch (lastSuccessfulBootstrap) {
|
|
||||||
// For the moment we don't support relay mode as it has too much problems
|
|
||||||
/* case RELAY_SUCCESS:
|
|
||||||
bootstrapWithRelay();
|
|
||||||
break;*/
|
|
||||||
case AUTO_PORT_FORWARDING_SUCCESS:
|
|
||||||
tryPortForwarding();
|
|
||||||
break;
|
|
||||||
case DIRECT_SUCCESS:
|
|
||||||
default:
|
|
||||||
discover();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
handleError(BootstrapState.PEER_CREATION, "Cannot create peer with port: " + port + ". Exception: " + e);
|
handleError(BootstrapState.PEER_CREATION_FAILED, "Cannot create a peer with port: " +
|
||||||
|
port + ". Exception: " + e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return settableFuture;
|
return settableFuture;
|
||||||
@ -213,105 +168,73 @@ class BootstrappedPeerFactory {
|
|||||||
peerDHT.shutdown();
|
peerDHT.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1. Attempt: Try to discover our outside visible address
|
// We need to discover our external address and test if we are reachable for other nodes
|
||||||
private void discover() {
|
// We know our internal address from a discovery of our local network interfaces
|
||||||
setState(BootstrapState.DIRECT_INIT, "We are starting discovery against a bootstrap node.");
|
// We start a discover process with our bootstrap node.
|
||||||
FutureDiscover futureDiscover = peer.discover().peerAddress(getBootstrapAddress()).start();
|
// There are 4 cases:
|
||||||
futureDiscover.addListener(new BaseFutureListener<BaseFuture>() {
|
// 1. If we are not behind a NAT we get reported back the same address as our internal.
|
||||||
@Override
|
// 2. If we are behind a NAT and manual port forwarding is setup we get reported our external address from the
|
||||||
public void operationComplete(BaseFuture future) throws Exception {
|
// bootstrap node and the bootstrap node could ping us so we know we are reachable.
|
||||||
if (future.isSuccess()) {
|
// 3. If we are behind a NAT and the ping probes fails we need to setup port forwarding with UPnP or NAT-PMP.
|
||||||
|
// If that is successfully setup we need to try again a discover so we find out our external address and have
|
||||||
// We are well connected so we can offer our capabilities as relay node for other peers
|
// tested successfully our reachability (the additional discover is done internally from startSetupPortforwarding)
|
||||||
new PeerBuilderNAT(peer).start();
|
// 4. If the port forwarding failed we can try as last resort to open a permanent TCP connection to the
|
||||||
|
// bootstrap node and use that peer as relay (currently not supported as its too unstable)
|
||||||
if (useManualPortForwarding) {
|
|
||||||
setState(BootstrapState.MANUAL_PORT_FORWARDING_SUCCESS,
|
private void discoverExternalAddress() {
|
||||||
"We use manual port forwarding and are visible to other peers.");
|
|
||||||
bootstrap(BootstrapState.MANUAL_PORT_FORWARDING_SUCCESS);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
setState(BootstrapState.DIRECT_SUCCESS,
|
|
||||||
"We are directly connected and visible to other peers.");
|
|
||||||
bootstrap(BootstrapState.DIRECT_SUCCESS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
setState(BootstrapState.DIRECT_NOT_SUCCEEDED, "We are probably behind a NAT and not reachable to " +
|
|
||||||
"other peers. We try to setup automatic port forwarding.");
|
|
||||||
tryPortForwarding();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void exceptionCaught(Throwable t) throws Exception {
|
|
||||||
handleError(BootstrapState.DIRECT_FAILED, "Exception at discover: " + t.getMessage());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. Attempt: Try to set up port forwarding with UPNP and NAT-PMP
|
|
||||||
private void tryPortForwarding() {
|
|
||||||
setState(BootstrapState.AUTO_PORT_FORWARDING_INIT, "We are trying with automatic port forwarding.");
|
|
||||||
FutureDiscover futureDiscover = peer.discover().peerAddress(getBootstrapAddress()).start();
|
FutureDiscover futureDiscover = peer.discover().peerAddress(getBootstrapAddress()).start();
|
||||||
|
setState(BootstrapState.DISCOVERY_STARTED, "We are starting discovery against a bootstrap node.");
|
||||||
PeerNAT peerNAT = new PeerBuilderNAT(peer).start();
|
PeerNAT peerNAT = new PeerBuilderNAT(peer).start();
|
||||||
FutureNAT futureNAT = peerNAT.startSetupPortforwarding(futureDiscover);
|
FutureNAT futureNAT = peerNAT.startSetupPortforwarding(futureDiscover);
|
||||||
futureNAT.addListener(new BaseFutureListener<BaseFuture>() {
|
futureNAT.addListener(new BaseFutureListener<BaseFuture>() {
|
||||||
@Override
|
@Override
|
||||||
public void operationComplete(BaseFuture future) throws Exception {
|
public void operationComplete(BaseFuture future) throws Exception {
|
||||||
if (future.isSuccess()) {
|
// If futureDiscover was successful we are directly connected (or manual port forwarding is set)
|
||||||
setState(BootstrapState.AUTO_PORT_FORWARDING_SETUP_DONE, "Automatic port forwarding is setup. " +
|
if (futureDiscover.isSuccess()) {
|
||||||
"We need to do a discover process again.");
|
if (useManualPortForwarding) {
|
||||||
// we need a second discover process
|
setState(BootstrapState.DISCOVERY_MANUAL_PORT_FORWARDING_SUCCEEDED,
|
||||||
discoverAfterPortForwarding();
|
"We use manual port forwarding and are visible to other peers.");
|
||||||
|
bootstrap();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setState(BootstrapState.DISCOVERY_NO_NAT_SUCCEEDED,
|
||||||
|
"We are not behind a NAT and visible to other peers.");
|
||||||
|
bootstrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
handleError(BootstrapState.AUTO_PORT_FORWARDING_FAILED, "Automatic port forwarding failed. " +
|
setState(BootstrapState.DISCOVERY_AUTO_PORT_FORWARDING_STARTED,
|
||||||
"Fail reason: " + future.failedReason() +
|
"We are probably behind a NAT and not reachable to other peers. " +
|
||||||
"\nCheck if UPnP is not enabled on your router. " +
|
"We try to setup automatic port forwarding.");
|
||||||
"\nYou can try also to setup manual port forwarding. " +
|
if (futureNAT.isSuccess()) {
|
||||||
"\nRelay mode is currently not supported but will follow later. ");
|
setState(BootstrapState.DISCOVERY_AUTO_PORT_FORWARDING_SUCCEEDED,
|
||||||
|
"Discover with automatic port forwarding was successful.");
|
||||||
|
bootstrap();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
handleError(BootstrapState.DISCOVERY_AUTO_PORT_FORWARDING_FAILED, "Automatic port forwarding " +
|
||||||
|
"failed. " +
|
||||||
|
"Fail reason: " + future.failedReason() +
|
||||||
|
"\nCheck if UPnP is not enabled on your router. " +
|
||||||
|
"\nYou can try also to setup manual port forwarding. " +
|
||||||
|
"\nRelay mode is currently not supported but will follow later. ");
|
||||||
|
|
||||||
// For the moment we don't support relay mode as it has too much problems
|
// For the moment we don't support relay mode as it has too much problems
|
||||||
/* setState(BootstrapState.AUTO_PORT_FORWARDING_NOT_SUCCEEDED, "Port forwarding has failed. " +
|
/* setState(BootstrapState.AUTO_PORT_FORWARDING_NOT_SUCCEEDED, "Port forwarding has failed. " +
|
||||||
"We try to use a relay as next step.");
|
"We try to use a relay as next step.");
|
||||||
bootstrapWithRelay();*/
|
bootstrapWithRelay();*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exceptionCaught(Throwable t) throws Exception {
|
public void exceptionCaught(Throwable t) throws Exception {
|
||||||
handleError(BootstrapState.AUTO_PORT_FORWARDING_FAILED, "Exception at port forwarding: " + t
|
handleError(BootstrapState.DISCOVERY_FAILED, "Exception at discover visibility: " + t
|
||||||
.getMessage());
|
.getMessage());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to determine our outside visible address after port forwarding is setup
|
|
||||||
private void discoverAfterPortForwarding() {
|
|
||||||
FutureDiscover futureDiscover = peer.discover().peerAddress(getBootstrapAddress()).start();
|
|
||||||
futureDiscover.addListener(new BaseFutureListener<BaseFuture>() {
|
|
||||||
@Override
|
|
||||||
public void operationComplete(BaseFuture future) throws Exception {
|
|
||||||
if (future.isSuccess()) {
|
|
||||||
setState(BootstrapState.AUTO_PORT_FORWARDING_SUCCESS, "Discover with automatic port forwarding " +
|
|
||||||
"was successful.");
|
|
||||||
bootstrap(BootstrapState.AUTO_PORT_FORWARDING_SUCCESS);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
handleError(BootstrapState.AUTO_PORT_FORWARDING_FAILED, "Discover with automatic port forwarding " +
|
|
||||||
"has failed " +
|
|
||||||
futureDiscover.failedReason());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void exceptionCaught(Throwable t) throws Exception {
|
|
||||||
handleError(BootstrapState.AUTO_PORT_FORWARDING_FAILED, "Exception at discover: " + t.getMessage());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// For the moment we don't support relay mode as it has too much problems
|
// For the moment we don't support relay mode as it has too much problems
|
||||||
// 3. Attempt: We try to use another peer as relay
|
// 3. Attempt: We try to use another peer as relay
|
||||||
/* private void bootstrapWithRelay() {
|
/* private void bootstrapWithRelay() {
|
||||||
@ -340,25 +263,25 @@ class BootstrappedPeerFactory {
|
|||||||
});
|
});
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
private void bootstrap(BootstrapState state) {
|
private void bootstrap() {
|
||||||
FutureBootstrap futureBootstrap = peer.bootstrap().peerAddress(getBootstrapAddress()).start();
|
FutureBootstrap futureBootstrap = peer.bootstrap().peerAddress(getBootstrapAddress()).start();
|
||||||
|
setState(BootstrapState.BOOT_STRAP_STARTED, "Bootstrap started.");
|
||||||
futureBootstrap.addListener(new BaseFutureListener<BaseFuture>() {
|
futureBootstrap.addListener(new BaseFutureListener<BaseFuture>() {
|
||||||
@Override
|
@Override
|
||||||
public void operationComplete(BaseFuture future) throws Exception {
|
public void operationComplete(BaseFuture future) throws Exception {
|
||||||
if (futureBootstrap.isSuccess()) {
|
if (futureBootstrap.isSuccess()) {
|
||||||
setState(state, "Bootstrap successful.");
|
setState(BootstrapState.BOOT_STRAP_SUCCEEDED, "Bootstrap successful.");
|
||||||
persistence.write(BootstrappedPeerFactory.this, "lastSuccessfulBootstrap", state);
|
|
||||||
settableFuture.set(peerDHT);
|
settableFuture.set(peerDHT);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
handleError(BootstrapState.DIRECT_NOT_SUCCEEDED, "Bootstrapping failed. " +
|
handleError(BootstrapState.BOOT_STRAP_FAILED, "Bootstrapping failed. " +
|
||||||
futureBootstrap.failedReason());
|
futureBootstrap.failedReason());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exceptionCaught(Throwable t) throws Exception {
|
public void exceptionCaught(Throwable t) throws Exception {
|
||||||
handleError(BootstrapState.DIRECT_FAILED, "Exception at bootstrap: " + t.getMessage());
|
handleError(BootstrapState.BOOT_STRAP_FAILED, "Exception at bootstrap: " + t.getMessage());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -399,7 +322,6 @@ class BootstrappedPeerFactory {
|
|||||||
|
|
||||||
private void handleError(BootstrapState state, String errorMessage) {
|
private void handleError(BootstrapState state, String errorMessage) {
|
||||||
setState(state, errorMessage, false);
|
setState(state, errorMessage, false);
|
||||||
persistence.write(this, "lastSuccessfulBootstrap", BootstrapState.DIRECT_SUCCESS);
|
|
||||||
peerDHT.shutdown();
|
peerDHT.shutdown();
|
||||||
settableFuture.setException(new Exception(errorMessage));
|
settableFuture.setException(new Exception(errorMessage));
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,6 @@ import net.tomp2p.futures.BaseFutureListener;
|
|||||||
import net.tomp2p.futures.FutureDirect;
|
import net.tomp2p.futures.FutureDirect;
|
||||||
import net.tomp2p.peers.Number160;
|
import net.tomp2p.peers.Number160;
|
||||||
import net.tomp2p.peers.PeerAddress;
|
import net.tomp2p.peers.PeerAddress;
|
||||||
import net.tomp2p.peers.PeerSocketAddress;
|
|
||||||
import net.tomp2p.storage.Data;
|
import net.tomp2p.storage.Data;
|
||||||
import net.tomp2p.utils.Utils;
|
import net.tomp2p.utils.Utils;
|
||||||
|
|
||||||
@ -378,13 +377,13 @@ public class TomP2PNode implements ClientNode {
|
|||||||
public ConnectionType getConnectionType() {
|
public ConnectionType getConnectionType() {
|
||||||
BootstrapState bootstrapState = bootstrappedPeerFactory.getBootstrapState().get();
|
BootstrapState bootstrapState = bootstrappedPeerFactory.getBootstrapState().get();
|
||||||
switch (bootstrapState) {
|
switch (bootstrapState) {
|
||||||
case DIRECT_SUCCESS:
|
case DISCOVERY_NO_NAT_SUCCEEDED:
|
||||||
return ConnectionType.DIRECT;
|
return ConnectionType.DIRECT;
|
||||||
case MANUAL_PORT_FORWARDING_SUCCESS:
|
case DISCOVERY_MANUAL_PORT_FORWARDING_SUCCEEDED:
|
||||||
return ConnectionType.MANUAL_PORT_FORWARDING;
|
return ConnectionType.MANUAL_PORT_FORWARDING;
|
||||||
case AUTO_PORT_FORWARDING_SUCCESS:
|
case DISCOVERY_AUTO_PORT_FORWARDING_SUCCEEDED:
|
||||||
return ConnectionType.AUTO_PORT_FORWARDING;
|
return ConnectionType.AUTO_PORT_FORWARDING;
|
||||||
case RELAY_SUCCESS:
|
case RELAY_SUCCEEDED:
|
||||||
return ConnectionType.RELAY;
|
return ConnectionType.RELAY;
|
||||||
default:
|
default:
|
||||||
throw new BitsquareException("Invalid bootstrap state: %s", bootstrapState);
|
throw new BitsquareException("Invalid bootstrap state: %s", bootstrapState);
|
||||||
@ -393,11 +392,11 @@ public class TomP2PNode implements ClientNode {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Node getAddress() {
|
public Node getAddress() {
|
||||||
PeerSocketAddress socketAddress = peerDHT.peerAddress().peerSocketAddress();
|
PeerAddress peerAddress = peerDHT.peerBean().serverPeerAddress();
|
||||||
return Node.at(
|
return Node.at(
|
||||||
peerDHT.peerID().toString(),
|
peerDHT.peerID().toString(),
|
||||||
socketAddress.inetAddress().toString(),
|
peerAddress.inetAddress().getHostAddress(),
|
||||||
socketAddress.tcpPort());
|
peerAddress.peerSocketAddress().tcpPort());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -17,25 +17,22 @@
|
|||||||
|
|
||||||
package io.bitsquare.network;
|
package io.bitsquare.network;
|
||||||
|
|
||||||
/**
|
|
||||||
* NOT_SUCCEEDED means we will try the next step, FAILED is used for fatal failures which will terminate the bootstrap
|
|
||||||
*/
|
|
||||||
public enum BootstrapState {
|
public enum BootstrapState {
|
||||||
PEER_CREATION,
|
PEER_CREATED,
|
||||||
PEER_CREATION_FAILED,
|
PEER_CREATION_FAILED,
|
||||||
DIRECT_INIT,
|
DISCOVERY_STARTED,
|
||||||
DIRECT_SUCCESS,
|
DISCOVERY_NO_NAT_SUCCEEDED,
|
||||||
DIRECT_NOT_SUCCEEDED,
|
DISCOVERY_MANUAL_PORT_FORWARDING_SUCCEEDED,
|
||||||
DIRECT_FAILED,
|
DISCOVERY_FAILED,
|
||||||
MANUAL_PORT_FORWARDING_SUCCESS,
|
DISCOVERY_AUTO_PORT_FORWARDING_STARTED,
|
||||||
AUTO_PORT_FORWARDING_INIT,
|
DISCOVERY_AUTO_PORT_FORWARDING_SUCCEEDED,
|
||||||
AUTO_PORT_FORWARDING_SETUP_DONE,
|
DISCOVERY_AUTO_PORT_FORWARDING_FAILED,
|
||||||
AUTO_PORT_FORWARDING_SUCCESS,
|
RELAY_STARTED,
|
||||||
AUTO_PORT_FORWARDING_NOT_SUCCEEDED,
|
RELAY_SUCCEEDED,
|
||||||
AUTO_PORT_FORWARDING_FAILED,
|
RELAY_FAILED,
|
||||||
RELAY_INIT,
|
BOOT_STRAP_STARTED,
|
||||||
RELAY_SUCCESS,
|
BOOT_STRAP_SUCCEEDED,
|
||||||
RELAY_FAILED;
|
BOOT_STRAP_FAILED;
|
||||||
|
|
||||||
private String message;
|
private String message;
|
||||||
|
|
||||||
|
@ -38,14 +38,19 @@
|
|||||||
<logger name="io.netty.channel" level="WARN"/>
|
<logger name="io.netty.channel" level="WARN"/>
|
||||||
<logger name="io.netty.buffer" level="WARN"/>
|
<logger name="io.netty.buffer" level="WARN"/>
|
||||||
|
|
||||||
<logger name="io.bitsquare.gui.ViewController" level="OFF"/>
|
<logger name="io.bitsquare.gui.UIModel" level="WARN"/>
|
||||||
<logger name="io.bitsquare.gui.CachedViewController" level="OFF"/>
|
<logger name="io.bitsquare.gui.PresentationModel" level="WARN"/>
|
||||||
<logger name="io.bitsquare.gui.util.Profiler" level="TRACE"/>
|
<logger name="io.bitsquare.gui.ViewController" level="WARN"/>
|
||||||
|
<logger name="io.bitsquare.gui.ViewCB" level="WARN"/>
|
||||||
|
<logger name="io.bitsquare.gui.CachedViewCB" level="WARN"/>
|
||||||
|
<logger name="io.bitsquare.gui.util.Profiler" level="WARN"/>
|
||||||
|
<logger name="io.bitsquare.persistence.Persistence" level="WARN"/>
|
||||||
|
|
||||||
|
|
||||||
<logger name="org.bitcoinj.core.BitcoinSerializer" level="WARN"/>
|
<logger name="org.bitcoinj.core.BitcoinSerializer" level="WARN"/>
|
||||||
<logger name="org.bitcoinj.core.AbstractBlockChain" level="WARN"/>
|
<logger name="org.bitcoinj.core.AbstractBlockChain" level="WARN"/>
|
||||||
<logger name="org.bitcoinj.wallet.DeterministicKeyChain" level="WARN"/>
|
<logger name="org.bitcoinj.wallet.DeterministicKeyChain" level="WARN"/>
|
||||||
|
<logger name="io.bitsquare.btc.WalletService" level="WARN"/>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
<logger name="org.bitcoinj.core.Wallet" level="OFF"/>
|
<logger name="org.bitcoinj.core.Wallet" level="OFF"/>
|
||||||
|
@ -33,7 +33,6 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import net.tomp2p.connection.Bindings;
|
import net.tomp2p.connection.Bindings;
|
||||||
import net.tomp2p.connection.ChannelClientConfiguration;
|
|
||||||
import net.tomp2p.connection.StandardProtocolFamily;
|
import net.tomp2p.connection.StandardProtocolFamily;
|
||||||
import net.tomp2p.dht.FutureGet;
|
import net.tomp2p.dht.FutureGet;
|
||||||
import net.tomp2p.dht.FuturePut;
|
import net.tomp2p.dht.FuturePut;
|
||||||
@ -54,8 +53,6 @@ import net.tomp2p.p2p.Peer;
|
|||||||
import net.tomp2p.p2p.PeerBuilder;
|
import net.tomp2p.p2p.PeerBuilder;
|
||||||
import net.tomp2p.peers.Number160;
|
import net.tomp2p.peers.Number160;
|
||||||
import net.tomp2p.peers.PeerAddress;
|
import net.tomp2p.peers.PeerAddress;
|
||||||
import net.tomp2p.peers.PeerMap;
|
|
||||||
import net.tomp2p.peers.PeerMapConfiguration;
|
|
||||||
import net.tomp2p.relay.RelayConfig;
|
import net.tomp2p.relay.RelayConfig;
|
||||||
import net.tomp2p.storage.Data;
|
import net.tomp2p.storage.Data;
|
||||||
|
|
||||||
@ -529,14 +526,19 @@ public class TomP2PTests {
|
|||||||
private Peer bootstrapDirectConnection(int clientPort) {
|
private Peer bootstrapDirectConnection(int clientPort) {
|
||||||
Peer peer = null;
|
Peer peer = null;
|
||||||
try {
|
try {
|
||||||
Number160 peerId = Number160.createHash(UUID.randomUUID().toString());
|
/* Number160 peerId = Number160.createHash(UUID.randomUUID().toString());
|
||||||
PeerMapConfiguration pmc = new PeerMapConfiguration(peerId).peerNoVerification();
|
PeerMapConfiguration pmc = new PeerMapConfiguration(peerId).peerNoVerification();
|
||||||
PeerMap pm = new PeerMap(pmc);
|
PeerMap pm = new PeerMap(pmc);
|
||||||
ChannelClientConfiguration cc = PeerBuilder.createDefaultChannelClientConfiguration();
|
ChannelClientConfiguration cc = PeerBuilder.createDefaultChannelClientConfiguration();
|
||||||
cc.maxPermitsTCP(100);
|
cc.maxPermitsTCP(100);
|
||||||
cc.maxPermitsUDP(100);
|
cc.maxPermitsUDP(100);
|
||||||
peer = new PeerBuilder(peerId).bindings(getBindings()).channelClientConfiguration(cc).peerMap(pm)
|
peer = new PeerBuilder(peerId).bindings(getBindings()).channelClientConfiguration(cc).peerMap(pm)
|
||||||
|
.ports(clientPort).start();*/
|
||||||
|
|
||||||
|
Number160 peerId = Number160.createHash(UUID.randomUUID().toString());
|
||||||
|
peer = new PeerBuilder(peerId).bindings(getBindings())
|
||||||
.ports(clientPort).start();
|
.ports(clientPort).start();
|
||||||
|
|
||||||
FutureDiscover futureDiscover = peer.discover().peerAddress(BOOTSTRAP_NODE_ADDRESS).start();
|
FutureDiscover futureDiscover = peer.discover().peerAddress(BOOTSTRAP_NODE_ADDRESS).start();
|
||||||
futureDiscover.awaitUninterruptibly();
|
futureDiscover.awaitUninterruptibly();
|
||||||
if (futureDiscover.isSuccess()) {
|
if (futureDiscover.isSuccess()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user