diff options
author | greatroar <61184462+greatroar@users.noreply.github.com> | 2021-07-10 13:53:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-10 13:53:51 +0200 |
commit | 1e210421383c96a2b9e4cbef3c2973adaa4f5f68 (patch) | |
tree | 4e5eac979fb63272e5079bd3f9b72a9ec15d92eb | |
parent | a56f70ab94ab3edd32cd5ffd4c967574212f8363 (diff) |
lib/connections: switch statement to get the QUIC network (#7816)v1.18.1-rc.1
-rw-r--r-- | lib/connections/quic_dial.go | 3 | ||||
-rw-r--r-- | lib/connections/quic_listen.go | 5 | ||||
-rw-r--r-- | lib/connections/quic_misc.go | 12 |
3 files changed, 15 insertions, 5 deletions
diff --git a/lib/connections/quic_dial.go b/lib/connections/quic_dial.go index a952d1ecdd..46e397b7a9 100644 --- a/lib/connections/quic_dial.go +++ b/lib/connections/quic_dial.go @@ -13,7 +13,6 @@ import ( "crypto/tls" "net" "net/url" - "strings" "time" "github.com/lucas-clemente/quic-go" @@ -46,7 +45,7 @@ type quicDialer struct { func (d *quicDialer) Dial(ctx context.Context, _ protocol.DeviceID, uri *url.URL) (internalConn, error) { uri = fixupPort(uri, config.DefaultQUICPort) - network := strings.ReplaceAll(uri.Scheme, "quic", "udp") + network := quicNetwork(uri) addr, err := net.ResolveUDPAddr(network, uri.Host) if err != nil { diff --git a/lib/connections/quic_listen.go b/lib/connections/quic_listen.go index 00a34544ab..b325efc376 100644 --- a/lib/connections/quic_listen.go +++ b/lib/connections/quic_listen.go @@ -13,7 +13,6 @@ import ( "crypto/tls" "net" "net/url" - "strings" "sync" "sync/atomic" "syscall" @@ -81,7 +80,7 @@ func (t *quicListener) OnExternalAddressChanged(address *stun.Host, via string) } func (t *quicListener) serve(ctx context.Context) error { - network := strings.ReplaceAll(t.uri.Scheme, "quic", "udp") + network := quicNetwork(t.uri) udpAddr, err := net.ResolveUDPAddr(network, t.uri.Host) if err != nil { @@ -204,7 +203,7 @@ func (t *quicListener) LANAddresses() []*url.URL { uri := maybeReplacePort(t.uri, t.laddr) t.mut.Unlock() addrs := []*url.URL{uri} - network := strings.ReplaceAll(uri.Scheme, "quic", "udp") + network := quicNetwork(uri) addrs = append(addrs, getURLsForAllAdaptersIfUnspecified(network, uri)...) return addrs } diff --git a/lib/connections/quic_misc.go b/lib/connections/quic_misc.go index c5e1378db2..f7e7ae57b1 100644 --- a/lib/connections/quic_misc.go +++ b/lib/connections/quic_misc.go @@ -11,6 +11,7 @@ package connections import ( "crypto/tls" "net" + "net/url" "github.com/lucas-clemente/quic-go" "github.com/syncthing/syncthing/lib/util" @@ -23,6 +24,17 @@ var ( } ) +func quicNetwork(uri *url.URL) string { + switch uri.Scheme { + case "quic4": + return "udp4" + case "quic6": + return "udp6" + default: + return "udp" + } +} + type quicTlsConn struct { quic.Session quic.Stream |