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

[BOUNTY-2] Explicit Configuration & General internal NAT API #190

Closed
wants to merge 12 commits into from

Conversation

matkt
Copy link
Contributor

@matkt matkt commented Nov 15, 2019

Signed-off-by: Karim TAAM karim.t2am@gmail.com

PR description

Create a general internal API to support Network Address Translation (NAT) technologies in Besu. The goal of this work is to offer developers a consistent API for performing NAT tasks so that I can abstractly add support for new NAT systems (e.g. Docker, Kubernetes, etc.) with a minimum amount of code changes. As a second NAT style, explicit configuration for all ports and IP addresses would be available.

A few comments

Java APIs to determine if a node is in a NAT environment, and then identify the kind of NAT environment

The method is passed using the --nat-method parameter. If the method is not passed in argument the client will try to detect it automatically. Automatic detection is being developed.
it is possible to call isNATEnvironment to get the result

Java APIs to enable/disable the NAT port forwarding if the environment requires it, as well as APIs to determine if such calls are needed or making the enable/disable calls a no-op when it is unneeded.

As requested, the generic API does not allow to enable or disable the port forwading. requestPortForward and releasePortForward are only available in the UPNP implementation

Ability to explicitly configure the external IP to broadcast without regards to NAT or other considerations.

A new command-line parameter --nat-external-ip-usage-enabled has been added to allow the user to force the usage of the external ip addresss, otherwise the p2pAdvertisedHost is used. The default value is true

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Copy link
Contributor

@shemnon shemnon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's hard for me to provide quality feedback because this PR is too large, 1,600 changed lines. I can't wrap my head around it in anything less than an hour. The few comments I left were before I realized that was why I was having a hard time thinking deeply about it. This needs to be split up into several smaller PRs. Here's some ideas on how

  • A PR that just refactors the existing UPNP/None options into the NatManager
  • A PR that renames and moves files with no other changes to the desired places and names.
  • A PR to add network reporting files (besu.network)
  • A PR to add reporting in the Admin Info
  • A PR that adds manual NAT settings into the newly refactored NatManager
  • A PR that adds docker support into the newly refactored NatManager
  • A PR that adds K8s support into the newly refactoed NatManager.

It looks like docker, k8s, and manual are not in this PR, but there are some config options set up for them. Don't add these until the code adding them is brought in, it makes the PR look like it's doing more than it intends.

Also, minimize moving methods around if possible, it increases the diff count and makes it difficult to see if any changes were done in those methods. At least 200 of the diff lines are just moving within classes.

The refactoring may make for a somewhat large PR, but try and minimize what else is going on to keep it as slim as possible.

private final NATMethod natMethod = DEFAULT_NAT_METHOD;

@Option(
names = {"--nat-external-ip-usage-enabled"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be implicit by --nat-method=MANUAL.

UPNP,
DOCKER,
KUBERNETES,
NONE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need a MANUAL value where the client just has the values plugged via configuration.

* <li><b>KUBERNETES:</b> Besu node is running inside a Kubernetes pod.
* </ul>
*/
public enum NATMethod {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally we treat initialism as words, so UpperCamelCase would be -> NatMethod

https://google.github.io/styleguide/javaguide.html#s5.3-camel-case

@matkt
Copy link
Contributor Author

matkt commented Nov 19, 2019

It's hard for me to provide quality feedback because this PR is too large, 1,600 changed lines. I can't wrap my head around it in anything less than an hour. The few comments I left were before I realized that was why I was having a hard time thinking deeply about it. This needs to be split up into several smaller PRs. Here's some ideas on how

  • A PR that just refactors the existing UPNP/None options into the NatManager
  • A PR that renames and moves files with no other changes to the desired places and names.
  • A PR to add network reporting files (besu.network)
  • A PR to add reporting in the Admin Info
  • A PR that adds manual NAT settings into the newly refactored NatManager
  • A PR that adds docker support into the newly refactored NatManager
  • A PR that adds K8s support into the newly refactoed NatManager.

It looks like docker, k8s, and manual are not in this PR, but there are some config options set up for them. Don't add these until the code adding them is brought in, it makes the PR look like it's doing more than it intends.

Also, minimize moving methods around if possible, it increases the diff count and makes it difficult to see if any changes were done in those methods. At least 200 of the diff lines are just moving within classes.

The refactoring may make for a somewhat large PR, but try and minimize what else is going on to keep it as slim as possible.

OK thanks for your answer. Indeed there is a lot of change in this PR. I start splitting my PR and I get back to you quickly with a smaller PR

@matkt
Copy link
Contributor Author

matkt commented Nov 20, 2019

It's hard for me to provide quality feedback because this PR is too large, 1,600 changed lines. I can't wrap my head around it in anything less than an hour. The few comments I left were before I realized that was why I was having a hard time thinking deeply about it. This needs to be split up into several smaller PRs. Here's some ideas on how

  • A PR that just refactors the existing UPNP/None options into the NatManager
  • A PR that renames and moves files with no other changes to the desired places and names.
  • A PR to add network reporting files (besu.network)
  • A PR to add reporting in the Admin Info
  • A PR that adds manual NAT settings into the newly refactored NatManager
  • A PR that adds docker support into the newly refactored NatManager
  • A PR that adds K8s support into the newly refactoed NatManager.

It looks like docker, k8s, and manual are not in this PR, but there are some config options set up for them. Don't add these until the code adding them is brought in, it makes the PR look like it's doing more than it intends.

Also, minimize moving methods around if possible, it increases the diff count and makes it difficult to see if any changes were done in those methods. At least 200 of the diff lines are just moving within classes.

The refactoring may make for a somewhat large PR, but try and minimize what else is going on to keep it as slim as possible.

Hi @shemnon

I just published a smaller PR in my private repo in order to simplify the review. I have also detailed as much as possible my modifications in the description. Hoping that it facilitates the review. it will make a merge to a branch that I would push to the master of the official repository at the end of the bounty

Link to the PR : matkt#3

@matkt matkt closed this Jan 7, 2020
AbdelStark added a commit that referenced this pull request Jan 9, 2020
* refactor nat manager

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* restart tests

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* restart tests

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Add Tuweni to Plugin-APIs (#295)

Generally, byte[] -> Bytes of some form.  Most of the changes are the
side effect of the type changes or chaning to the names of Tuweni
equivilant calls (getHexString->toHexString, etc).

UnformattedData -> Bytes
Log Topics went from Hash to Bytes32
Difficulty went to UInt256 to match core impl.
Quantity lost BinaryData and is just getValue() and toHexString()

Signed-off-by: Danno Ferrin <danno.ferrin@gmail.com>
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* DSL precondition to avoid creating orphan processes (#291)

Signed-off-by: Christopher Hare <chris.hare@consensys.net>

Co-authored-by: Danno Ferrin <danno.ferrin@shemnon.com>
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Fix AT failure because of additional field sent by Orion (#299)

Signed-off-by: Stefan Pingel <stefan.pingel@consensys.net>
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Update NatService.java

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Update NatServiceType.java

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Update NatServiceType.java

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Update NatServiceType.java

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Update NatServiceType.java

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* remove method

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* SPDX-License-Identifier: Apache-2.0

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* SPDX-License-Identifier: Apache-2.0

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Comment waitForFile: "besu.networks"

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* spotless apply

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* test

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* create file if not exist

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* remove useless code

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* fix waitForFile method

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>

Co-authored-by: Danno Ferrin <danno.ferrin@shemnon.com>
Co-authored-by: CJ Hare <CjHare@users.noreply.github.com>
Co-authored-by: pinges <16143240+pinges@users.noreply.github.com>
Co-authored-by: Abdelhamid Bakhta <45264458+abdelhamidbakhta@users.noreply.github.com>
@matkt matkt deleted the feature/bounty-nat-internal-api branch January 21, 2020 19:12
GregTheGreek pushed a commit to ChainSafe/besu that referenced this pull request Feb 4, 2020
…ger#190  (hyperledger#298)

* refactor nat manager

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* restart tests

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* restart tests

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Add Tuweni to Plugin-APIs (hyperledger#295)

Generally, byte[] -> Bytes of some form.  Most of the changes are the
side effect of the type changes or chaning to the names of Tuweni
equivilant calls (getHexString->toHexString, etc).

UnformattedData -> Bytes
Log Topics went from Hash to Bytes32
Difficulty went to UInt256 to match core impl.
Quantity lost BinaryData and is just getValue() and toHexString()

Signed-off-by: Danno Ferrin <danno.ferrin@gmail.com>
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* DSL precondition to avoid creating orphan processes (hyperledger#291)

Signed-off-by: Christopher Hare <chris.hare@consensys.net>

Co-authored-by: Danno Ferrin <danno.ferrin@shemnon.com>
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Fix AT failure because of additional field sent by Orion (hyperledger#299)

Signed-off-by: Stefan Pingel <stefan.pingel@consensys.net>
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Update NatService.java

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Update NatServiceType.java

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Update NatServiceType.java

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Update NatServiceType.java

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Update NatServiceType.java

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* remove method

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* SPDX-License-Identifier: Apache-2.0

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* SPDX-License-Identifier: Apache-2.0

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Comment waitForFile: "besu.networks"

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* spotless apply

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* test

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* create file if not exist

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* remove useless code

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* fix waitForFile method

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>

Co-authored-by: Danno Ferrin <danno.ferrin@shemnon.com>
Co-authored-by: CJ Hare <CjHare@users.noreply.github.com>
Co-authored-by: pinges <16143240+pinges@users.noreply.github.com>
Co-authored-by: Abdelhamid Bakhta <45264458+abdelhamidbakhta@users.noreply.github.com>
edwardmack pushed a commit to ChainSafe/besu that referenced this pull request Feb 4, 2020
…ger#190  (hyperledger#298)

* refactor nat manager

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* restart tests

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* restart tests

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Add Tuweni to Plugin-APIs (hyperledger#295)

Generally, byte[] -> Bytes of some form.  Most of the changes are the
side effect of the type changes or chaning to the names of Tuweni
equivilant calls (getHexString->toHexString, etc).

UnformattedData -> Bytes
Log Topics went from Hash to Bytes32
Difficulty went to UInt256 to match core impl.
Quantity lost BinaryData and is just getValue() and toHexString()

Signed-off-by: Danno Ferrin <danno.ferrin@gmail.com>
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* DSL precondition to avoid creating orphan processes (hyperledger#291)

Signed-off-by: Christopher Hare <chris.hare@consensys.net>

Co-authored-by: Danno Ferrin <danno.ferrin@shemnon.com>
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Fix AT failure because of additional field sent by Orion (hyperledger#299)

Signed-off-by: Stefan Pingel <stefan.pingel@consensys.net>
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Update NatService.java

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Update NatServiceType.java

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Update NatServiceType.java

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Update NatServiceType.java

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Update NatServiceType.java

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* remove method

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* SPDX-License-Identifier: Apache-2.0

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* SPDX-License-Identifier: Apache-2.0

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Comment waitForFile: "besu.networks"

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* spotless apply

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* test

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* create file if not exist

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* remove useless code

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* fix waitForFile method

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>

Co-authored-by: Danno Ferrin <danno.ferrin@shemnon.com>
Co-authored-by: CJ Hare <CjHare@users.noreply.github.com>
Co-authored-by: pinges <16143240+pinges@users.noreply.github.com>
Co-authored-by: Abdelhamid Bakhta <45264458+abdelhamidbakhta@users.noreply.github.com>
edwardmack pushed a commit to ChainSafe/besu that referenced this pull request Feb 4, 2020
…ger#190  (hyperledger#298)

* refactor nat manager

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* restart tests

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* restart tests

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Add Tuweni to Plugin-APIs (hyperledger#295)

Generally, byte[] -> Bytes of some form.  Most of the changes are the
side effect of the type changes or chaning to the names of Tuweni
equivilant calls (getHexString->toHexString, etc).

UnformattedData -> Bytes
Log Topics went from Hash to Bytes32
Difficulty went to UInt256 to match core impl.
Quantity lost BinaryData and is just getValue() and toHexString()

Signed-off-by: Danno Ferrin <danno.ferrin@gmail.com>
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* DSL precondition to avoid creating orphan processes (hyperledger#291)

Signed-off-by: Christopher Hare <chris.hare@consensys.net>

Co-authored-by: Danno Ferrin <danno.ferrin@shemnon.com>
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Fix AT failure because of additional field sent by Orion (hyperledger#299)

Signed-off-by: Stefan Pingel <stefan.pingel@consensys.net>
Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Update NatService.java

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Update NatServiceType.java

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Update NatServiceType.java

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Update NatServiceType.java

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Update NatServiceType.java

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* remove method

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* SPDX-License-Identifier: Apache-2.0

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* SPDX-License-Identifier: Apache-2.0

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* Comment waitForFile: "besu.networks"

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* spotless apply

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* test

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* create file if not exist

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* remove useless code

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>

* fix waitForFile method

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>

Co-authored-by: Danno Ferrin <danno.ferrin@shemnon.com>
Co-authored-by: CJ Hare <CjHare@users.noreply.github.com>
Co-authored-by: pinges <16143240+pinges@users.noreply.github.com>
Co-authored-by: Abdelhamid Bakhta <45264458+abdelhamidbakhta@users.noreply.github.com>
Signed-off-by: edwardmack <ed@edwardmack.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants