Add UPnP support for peer discovery. Resolves #1036 #1088
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Feature description:
UPnP is toggleable by the config property
peer.discovery.upnp_enabled
and is enabled by default.If automatic port mapping fails, a log message notifies the user to enable UPnP on their router, or disable UPnP in the node conf and forward router ports manually.
Any automatic port mapping created via UPnP on the router is deleted upon node shutdown.
Implementation notes:
The
UpnpService
is injected intoUDPServer
if the service was enabled in the conf. This is the only service using UPnP right now.There are three TCP services running:
Web3WebSocketServer
,Web3HttpServer
,PeerServerImpl
. All three of these services are configurable with different network interfaces/local addresses, each of which could be connected to unique WAN gateways. IfUpnpService
was injected into these server objects, it could handle the port mapping easily. But that is out of scope for this ticket.There is one unit test which relies on
@VisibleForTesting
(UpnpServiceTest::testExceptionDuringStop()
)There are two integration test which rely on
PowerMockito
which was already being used in the test class (RskContextTest::testPeerDiscoveryWithUpnpEnabled()
andRskContextTest::testPeerDiscoveryWithUpnpDisabled()
).TODO:
There is a new dependency on the weUPnP library, see rsksmart/reproducible-builds#19. The
build.gradle
dependency is currently using the SHA hash of the public repo, but should be switched to that of the reproducible build when it is ready.