-
Notifications
You must be signed in to change notification settings - Fork 20.3k
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 #30882
base: master
Are you sure you want to change the base?
p2p/nat: add stun protocol #30882
Conversation
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.
Please do a go mod tidy
also
p2p/nat/nat_stun.go
Outdated
} | ||
|
||
func NewSTUN(serverAddr string) STUN { | ||
if serverAddr == "" { |
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 serverAddr == "" { | |
if serverAddr == "default" { |
Imo better if using the default is an explicit opt-in from the user
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.
Should also verify that serverAddr
can be converted into a valid udp4
addr, and error otherwise.
And why not let serverAddr
be and *UDPAddr
instead?
addr, err := net.ResolveUDPAddr("udp4", serverAddr)
if err != nil{
return nil, err
}
return STUN{ serverAddr: addr}, 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.
yeah, that a good idea, I will use *UDPAddr
instead and return err if addr are not valid
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.
@holiman
for this oneImo better if using the default is an explicit opt-in from the user
you mean use should use like this --nat stun: default
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.
yeah, something like that. --nat=stun:default
without space, probably
1. upgrade to github.com/pion/stun/v2 2. check the server addr
// "stun:default" uses stun protocol with default stun server | ||
// "stun:192.168.0.1:1234" uses stun protocol with stun server address 192.168.0.1:1234 |
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.
Another way to do it would be to mimic pmp
// "stun" uses stun protocol with default stun server
// "stun:192.168.0.1:1234" uses stun protocol with stun server address 192.168.0.1:1234
Don't really know if it's a good idea to have a default. For now, some devops team maintain a stun on a server, but is that a promise for the future? What happens when DO recycles it and someone else is given the ip address?
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 don't like it either. We try to avoid hard-coding network endpoints in the client, and when we do, it should be a list of multiple ones. There are lists of public STUN server endpoints floating around that we could use.
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.
how about server list here
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.
yeah we can integrate that
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.
@fjl I make the stun addr to stun server list. When request to stun server, it's up to three requests. f the response is error, it will request to the next server until a success response or all stun server are requested. The code are inspired in p2p/discover/lookup.go
fixed #30881
This PR introduces STUN (Session Traversal Utilities for NAT) support to the
nat
package. The STUN protocol is useful for determining the public IP address of a NAT gateway and enables applications to work effectively in NAT environments.usage