diff options
author | greatroar <61184462+greatroar@users.noreply.github.com> | 2021-10-06 10:52:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-06 10:52:51 +0200 |
commit | 7c292cc812320c01675697f50f0f419f7fc93bb7 (patch) | |
tree | b8dc1ed94555b095cc1dd55c9019211efeff37dc /lib/connections/quic_misc.go | |
parent | c94b797f000333256058b08aeb573d45055a9b99 (diff) |
lib/connections: Fix and optimize registry (#7996)
Registry.Get used a full sort to get the minimum of a list, and the sort
was broken because util.AddressUnspecifiedLess assumed it could find out
whether an address is IPv4 or IPv6 from its Network method. However,
net.(TCP|UDP)Addr.Network always returns "tcp"/"udp".
Diffstat (limited to 'lib/connections/quic_misc.go')
-rw-r--r-- | lib/connections/quic_misc.go | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/connections/quic_misc.go b/lib/connections/quic_misc.go index 5014dd259f..fb8e7044f5 100644 --- a/lib/connections/quic_misc.go +++ b/lib/connections/quic_misc.go @@ -15,7 +15,6 @@ import ( "net/url" "github.com/lucas-clemente/quic-go" - "github.com/syncthing/syncthing/lib/util" ) var ( @@ -63,7 +62,10 @@ func (q *quicTlsConn) ConnectionState() tls.ConnectionState { return q.Session.ConnectionState().TLS.ConnectionState } -// Sort available packet connections by ip address, preferring unspecified local address. -func packetConnLess(i interface{}, j interface{}) bool { - return util.AddressUnspecifiedLess(i.(net.PacketConn).LocalAddr(), j.(net.PacketConn).LocalAddr()) +func packetConnUnspecified(conn interface{}) bool { + // Since QUIC connections are wrapped, we can't do a simple typecheck + // on *net.UDPAddr here. + addr := conn.(net.PacketConn).LocalAddr() + host, _, err := net.SplitHostPort(addr.String()) + return err == nil && net.ParseIP(host).IsUnspecified() } |