-
Notifications
You must be signed in to change notification settings - Fork 20.5k
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
p2p/nat: add stun protocol #31064
p2p/nat: add stun protocol #31064
Conversation
1. upgrade to github.com/pion/stun/v2 2. check the server addr
cmd/utils/flags.go
Outdated
@@ -760,7 +760,7 @@ var ( | |||
} | |||
NATFlag = &cli.StringFlag{ | |||
Name: "nat", | |||
Usage: "NAT port mapping mechanism (any|none|upnp|pmp|pmp:<IP>|extip:<IP>)", | |||
Usage: "NAT port mapping mechanism (any|none|upnp|pmp|pmp:<IP>|extip:<IP>|stun:default|stun:<IP:PORT>)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can omit the default, e.g. stun|stun:<IP:PORT>
p2p/nat/nat.go
Outdated
@@ -59,13 +59,16 @@ type Interface interface { | |||
// "upnp" uses the Universal Plug and Play protocol | |||
// "pmp" uses NAT-PMP with an auto-detected gateway address | |||
// "pmp:192.168.0.1" uses NAT-PMP with the given gateway address | |||
// "stun:default" uses stun protocol with default stun server |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use "stun"
to represent using stun protocol with default server
p2p/nat/nat_stun.go
Outdated
@@ -0,0 +1,94 @@ | |||
// Copyright 2024 The go-ethereum Authors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2025
p2p/nat/nat_stun.go
Outdated
return fmt.Sprintf("STUN(%s)", s.server) | ||
} | ||
|
||
func (stun) SupportsMapping() bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is not needed
p2p/nat/nat_stun.go
Outdated
responseError = event.Error | ||
return | ||
} | ||
if err := mappedAddr.GetFrom(event.Message); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if err := mappedAddr.GetFrom(event.Message); err != nil { | |
responseError = mappedAddr.GetFrom(event.Message) |
Also removes concurrency, since the requests will usually be quick.
I have pushed my changes:
|
@@ -0,0 +1,24 @@ | |||
package nat |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls add the license
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added the license
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one nitpick, otherwise lgtm
This implements a basic mechanism to query the node's external IP using a STUN server. There is a built-in list of public STUN servers for convenience. The new detection mechanism must be selected explicitly using `--nat=stun` and is not enabled by default in Geth. Fixes ethereum#30881 --------- Co-authored-by: Felix Lange <fjl@twurst.com>
@fjl here is the new pr to replace the old one, which Allow edits by maintainers. I rebase the branch from the master.
fixes #30881