mirror of
https://github.com/octoleo/syncthing.git
synced 2025-02-08 23:08:27 +00:00
lib/connections: Stun resolves server adress beforehand (fixes #4453)
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4454
This commit is contained in:
parent
b2966957e0
commit
a9c221189b
@ -200,6 +200,7 @@ func (t *kcpListener) stunRenewal(listener net.PacketConn) {
|
|||||||
|
|
||||||
var natType stun.NATType
|
var natType stun.NATType
|
||||||
var extAddr *stun.Host
|
var extAddr *stun.Host
|
||||||
|
var udpAddr *net.UDPAddr
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
oldType := stun.NATUnknown
|
oldType := stun.NATUnknown
|
||||||
@ -218,7 +219,17 @@ func (t *kcpListener) stunRenewal(listener net.PacketConn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, addr := range t.cfg.StunServers() {
|
for _, addr := range t.cfg.StunServers() {
|
||||||
client.SetServerAddr(addr)
|
// Resolve the address, so that in case the server advertises two
|
||||||
|
// IPs, we always hit the same one, as otherwise, the mapping might
|
||||||
|
// expire as we hit the other address, and cause us to flip flop
|
||||||
|
// between servers/external addresses, as a result flooding discovery
|
||||||
|
// servers.
|
||||||
|
udpAddr, err = net.ResolveUDPAddr("udp", addr)
|
||||||
|
if err != nil {
|
||||||
|
l.Debugf("%s stun addr resolution on %s: %s", t.uri, addr, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
client.SetServerAddr(udpAddr.String())
|
||||||
|
|
||||||
natType, extAddr, err = client.Discover()
|
natType, extAddr, err = client.Discover()
|
||||||
if err != nil || extAddr == nil {
|
if err != nil || extAddr == nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user