mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-25 07:27:18 +01:00
Adopt tests for manual port forwarding, rename NAT to AUTO_PORT_FORWARDING
This commit is contained in:
parent
dc464b36e4
commit
103542dd87
6 changed files with 51 additions and 30 deletions
|
@ -88,21 +88,21 @@ class MainPM extends PresentationModel<MainModel> {
|
|||
|
||||
model.bootstrapState.addListener((ov, oldValue, newValue) -> {
|
||||
if (newValue == BootstrapState.DIRECT_SUCCESS ||
|
||||
newValue == BootstrapState.NAT_SUCCESS ||
|
||||
newValue == BootstrapState.AUTO_PORT_FORWARDING_SUCCESS ||
|
||||
newValue == BootstrapState.RELAY_SUCCESS) {
|
||||
bootstrapState.set("Successfully connected to P2P network: " + newValue.getMessage());
|
||||
bootstrapProgress.set(1);
|
||||
|
||||
if (newValue == BootstrapState.DIRECT_SUCCESS)
|
||||
bootstrapIconId.set("image-connection-direct");
|
||||
else if (newValue == BootstrapState.NAT_SUCCESS)
|
||||
else if (newValue == BootstrapState.AUTO_PORT_FORWARDING_SUCCESS)
|
||||
bootstrapIconId.set("image-connection-nat");
|
||||
else if (newValue == BootstrapState.RELAY_SUCCESS)
|
||||
bootstrapIconId.set("image-connection-relay");
|
||||
}
|
||||
else if (newValue == BootstrapState.PEER_CREATION_FAILED ||
|
||||
newValue == BootstrapState.DIRECT_FAILED ||
|
||||
newValue == BootstrapState.NAT_FAILED ||
|
||||
newValue == BootstrapState.AUTO_PORT_FORWARDING_FAILED ||
|
||||
newValue == BootstrapState.RELAY_FAILED) {
|
||||
|
||||
bootstrapErrorMsg.set(newValue.getMessage());
|
||||
|
|
|
@ -191,7 +191,7 @@ class BootstrappedPeerFactory {
|
|||
case RELAY_SUCCESS:
|
||||
bootstrapWithRelay();
|
||||
break;
|
||||
case NAT_SUCCESS:
|
||||
case AUTO_PORT_FORWARDING_SUCCESS:
|
||||
tryPortForwarding();
|
||||
break;
|
||||
case DIRECT_SUCCESS:
|
||||
|
@ -246,7 +246,7 @@ class BootstrappedPeerFactory {
|
|||
|
||||
// 2. Attempt: Try to set up port forwarding with UPNP and NAT-PMP
|
||||
private void tryPortForwarding() {
|
||||
setState(BootstrapState.NAT_INIT, "We are trying with automatic port forwarding.");
|
||||
setState(BootstrapState.AUTO_PORT_FORWARDING_INIT, "We are trying with automatic port forwarding.");
|
||||
FutureDiscover futureDiscover = peer.discover().peerAddress(getBootstrapAddress()).start();
|
||||
PeerNAT peerNAT = new PeerBuilderNAT(peer).start();
|
||||
FutureNAT futureNAT = peerNAT.startSetupPortforwarding(futureDiscover);
|
||||
|
@ -254,13 +254,13 @@ class BootstrappedPeerFactory {
|
|||
@Override
|
||||
public void operationComplete(BaseFuture future) throws Exception {
|
||||
if (future.isSuccess()) {
|
||||
setState(BootstrapState.NAT_SETUP_DONE, "Automatic port forwarding is setup. " +
|
||||
setState(BootstrapState.AUTO_PORT_FORWARDING_SETUP_DONE, "Automatic port forwarding is setup. " +
|
||||
"We need to do a discover process again.");
|
||||
// we need a second discover process
|
||||
discoverAfterPortForwarding();
|
||||
}
|
||||
else {
|
||||
setState(BootstrapState.NAT_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.");
|
||||
bootstrapWithRelay();
|
||||
}
|
||||
|
@ -268,7 +268,8 @@ class BootstrappedPeerFactory {
|
|||
|
||||
@Override
|
||||
public void exceptionCaught(Throwable t) throws Exception {
|
||||
handleError(BootstrapState.NAT_FAILED, "Exception at port forwarding: " + t.getMessage());
|
||||
handleError(BootstrapState.AUTO_PORT_FORWARDING_FAILED, "Exception at port forwarding: " + t
|
||||
.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -280,18 +281,19 @@ class BootstrappedPeerFactory {
|
|||
@Override
|
||||
public void operationComplete(BaseFuture future) throws Exception {
|
||||
if (future.isSuccess()) {
|
||||
setState(BootstrapState.NAT_SUCCESS, "Discover with automatic port forwarding was successful.");
|
||||
bootstrap(BootstrapState.NAT_SUCCESS);
|
||||
setState(BootstrapState.AUTO_PORT_FORWARDING_SUCCESS, "Discover with automatic port forwarding " +
|
||||
"was successful.");
|
||||
bootstrap(BootstrapState.AUTO_PORT_FORWARDING_SUCCESS);
|
||||
}
|
||||
else {
|
||||
handleError(BootstrapState.NAT_FAILED, "Discover with automatic port forwarding has failed " +
|
||||
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.NAT_FAILED, "Exception at discover: " + t.getMessage());
|
||||
handleError(BootstrapState.AUTO_PORT_FORWARDING_FAILED, "Exception at discover: " + t.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -382,8 +382,8 @@ public class TomP2PNode implements ClientNode {
|
|||
return ConnectionType.DIRECT;
|
||||
case MANUAL_PORT_FORWARDING_SUCCESS:
|
||||
return ConnectionType.MANUAL_PORT_FORWARDING;
|
||||
case NAT_SUCCESS:
|
||||
return ConnectionType.NAT;
|
||||
case AUTO_PORT_FORWARDING_SUCCESS:
|
||||
return ConnectionType.AUTO_PORT_FORWARDING;
|
||||
case RELAY_SUCCESS:
|
||||
return ConnectionType.RELAY;
|
||||
default:
|
||||
|
|
|
@ -28,11 +28,11 @@ public enum BootstrapState {
|
|||
DIRECT_NOT_SUCCEEDED,
|
||||
DIRECT_FAILED,
|
||||
MANUAL_PORT_FORWARDING_SUCCESS,
|
||||
NAT_INIT,
|
||||
NAT_SETUP_DONE,
|
||||
NAT_SUCCESS,
|
||||
NAT_NOT_SUCCEEDED,
|
||||
NAT_FAILED,
|
||||
AUTO_PORT_FORWARDING_INIT,
|
||||
AUTO_PORT_FORWARDING_SETUP_DONE,
|
||||
AUTO_PORT_FORWARDING_SUCCESS,
|
||||
AUTO_PORT_FORWARDING_NOT_SUCCEEDED,
|
||||
AUTO_PORT_FORWARDING_FAILED,
|
||||
RELAY_INIT,
|
||||
RELAY_SUCCESS,
|
||||
RELAY_FAILED;
|
||||
|
|
|
@ -18,5 +18,5 @@
|
|||
package io.bitsquare.network;
|
||||
|
||||
public enum ConnectionType {
|
||||
UNKNOWN, DIRECT, MANUAL_PORT_FORWARDING, NAT, RELAY
|
||||
UNKNOWN, DIRECT, MANUAL_PORT_FORWARDING, AUTO_PORT_FORWARDING, RELAY
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ public class TomP2PTests {
|
|||
private static final Logger log = LoggerFactory.getLogger(TomP2PTests.class);
|
||||
|
||||
// If you want to test in one specific connection mode define it directly, otherwise use UNKNOWN
|
||||
private static final ConnectionType FORCED_CONNECTION_TYPE = ConnectionType.DIRECT;
|
||||
private static final ConnectionType FORCED_CONNECTION_TYPE = ConnectionType.MANUAL_PORT_FORWARDING;
|
||||
|
||||
// Typically you run the bootstrap node in localhost to test direct connection.
|
||||
// If you have a setup where you are not behind a router you can also use a WAN bootstrap node.
|
||||
|
@ -116,8 +116,8 @@ public class TomP2PTests {
|
|||
|
||||
@Before
|
||||
public void setUp() {
|
||||
client1Port = 7777;
|
||||
client2Port = 7778;
|
||||
client1Port = 7367;
|
||||
client2Port = 7368;
|
||||
}
|
||||
|
||||
@After
|
||||
|
@ -153,8 +153,9 @@ public class TomP2PTests {
|
|||
@Test
|
||||
@Repeat(STRESS_TEST_COUNT)
|
||||
public void testBootstrapWithPortForwarding() throws Exception {
|
||||
if (FORCED_CONNECTION_TYPE == ConnectionType.NAT) {
|
||||
peer = bootstrapWithPortForwarding(client1Port);
|
||||
if (FORCED_CONNECTION_TYPE == ConnectionType.AUTO_PORT_FORWARDING ||
|
||||
FORCED_CONNECTION_TYPE == ConnectionType.MANUAL_PORT_FORWARDING) {
|
||||
peer = bootstrapWithPortForwarding(client2Port);
|
||||
assertNotNull(peer);
|
||||
}
|
||||
}
|
||||
|
@ -570,9 +571,22 @@ public class TomP2PTests {
|
|||
Number160 peerId = Number160.createHash(UUID.randomUUID().toString());
|
||||
Peer peer = null;
|
||||
try {
|
||||
peer = new PeerBuilder(peerId).bindings(getBindings()).behindFirewall()
|
||||
.ports(clientPort).start();
|
||||
|
||||
if (FORCED_CONNECTION_TYPE == ConnectionType.MANUAL_PORT_FORWARDING ||
|
||||
resolvedConnectionType == ConnectionType.MANUAL_PORT_FORWARDING) {
|
||||
peer = new PeerBuilder(peerId).bindings(getBindings())
|
||||
.behindFirewall()
|
||||
.tcpPortForwarding(clientPort)
|
||||
.udpPortForwarding(clientPort)
|
||||
.ports(clientPort)
|
||||
.start();
|
||||
}
|
||||
else {
|
||||
peer = new PeerBuilder(peerId).bindings(getBindings())
|
||||
.behindFirewall()
|
||||
.ports(clientPort)
|
||||
.start();
|
||||
}
|
||||
|
||||
PeerNAT peerNAT = new PeerBuilderNAT(peer).start();
|
||||
FutureDiscover futureDiscover = peer.discover().peerAddress(BOOTSTRAP_NODE_ADDRESS).start();
|
||||
FutureNAT futureNAT = peerNAT.startSetupPortforwarding(futureDiscover);
|
||||
|
@ -668,7 +682,12 @@ public class TomP2PTests {
|
|||
if (peer != null)
|
||||
return peer;
|
||||
|
||||
resolvedConnectionType = ConnectionType.NAT;
|
||||
resolvedConnectionType = ConnectionType.MANUAL_PORT_FORWARDING;
|
||||
peer = bootstrapWithPortForwarding(clientPort);
|
||||
if (peer != null)
|
||||
return peer;
|
||||
|
||||
resolvedConnectionType = ConnectionType.AUTO_PORT_FORWARDING;
|
||||
peer = bootstrapWithPortForwarding(clientPort);
|
||||
if (peer != null)
|
||||
return peer;
|
||||
|
@ -689,7 +708,7 @@ public class TomP2PTests {
|
|||
if (FORCED_CONNECTION_TYPE == ConnectionType.DIRECT) {
|
||||
peer = bootstrapDirectConnection(clientPort);
|
||||
}
|
||||
else if (FORCED_CONNECTION_TYPE == ConnectionType.NAT) {
|
||||
else if (FORCED_CONNECTION_TYPE == ConnectionType.AUTO_PORT_FORWARDING) {
|
||||
peer = bootstrapWithPortForwarding(clientPort);
|
||||
}
|
||||
else if (FORCED_CONNECTION_TYPE == ConnectionType.RELAY) {
|
||||
|
|
Loading…
Add table
Reference in a new issue