mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-10 07:11:08 +00:00
lib/connections: switch statement to get the QUIC network (#7816)
This commit is contained in:
parent
a56f70ab94
commit
1e21042138
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user