Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UPnP support for peer discovery. Resolves #1036 #1073

Closed
wants to merge 17 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added two more unit tests, one of which requires @VisibleForTesting.
CoeJoder committed Nov 8, 2019
commit e196ecd8a20bd6299d004704beaff250679e2cb8
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
package co.rsk.net.discovery.upnp;

import co.rsk.config.InternalService;
import com.google.common.annotations.VisibleForTesting;
import org.bitlet.weupnp.GatewayDevice;
import org.bitlet.weupnp.GatewayDiscover;
import org.ethereum.config.SystemProperties;
@@ -206,4 +207,9 @@ private synchronized boolean isValidGateway(GatewayDevice gateway) {
return false;
}
}

@VisibleForTesting
Map<InetAddress, UpnpGatewayManager> getCachedGatewayManagers() {
return cachedGatewayManagers;
}
}
Original file line number Diff line number Diff line change
@@ -43,6 +43,7 @@ public final class UpnpServiceTest {
private static final String LOCAL_ADDRESS_VALID_1 = "192.168.0.100";
private static final String LOCAL_ADDRESS_VALID_2 = "192.168.1.100";
private static final String LOCAL_ADDRESS_INVALID = "192.168.0.101";
private static final String LOCAL_ADDRESS_UNKNOWN_HOST = "[" + LOCAL_ADDRESS_VALID_1 + "]";
private static final String VALID_GATEWAY_NAME_1 = "Valid Mock Gateway 1";
private static final String VALID_GATEWAY_NAME_2 = "Valid Mock Gateway 2";
private static final String INVALID_GATEWAY_NAME = "Invalid Mock Gateway";
@@ -156,6 +157,32 @@ private static UpnpService createAndStartUpnpService(GatewayDiscover query) {
return upnpService;
}

@Test
public void testExceptionDuringStop() {
UpnpService testService = createAndStartUpnpService(mockWildcardDiscoverValid);
testService.findGateway();

// force a NPE during stop()'s Executor task construction
testService.getCachedGatewayManagers().clear();
testService.getCachedGatewayManagers().put(wildcardAddress, null);

try {
testService.stop();
} catch (Exception e) {
Assert.fail("Should not throw Exception when stop()'s cleanup fails.");
}
}

@Test
public void testStringAddressThrowsUnknownHost() {
UpnpService testService = createAndStartUpnpService(mockWildcardDiscoverValid);
Optional<UpnpGatewayManager> gdm = testService.findGateway(LOCAL_ADDRESS_UNKNOWN_HOST);
Assert.assertFalse(
"An unresolvable hostname should not return a gateway manager",
gdm.isPresent()
);
}

@Test
public void testStopWithoutValidSearchResults() {
try {