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

Set external IP and mapping port to es-node ENR when it behind a NAT and the advertise IP is not set #132

Closed
wants to merge 13 commits into from

Conversation

ping-ke
Copy link
Collaborator

@ping-ke ping-ke commented Dec 5, 2023

Issue: #131
If the es-node is running behind a NAT and without the advertiseIP being set. we can discover the NAT service and add port mappings to the NAT service, then add the external IP and mapping ports to ENR.

How to test:
Run the es-node behind NAT service without advertiseIP being set. Then copy the ENR the es-node output and check it in the https://enr-viewer.com/.
enr:-Li4QCVR_onX8sRp5LVSxHTMbxIkvJVcS3VXu9c3DcFBhnrjK4YmZHc55Mhktqi9Qj-ypbbUms_u56PyrXbBT2po7CCGAYwvPP-9imV0aHN0b3JhZ2XbAYDY15Sfn1_YmtZI8sAAyVTY2ch3QyQ-xcGAgmlkgnY0gmlwhEmqKEKJc2VjcDI1NmsxoQP9Mik329t5ntsy0m8DWu-JRgT6T1TNOCx_M62HV9GPCIN0Y3CCggGDdWRwgnZc

we can see its multiaddr like

tcp4 multiaddr  /ip4/73.170.40.66/tcp/33281/p2p/16Uiu2HAmVhMrt2PoKbxBjEoFPzc3auqn4HM82oqZrXwkpUAeGgEK
udp4 multiaddr  /ip4/73.170.40.66/udp/30300/p2p/16Uiu2HAmVhMrt2PoKbxBjEoFPzc3auqn4HM82oqZrXwkpUAeGgEK

run the second es-node with the first es-node ENR and see the log like the following

t=2023-12-04T23:54:39+0800 lvl=info msg="Connected to peer"                     peer=16Uiu2HAmVhMrt2PoKbxBjEoFPzc3auqn4HM82oqZrXwkpUAeGgEK addr=/ip4/73.170.40.66/tcp/32501
... ...
t=2023-12-04T23:55:06+0800 lvl=info msg="Disconnected from peer"                peer=16Uiu2HAmVhMrt2PoKbxBjEoFPzc3auqn4HM82oqZrXwkpUAeGgEK addr=/ip4/73.170.40.66/tcp/32501

@@ -149,6 +166,30 @@ func (v *Secp256k1) DecodeRLP(s *rlp.Stream) error {
return nil
}

func addNATMappings(tcpPort, udpPort int) (net.IP, int, int, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We may want to investigate whether libp2p can do this work if we enable NAT option in the libp2p constructor

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

NAT manager is not public, we cannot directly use it.

ethstorage/p2p/discovery.go Show resolved Hide resolved
@ping-ke ping-ke closed this Feb 1, 2024
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.

2 participants