Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Add UPnP Support #1334

Merged
merged 211 commits into from
Jul 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
211 commits
Select commit Hold shift + click to select a range
056f51e
Initial commit of UPnP functionality using jupnp
notlesh Apr 25, 2019
a2fc9db
Improve documentation (esp. javadocs) for UpnpNatManager
notlesh Apr 27, 2019
0e9882b
Tweak comments (appease spotless)
notlesh Apr 27, 2019
588d24b
Add basic unit tests for UpnpNatManager
notlesh May 3, 2019
3c8df09
Remove dead code and excessive logging from UpnpNatManager
notlesh May 3, 2019
898197e
Network vs node configuration (#1223)
MadelineMurray Apr 7, 2019
1167230
Make contract size limit configurable. (#1227)
rojotek Apr 7, 2019
039c620
custom deserializer for TopicsParameter (#1235)
macfarla Apr 7, 2019
7066859
Updated eea_getTransactionReceipt to include extra parameter
MadelineMurray Apr 7, 2019
03b008c
Updated Permissions Configuration File for new CLI options (#1234)
MadelineMurray Apr 8, 2019
e3d7349
[PIE-1224] Different request limits for different request types (#1224)
AbdelStark Apr 8, 2019
2df50ff
Enable pipeline chain downloader for fast sync. (#1232)
ajsutton Apr 8, 2019
954a8fc
[PRIV-45] Improve eea_sendRawTransaction error messages (#1238)
Puneetha17 Apr 9, 2019
ecd1667
Added permissioning overview (#1242)
MadelineMurray Apr 9, 2019
133c1f3
Update PantheonCommand.java (#1245)
AbdelStark Apr 9, 2019
b1e918c
[PRIV-41] Refactor PrivacyParameters config to use builder pattern (#…
antonydenyer Apr 9, 2019
69e3bda
Reduce memory usage in import (#1239)
shemnon Apr 9, 2019
e96004a
Feature/pie 1502 ewp options cli (#1246)
AbdelStark Apr 9, 2019
f70a619
added note (#1244)
MadelineMurray Apr 10, 2019
8889cf2
Fixed link (#1249)
MadelineMurray Apr 10, 2019
1eafb7d
Added note about using node permissioning only (#1243)
MadelineMurray Apr 10, 2019
8703ed3
Feature/pie 1502 ewp options cli (#1255)
AbdelStark Apr 10, 2019
1b4bceb
Choose sync target based on td rather than height (#1256)
mbaxter Apr 10, 2019
8b1f604
Added 1.0.3 updates (#1250)
MadelineMurray Apr 10, 2019
bb09192
added content on free gas (#1252)
MadelineMurray Apr 10, 2019
55b33d2
[PAN-2433] Fix netty pipeline (#1257)
mbaxter Apr 10, 2019
fa17cd8
[Gradle Release Plugin] - pre tag commit: '1.0.3'.
pegasys-admin Apr 10, 2019
8a84992
[Gradle Release Plugin] - new version commit: '1.1.0-SNAPSHOT'.
pegasys-admin Apr 10, 2019
8690418
[PAN-2529] subscribing to sync events should receive false when in sy…
Errorific Apr 11, 2019
1b2e2b1
[Minor] Ignore extra json rpc params (#1261)
mbaxter Apr 11, 2019
8a99708
[PRIV-44] Use single instance of Rocksdb for privacy (#1247)
Puneetha17 Apr 11, 2019
3bf8d0d
[PAN-2499] debug trace transaction (#1258)
AbdelStark Apr 11, 2019
6240b13
Added fast sync options (#1241)
MadelineMurray Apr 11, 2019
379f945
PAN-2404 - Make PeerDiscovertAgentTest less flakey. (#1262)
shemnon Apr 11, 2019
e486e49
PIE-1505 - Build broken in Java 12 (#1263)
shemnon Apr 11, 2019
1a22d28
RocksDB Statistics in Metrics (#1169)
shemnon Apr 11, 2019
11334ba
Allow use of / in branch name when using the branch from tag release …
jframe Apr 12, 2019
505e236
Normalize EnodeURLs (#1264)
mbaxter Apr 12, 2019
33ccff1
Expose sync mode option (#1270)
AbdelStark Apr 12, 2019
4cf8e91
Feature/move subclass in pantheon command (#1272)
AbdelStark Apr 12, 2019
deb6040
[PRIV-46] Use labelled timer to differentiate between rocks db metric…
Puneetha17 Apr 12, 2019
45c61e8
Keep enode nodeId stored as a BytesValue (#1274)
mbaxter Apr 12, 2019
f8d354f
Refactor RocksDBStats (#1266)
shemnon Apr 13, 2019
f65c3d8
Create EnodeURL Builder (#1275)
mbaxter Apr 14, 2019
35e9a9e
Add block trace RPC methods (#1088)
kziemianek Apr 15, 2019
42b81da
Log error when a JSON decode problem is encountered (#1278)
CjHare Apr 15, 2019
faebb4a
[MINOR] migrate TransactionPool (& affiliated test) from 'core' to 'e…
smatthewenglish Apr 15, 2019
1c0758b
fetch local transactions in isolation (#1259)
smatthewenglish Apr 15, 2019
9131d4a
Rollback to rocksdb 5.15.10 (#1279)
shemnon Apr 15, 2019
a2518a2
[PAN-2560] Cleanup PeerConnection interface (#1282)
mbaxter Apr 15, 2019
77f432f
[PIE-7] Ignore transactions from the network while behind chain head …
smatthewenglish Apr 15, 2019
fb64b5d
Fix running ATs with in-process node runner (#1285)
ajsutton Apr 15, 2019
b8c80ff
Simplify enode construction (#1283)
mbaxter Apr 16, 2019
e9adfc2
[PRIV-54] Use default enclave public key to generate eea_getTransacti…
Puneetha17 Apr 16, 2019
33e0dd4
Update permissioning smart contract interface to match updated EEA pr…
Errorific Apr 16, 2019
a024bf4
[PAN-2560] Consolidate p2p node info methods (#1288)
mbaxter Apr 16, 2019
c6c2179
Undo changes to PendingTransactions method visibility (#1281)
mbaxter Apr 16, 2019
18d5896
Switch to new sync target if it exceeds the td threshold (#1286)
ajsutton Apr 16, 2019
1812c58
Better errors for when permissioning contract is set up wrong (#1296)
Errorific Apr 17, 2019
d387899
Remove --fast-sync-wait-time option (#1297)
ajsutton Apr 17, 2019
3fcf7b0
PAN-2485#Add net_services json rpc endpoint (#1295)
usmananwar Apr 17, 2019
6cdd98a
Fix RunnerBuilder method names (#1284)
mbaxter Apr 17, 2019
8094b4d
Updated eth_getTransactionCount
MadelineMurray Apr 17, 2019
2284e09
Added 1.1 RC changes (#1298)
MadelineMurray Apr 17, 2019
e9c944a
Implement max message size rather than limiting with fixed number of …
AbdelStark Apr 17, 2019
0260314
Pipeline based full sync (#1291)
ajsutton Apr 17, 2019
481a3fa
Removed available in 1.1 notes and added links from CLI options (#1294)
MadelineMurray Apr 17, 2019
bbf6c17
Added txpool pantheon statistics endpoint. (#1293)
rojotek Apr 17, 2019
61fe4ea
[Gradle Release Plugin] - pre tag commit: '1.1.0-RC1'.
pegasys-admin Apr 17, 2019
9dd30fe
[Gradle Release Plugin] - new version commit: '1.1.1-SNAPSHOT'.
pegasys-admin Apr 17, 2019
334a471
Removing 'all' from the help wording for host-whitelist (as that no l…
CjHare Apr 18, 2019
0cc83f4
Remove remnants of the old dev mode. (#1307)
ajsutton Apr 20, 2019
d153c2d
Stop synchronizer prior to stopping the network (#1302)
ajsutton Apr 21, 2019
2741efd
PAN-2577 - missing p2p info when queried live (#1310)
shemnon Apr 22, 2019
5abde68
tx limit size send peers follow up (#1308)
AbdelStark Apr 22, 2019
93b4fde
Configure RocksDb max background compaction and thread count (#1312)
ajsutton Apr 23, 2019
097fb61
Remove duplicate init code from PantheonController instances (#1305)
ajsutton Apr 23, 2019
886c53b
PIE-1526: Fix account permissioning check case matching (#1314)
lucassaldanha Apr 23, 2019
706a8b3
[PAN-1339] Send local transactions to new peers (#1253)
smatthewenglish Apr 23, 2019
7cdb381
Update Enclave executePost method (#1317)
AbdelStark Apr 23, 2019
3f99d87
Use header validation mode for ommers (#1313)
ajsutton Apr 23, 2019
92af164
PIE-1526: Normalize account permissioning addresses in whitelist (#1320)
lucassaldanha Apr 23, 2019
5361632
Require block numbers for debug_traceBlockByNumber to be in hex (#1326)
ajsutton Apr 24, 2019
1637040
Ensure eth scheduler is stopped in tests (#1324)
ajsutton Apr 24, 2019
dffcefd
Improve logging of chain download errors in the pipeline chain downlo…
ajsutton Apr 24, 2019
e3476aa
[PAN-1878] Provide error message when invalid key specified in key fi…
AbdelStark Apr 24, 2019
e234af7
Allow use of large chain ids (#1289)
jframe Apr 24, 2019
fa85847
[PAN-2576] Allow whitespace in path (#1327)
AbdelStark Apr 24, 2019
d7f054d
[PIE-1531] Allow whitespace in file paths loaded from resources direc…
AbdelStark Apr 24, 2019
57fbcff
[PAN-2574] Fix failed tests on Windows (#1332)
AbdelStark Apr 25, 2019
c59ea96
[PAN-1062] Evict old transactions (1 of 2) (#1299)
smatthewenglish Apr 25, 2019
04be323
Ensured that the transaction statistics endpoint is exposed. (#1330)
rojotek Apr 26, 2019
80e1c50
JsonRpcError decoding to include message (#1336)
CjHare Apr 26, 2019
d37e984
[PRIV-55] Allow private contract invocations in multiple privacy grou…
iikirilov Apr 26, 2019
d7fa801
removed unstable fast sync note in documentation (#1341)
NicolasMassart Apr 26, 2019
3985f31
Cache current chain head info (#1335)
ajsutton Apr 26, 2019
9ef3906
Added net_services (#1306)
MadelineMurray Apr 27, 2019
8b41ce7
Updated for returning false (#1309)
MadelineMurray Apr 27, 2019
466199d
Added sending private transactions initial content (#1301)
MadelineMurray Apr 27, 2019
c403fe3
Upated Docker image to indicate it doesn't run on Windows (#1346)
MadelineMurray Apr 28, 2019
312187d
[PAN-2573] include static nodes in permissioning logic (#1339)
macfarla Apr 28, 2019
4f94c84
Removed all option for host-whitelist (#1347)
MadelineMurray Apr 28, 2019
23d0210
Added content on using multinode example (#1345)
MadelineMurray Apr 28, 2019
9bc95d3
Don't abort in-progress master builds when a new commit is added. (#1…
ajsutton Apr 29, 2019
bf1c14f
Updating Orion to 0.9.0 (#1359)
lucassaldanha Apr 29, 2019
ddf1695
Added txpool_pantheonStatistics (#1354)
MadelineMurray Apr 29, 2019
9e99589
Removed privacy quickstart reference (#1361)
MadelineMurray Apr 29, 2019
7824f01
Updated overview (#1362)
MadelineMurray Apr 29, 2019
4703067
Onchain permissioning (#1300)
MadelineMurray Apr 29, 2019
7eec639
Update Private-Transaction-Processing.md (#1352)
jacobhackman Apr 29, 2019
d3ef26a
Update Using-Configuration-File.md (#1351)
jacobhackman Apr 29, 2019
e152dd4
[PAN-2588] Create P2PNetwork Builder (#1343)
mbaxter Apr 29, 2019
66d79ad
[PRIV-65] eea_getTransactionCount fails if account has not interacted…
iikirilov Apr 29, 2019
834d1a1
Added requirement to enable JSON-RPC (#1365)
MadelineMurray Apr 29, 2019
d91a01c
Request open ended headers from sync target (#1355)
ajsutton Apr 29, 2019
3ee61ef
Increase RocksDB max-background-compactions and background-thread-cou…
ajsutton Apr 29, 2019
c93dbbf
Added 1.1 changes (#1356)
MadelineMurray Apr 29, 2019
daa025a
Update roadmap (#1371)
arash009 Apr 29, 2019
0090901
[PAN-1062] Specify pending transaction retention period (2 of 2) (#1333)
smatthewenglish Apr 30, 2019
9d4561c
Handle the pipeline being aborted while finalizing an async operation…
ajsutton Apr 30, 2019
363573d
Enable the pipeline chain downloader by default (#1344)
ajsutton Apr 30, 2019
681e1fc
[MINOR] Rename rocksdDbConfiguration to rocksDbConfiguration (#1375)
smatthewenglish Apr 30, 2019
0069f61
[PAN-2595] Consolidate local enode representation (#1376)
mbaxter May 1, 2019
e1583b9
Use execute instead of submit so unhandled exceptions get logged (#1379)
ajsutton May 1, 2019
d928ac1
[PAN-2585] Prefer EnodeURL over Endpoint (#1378)
mbaxter May 1, 2019
af11178
[PAN-2605] Add getPeer method to PeerConnection (#1383)
mbaxter May 1, 2019
e63f645
Remove EthTaskChainDownloader and supporting code (#1373)
ajsutton May 1, 2019
17b37c3
Remove unnecessary field (#1384)
mbaxter May 1, 2019
9936142
Use streams and avoid iterating child nodes multiple times (#1380)
ajsutton May 1, 2019
094e420
Removing smart quotes (#1381)
jmcnevin May 2, 2019
6205fc5
Update Log message in IBFT Controller (#1387)
rain-on May 2, 2019
8e914ce
Fixed typo (#1388)
MadelineMurray May 2, 2019
477e15c
update python mkdocs requirements versions (#1374)
NicolasMassart May 2, 2019
f9f83c6
Handle case where peers advertise a listening port of 0 (#1391)
mbaxter May 2, 2019
7cdb378
Add explanatory comment about default port (#1392)
mbaxter May 2, 2019
530e9dd
Added privacy roadmap (#1386)
MadelineMurray May 2, 2019
9cbce02
Queue pending requests when all peers are busy (#1331)
ajsutton May 2, 2019
a5583a6
Wait for next message to be sent in FullSyncChainDownloaderTest. (#1394)
ajsutton May 2, 2019
93aa2b6
Update Create-Permissioned-Network.md (#1353)
jacobhackman May 3, 2019
169f56d
Update Transactions.md (#1350)
jacobhackman May 3, 2019
583d1a2
Update Bootnodes.md (#1349)
jacobhackman May 3, 2019
c56e87a
fixes PIE-1499 remove hotjar tag as we can manage all tags with Googl…
NicolasMassart May 3, 2019
9cb4267
Merge branch 'master' into upnp_support
shemnon May 6, 2019
07b06e6
Attempt to configure NAT environment before init'ing networking
notlesh May 6, 2019
61a6877
Remove jetty from gradle config (expect runtime error in jupnp)
notlesh May 6, 2019
30cc0dd
Avoid some of the rawtypes warnings caused by UpnpNatManager
notlesh May 6, 2019
440b5c7
spotlessApply
notlesh May 6, 2019
a87c782
Capture local address when querying UPnP external address
notlesh May 6, 2019
baf2e98
Merge branch 'master' of github.com:PegaSysEng/pantheon into PR1334
shemnon May 7, 2019
b6945e5
update style on dependencies
shemnon May 7, 2019
c097c29
hand made configuration for Jupnp
shemnon May 7, 2019
596a15b
Provide CLI switch for UPnP functionality
notlesh May 13, 2019
cc21d03
Merge branch 'master' into upnp_support
notlesh May 14, 2019
b19fc45
Use enum for NAT/UPnP configuration instead of boolean
notlesh May 15, 2019
bf9f7ce
Add tests to ensure the --nat-method CLI switch is processed correctly
notlesh May 15, 2019
edf180f
UPnP: kick off external IP address query automatically from start(), …
notlesh May 17, 2019
e67b42d
spotlessApply
notlesh May 17, 2019
cbae50c
Merge remote-tracking branch 'upstream/master' into upnp_support
notlesh May 17, 2019
b8c4dd3
Clean up UpnpNatManager api and logging
notlesh May 18, 2019
8ac5486
Move UpnpNatManager creation to RunnerBuilder, integrate with JsonRpc…
notlesh May 18, 2019
427ef1a
Update acceptance tests with new JsonRpcHttpServiceTest() ctor args
notlesh May 20, 2019
c7a2fc2
Avoid Java 9+ API (CompletableFuture.copy())
notlesh May 20, 2019
e140b27
Make UpnpNatManagerTest threadsafe, add related unit tests
notlesh May 29, 2019
366345b
More UpnpManager tests
notlesh May 29, 2019
7ceb095
Merge remote-tracking branch 'upstream/master' into upnp_support
notlesh May 29, 2019
a3dd961
Merge branch 'master' into upnp_support
mbaxter Jun 11, 2019
1cbf393
Merge branch 'master' into upnp_support
mbaxter Jun 14, 2019
3cf3006
Merge branch 'master' into upnp_support
mbaxter Jun 20, 2019
90b9065
Merge pull request #5 from mbaxter/upnp_support
notlesh Jun 21, 2019
becac87
Avoid storing natMethod in NetworkingConfiguration,
notlesh Jun 22, 2019
7e67b4d
Add timeout and log output to UPnP query
notlesh Jun 22, 2019
7c18e0a
Remove insultingly worthless comments
notlesh Jun 22, 2019
c045cf8
Update pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonComma…
notlesh Jun 22, 2019
a4cb18f
Update ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/…
notlesh Jun 22, 2019
537d01d
Update ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/…
notlesh Jun 22, 2019
68f46c6
Update docs/Reference/Pantheon-CLI-Syntax.md
notlesh Jun 22, 2019
a2b9f0f
Remove dead code
notlesh Jun 22, 2019
868ce8b
Add test case to handle invlaid --unpn-method parameter
notlesh Jun 22, 2019
04e882c
Make chained-ctor package-private
notlesh Jun 22, 2019
567c638
Remove redundant initiation of UPnP search query
notlesh Jun 22, 2019
034855f
Update ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/…
notlesh Jun 22, 2019
d05b3f2
Use parameterized log messages instead of explicit string concat
notlesh Jun 24, 2019
f696f83
Guard all UpnpNatManager public functions with a check against !started
notlesh Jun 25, 2019
cd51bbb
Don't test that UpnpService calls controlPoint.search(), won't happen…
notlesh Jun 25, 2019
52d1814
Update other log statements in UpnpNatManager to avoid explicit strin…
notlesh Jun 25, 2019
b453162
Merge branch 'upnp_support' of github.com:notlesh/pantheon into upnp_…
notlesh Jun 25, 2019
026cb51
Detect when second UPnP WANIPConnection service is observed and log a…
notlesh Jun 25, 2019
f4c1171
Annotate UpnpNatManager.getWANIPConnectionService() as @VisibleForTes…
notlesh Jun 25, 2019
ca38031
Remove comment about UpnpNatManager not being threadsafe
notlesh Jun 25, 2019
764ba12
Chain port forward request to external ip address query instead of Wa…
notlesh Jun 26, 2019
6d573c3
Request UPnP port forwards after listening ports have been resolved
notlesh Jun 27, 2019
58ae310
Start UpnpNatManager from main Runner, not from DefaultP2PNetwork
notlesh Jun 27, 2019
75c9232
Release port forwards on shutdown
notlesh Jun 27, 2019
fde8913
s/DefaultRegistryListener/PantheonUpnpRegistryListener/
notlesh Jun 27, 2019
bedbb12
Create enum for TCP/UDP Protocol instead of using String
notlesh Jul 1, 2019
776c51f
Shut down UpnpNatManager in Runner (same place it's started)
notlesh Jul 2, 2019
16a71a9
Advertise detected NAT external IP address in PeerDiscoveryAgent
notlesh Jul 2, 2019
0e08f04
Track CompletableFuture's created for UPnP RemoteService discovery so…
notlesh Jul 3, 2019
970bbcb
Merge remote-tracking branch 'upstream/master' into upnp_support
notlesh Jul 3, 2019
9733681
Move NAT functionality to its own root-level subproject
notlesh Jul 3, 2019
e1d386b
Fix nat setup ordering and discovery port forwarding
mbaxter Jul 3, 2019
79dc1ea
Setup json-rpc port forwarding after port is fully resolved
mbaxter Jul 3, 2019
1ba824c
Remove unnecessary dependencies
mbaxter Jul 3, 2019
74ba64c
Shutdown services in the reverse order they were started
mbaxter Jul 3, 2019
34d40dc
Make package name match directory structure
mbaxter Jul 3, 2019
083f897
Style - use final where possible, use Optional over Nullable values
mbaxter Jul 3, 2019
2f0a5f7
Shutdown configuration executor
mbaxter Jul 3, 2019
e461e69
Merge pull request #6 from mbaxter/upnp_support
notlesh Jul 3, 2019
e75c957
Don't throw in UpnpNatManager.start() when already started; update te…
notlesh Jul 5, 2019
70bf74d
Merge branch 'master' into upnp_support
Jul 6, 2019
15d6176
update submodule reference
shemnon Jul 6, 2019
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
21 changes: 21 additions & 0 deletions docs/Reference/Pantheon-CLI-Syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,27 @@ The default is 30303. Ports must be [exposed appropriately](../Configuring-Panth
!!!note
This option is not used when running Pantheon from the [Docker image](../Getting-Started/Run-Docker-Image.md#exposing-ports).

### nat-method

```bash tab="Syntax"
--nat-method=UPNP
```

```bash tab="Example Configuration File"
nat-method="UPNP"
```

Specify the method for handling NAT environments. Options are: `UPNP` and `NONE`.
The default is `NONE`, which disables NAT functionality.

!!!tip
`UPNP` works well with a typical home or small office environment where a wireless router or modem provides NAT isolation. This should provide
automatic detection and port-forwarding. UPnP support is often disabled by default in networking equipment firmware, however, any may need to be
explicitly enabled.

!!!note
Option `UPNP` may introduce delays during node startup, especially on networks where no UPnP gateway device can be found.

### permissions-accounts-config-file-enabled

```bash tab="Syntax"
Expand Down
1 change: 1 addition & 0 deletions ethereum/jsonrpc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dependencies {
implementation project(':ethereum:rlp')
implementation project(':ethereum:permissioning')
implementation project(':metrics:core')
implementation project(':nat')

implementation 'com.google.guava:guava'
implementation 'io.vertx:vertx-core'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import tech.pegasys.pantheon.metrics.OperationTimer;
import tech.pegasys.pantheon.metrics.OperationTimer.TimingContext;
import tech.pegasys.pantheon.metrics.PantheonMetricCategory;
import tech.pegasys.pantheon.nat.upnp.UpnpNatManager;
import tech.pegasys.pantheon.util.NetworkUtility;

import java.net.InetSocketAddress;
Expand Down Expand Up @@ -82,6 +83,7 @@ public class JsonRpcHttpService {
private final Vertx vertx;
private final JsonRpcConfiguration config;
private final RpcMethods rpcMethods;
private final Optional<UpnpNatManager> natManager;
private final Path dataDir;
private final LabelledMetric<OperationTimer> requestTimer;

Expand All @@ -91,11 +93,24 @@ public class JsonRpcHttpService {
private final HealthService livenessService;
private final HealthService readinessService;

/**
* Construct a JsonRpcHttpService handler
*
* @param vertx The vertx process that will be running this service
* @param dataDir The data directory where requests can be buffered
* @param config Configuration for the rpc methods being loaded
* @param metricsSystem The metrics service that activities should be reported to
* @param natManager The NAT environment manager.
* @param methods The json rpc methods that should be enabled
* @param livenessService A service responsible for reporting whether this node is live
* @param readinessService A service responsible for reporting whether this node has fully started
*/
public JsonRpcHttpService(
final Vertx vertx,
final Path dataDir,
final JsonRpcConfiguration config,
final MetricsSystem metricsSystem,
final Optional<UpnpNatManager> natManager,
final Map<String, JsonRpcMethod> methods,
final HealthService livenessService,
final HealthService readinessService) {
Expand All @@ -104,6 +119,7 @@ public JsonRpcHttpService(
dataDir,
config,
metricsSystem,
natManager,
methods,
AuthenticationService.create(vertx, config),
livenessService,
Expand All @@ -115,6 +131,7 @@ private JsonRpcHttpService(
final Path dataDir,
final JsonRpcConfiguration config,
final MetricsSystem metricsSystem,
final Optional<UpnpNatManager> natManager,
final Map<String, JsonRpcMethod> methods,
final Optional<AuthenticationService> authenticationService,
final HealthService livenessService,
Expand All @@ -129,6 +146,7 @@ private JsonRpcHttpService(
validateConfig(config);
this.config = config;
this.vertx = vertx;
this.natManager = natManager;
this.rpcMethods = new RpcMethods(methods);
this.authenticationService = authenticationService;
this.livenessService = livenessService;
Expand All @@ -144,6 +162,7 @@ private void validateConfig(final JsonRpcConfiguration config) {

public CompletableFuture<?> start() {
LOG.info("Starting JsonRPC service on {}:{}", config.getHost(), config.getPort());

// Create the HTTP server and a router object.
httpServer =
vertx.createHttpServer(
Expand Down Expand Up @@ -207,6 +226,13 @@ public CompletableFuture<?> start() {
LOG.info(
"JsonRPC service started and listening on {}:{}", config.getHost(), actualPort);
config.setPort(actualPort);
// Request that a NAT port forward for our server port
if (natManager.isPresent()) {
natManager
.get()
.requestPortForward(
config.getPort(), UpnpNatManager.Protocol.TCP, "partheon-json-rpc");
}
return;
}
httpServer = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ public void setupTest() throws Exception {
folder.newFolder().toPath(),
config,
new NoOpMetricsSystem(),
Optional.empty(),
methods,
HealthService.ALWAYS_HEALTHY,
HealthService.ALWAYS_HEALTHY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;

import java.util.HashMap;
import java.util.Optional;

import com.google.common.collect.Lists;
import io.vertx.core.Vertx;
Expand Down Expand Up @@ -193,6 +194,7 @@ private JsonRpcHttpService createJsonRpcHttpServiceWithAllowedDomains(
folder.newFolder().toPath(),
config,
new NoOpMetricsSystem(),
Optional.empty(),
new HashMap<>(),
HealthService.ALWAYS_HEALTHY,
HealthService.ALWAYS_HEALTHY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ private JsonRpcHttpService createJsonRpcHttpService() throws Exception {
folder.newFolder().toPath(),
jsonRpcConfig,
new NoOpMetricsSystem(),
Optional.empty(),
rpcMethods,
HealthService.ALWAYS_HEALTHY,
HealthService.ALWAYS_HEALTHY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ private static JsonRpcHttpService createJsonRpcHttpService() throws Exception {
folder.newFolder().toPath(),
config,
new NoOpMetricsSystem(),
Optional.empty(),
rpcMethods,
HealthService.ALWAYS_HEALTHY,
HealthService.ALWAYS_HEALTHY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ private JsonRpcHttpService createJsonRpcHttpServiceWithRpcApis(final JsonRpcConf
folder.newFolder().toPath(),
config,
new NoOpMetricsSystem(),
Optional.empty(),
rpcMethods,
HealthService.ALWAYS_HEALTHY,
HealthService.ALWAYS_HEALTHY);
Expand Down Expand Up @@ -301,6 +302,7 @@ private JsonRpcHttpService createJsonRpcHttpService(
folder.newFolder().toPath(),
jsonRpcConfiguration,
new NoOpMetricsSystem(),
Optional.empty(),
rpcMethods,
HealthService.ALWAYS_HEALTHY,
HealthService.ALWAYS_HEALTHY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ private static JsonRpcHttpService createJsonRpcHttpService(final JsonRpcConfigur
folder.newFolder().toPath(),
config,
new NoOpMetricsSystem(),
Optional.empty(),
rpcMethods,
HealthService.ALWAYS_HEALTHY,
HealthService.ALWAYS_HEALTHY);
Expand All @@ -165,6 +166,7 @@ private static JsonRpcHttpService createJsonRpcHttpService() throws Exception {
folder.newFolder().toPath(),
createJsonRpcConfig(),
new NoOpMetricsSystem(),
Optional.empty(),
rpcMethods,
HealthService.ALWAYS_HEALTHY,
HealthService.ALWAYS_HEALTHY);
Expand Down
1 change: 1 addition & 0 deletions ethereum/p2p/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies {
implementation project(':ethereum:core')
implementation project(':ethereum:rlp')
implementation project(':metrics:core')
implementation project(':nat')

implementation 'com.google.guava:guava'
implementation 'io.prometheus:simpleclient'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import tech.pegasys.pantheon.ethereum.p2p.peers.PeerId;
import tech.pegasys.pantheon.ethereum.p2p.permissions.PeerPermissions;
import tech.pegasys.pantheon.metrics.MetricsSystem;
import tech.pegasys.pantheon.nat.upnp.UpnpNatManager;
import tech.pegasys.pantheon.util.NetworkUtility;
import tech.pegasys.pantheon.util.Subscribers;
import tech.pegasys.pantheon.util.bytes.BytesValue;
Expand All @@ -39,6 +40,7 @@
import java.util.OptionalInt;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -61,6 +63,7 @@ public abstract class PeerDiscoveryAgent {
protected final List<DiscoveryPeer> bootstrapPeers;
private final List<PeerRequirement> peerRequirements = new CopyOnWriteArrayList<>();
private final PeerPermissions peerPermissions;
private final Optional<UpnpNatManager> natManager;
private final MetricsSystem metricsSystem;
/* The peer controller, which takes care of the state machine of peers. */
protected Optional<PeerDiscoveryController> controller = Optional.empty();
Expand All @@ -83,6 +86,7 @@ public PeerDiscoveryAgent(
final SECP256K1.KeyPair keyPair,
final DiscoveryConfiguration config,
final PeerPermissions peerPermissions,
final Optional<UpnpNatManager> natManager,
final MetricsSystem metricsSystem) {
this.metricsSystem = metricsSystem;
checkArgument(keyPair != null, "keypair cannot be null");
Expand All @@ -91,6 +95,7 @@ public PeerDiscoveryAgent(
validateConfiguration(config);

this.peerPermissions = peerPermissions;
this.natManager = natManager;
this.bootstrapPeers =
config.getBootnodes().stream().map(DiscoveryPeer::fromEnode).collect(Collectors.toList());

Expand All @@ -117,6 +122,26 @@ public CompletableFuture<Integer> start(final int tcpPort) {
final int port = config.getBindPort();
LOG.info("Starting peer discovery agent on host={}, port={}", host, port);

// override advertised host if we detect an external IP address via NAT manager
String externalIpAddress = null;
if (natManager.isPresent()) {
try {
final int timeoutSeconds = 60;
LOG.info("Waiting for up to {} seconds to detect external IP address...", timeoutSeconds);
externalIpAddress =
natManager.get().queryExternalIPAddress().get(timeoutSeconds, TimeUnit.SECONDS);

} catch (Exception e) {
LOG.warn(
"Caught exception while trying to query NAT external IP address (ignoring): {}", e);
}
}

final String advertisedAddress =
(null != externalIpAddress && !externalIpAddress.equals(""))
? externalIpAddress
: config.getAdvertisedHost();

return listenForConnections()
.thenApply(
(InetSocketAddress localAddress) -> {
Expand All @@ -126,7 +151,7 @@ public CompletableFuture<Integer> start(final int tcpPort) {
DiscoveryPeer.fromEnode(
EnodeURL.builder()
.nodeId(id)
.ipAddress(config.getAdvertisedHost())
.ipAddress(advertisedAddress)
.listeningPort(tcpPort)
.discoveryPort(discoveryPort)
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
import tech.pegasys.pantheon.ethereum.p2p.permissions.PeerPermissions;
import tech.pegasys.pantheon.metrics.MetricsSystem;
import tech.pegasys.pantheon.metrics.PantheonMetricCategory;
import tech.pegasys.pantheon.nat.upnp.UpnpNatManager;
import tech.pegasys.pantheon.util.NetworkUtility;

import java.io.IOException;
import java.net.BindException;
import java.net.InetSocketAddress;
import java.net.SocketException;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.concurrent.CompletableFuture;
import java.util.function.IntSupplier;
Expand Down Expand Up @@ -58,8 +60,9 @@ public VertxPeerDiscoveryAgent(
final KeyPair keyPair,
final DiscoveryConfiguration config,
final PeerPermissions peerPermissions,
final Optional<UpnpNatManager> natManager,
final MetricsSystem metricsSystem) {
super(keyPair, config, peerPermissions, metricsSystem);
super(keyPair, config, peerPermissions, natManager, metricsSystem);
checkArgument(vertx != null, "vertx instance cannot be null");
this.vertx = vertx;

Expand Down
Loading