forked from quic-go/quic-go
use the slices package to simply QUIC version comparisons (#5130)
No functional change expected.
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"io"
|
||||
"net"
|
||||
"reflect"
|
||||
"slices"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
@@ -1278,8 +1279,7 @@ func (s *connection) handleVersionNegotiationPacket(p receivedPacket) {
|
||||
return
|
||||
}
|
||||
|
||||
for _, v := range supportedVersions {
|
||||
if v == s.version {
|
||||
if slices.Contains(supportedVersions, s.version) {
|
||||
if s.tracer != nil && s.tracer.DroppedPacket != nil {
|
||||
s.tracer.DroppedPacket(logging.PacketTypeVersionNegotiation, protocol.InvalidPacketNumber, p.Size(), logging.PacketDropUnexpectedVersion)
|
||||
}
|
||||
@@ -1287,7 +1287,6 @@ func (s *connection) handleVersionNegotiationPacket(p receivedPacket) {
|
||||
// This might be a packet sent by an attacker, or it was corrupted.
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
s.logger.Infof("Received a Version Negotiation packet. Supported Versions: %s", supportedVersions)
|
||||
if s.tracer != nil && s.tracer.ReceivedVersionNegotiationPacket != nil {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"math"
|
||||
mrand "math/rand/v2"
|
||||
"slices"
|
||||
"sync"
|
||||
)
|
||||
|
||||
@@ -64,12 +65,7 @@ func (vn Version) toGQUICVersion() int {
|
||||
|
||||
// IsSupportedVersion returns true if the server supports this version
|
||||
func IsSupportedVersion(supported []Version, v Version) bool {
|
||||
for _, t := range supported {
|
||||
if t == v {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.Contains(supported, v)
|
||||
}
|
||||
|
||||
// ChooseSupportedVersion finds the best version in the overlap of ours and theirs
|
||||
@@ -78,12 +74,10 @@ func IsSupportedVersion(supported []Version, v Version) bool {
|
||||
// The bool returned indicates if a matching version was found.
|
||||
func ChooseSupportedVersion(ours, theirs []Version) (Version, bool) {
|
||||
for _, ourVer := range ours {
|
||||
for _, theirVer := range theirs {
|
||||
if ourVer == theirVer {
|
||||
if slices.Contains(theirs, ourVer) {
|
||||
return ourVer, true
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user