mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 20:27:35 +03:00
add a function to tell if a packet is a 0-RTT packet
This commit is contained in:
parent
b2c2e4940f
commit
7676e455c5
3 changed files with 38 additions and 0 deletions
|
@ -2,6 +2,7 @@ package wire
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
@ -43,6 +44,21 @@ func IsVersionNegotiationPacket(b []byte) bool {
|
|||
return b[0]&0x80 > 0 && b[1] == 0 && b[2] == 0 && b[3] == 0 && b[4] == 0
|
||||
}
|
||||
|
||||
// Is0RTTPacket says if this is a 0-RTT packet.
|
||||
// A packet sent with a version we don't understand can never be a 0-RTT packet.
|
||||
func Is0RTTPacket(b []byte) bool {
|
||||
if len(b) < 5 {
|
||||
return false
|
||||
}
|
||||
if b[0]&0x80 == 0 {
|
||||
return false
|
||||
}
|
||||
if !protocol.IsSupportedVersion(protocol.SupportedVersions, protocol.VersionNumber(binary.BigEndian.Uint32(b[1:5]))) {
|
||||
return false
|
||||
}
|
||||
return b[0]&0x30>>4 == 0x1
|
||||
}
|
||||
|
||||
var ErrUnsupportedVersion = errors.New("unsupported version")
|
||||
|
||||
// The Header is the version independent part of the header
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue