mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 04:37:36 +03:00
combine packetUnpackerBase and packetUnpacker
The split was only needed for unpacking gQUIC packets.
This commit is contained in:
parent
a18b5c0335
commit
90c538bae4
1 changed files with 25 additions and 29 deletions
|
@ -20,43 +20,18 @@ type quicAEAD interface {
|
|||
Open1RTT(dst, src []byte, pn protocol.PacketNumber, ad []byte) ([]byte, error)
|
||||
}
|
||||
|
||||
type packetUnpackerBase struct {
|
||||
version protocol.VersionNumber
|
||||
}
|
||||
|
||||
func (u *packetUnpackerBase) parseFrames(decrypted []byte, hdr *wire.Header) ([]wire.Frame, error) {
|
||||
r := bytes.NewReader(decrypted)
|
||||
if r.Len() == 0 {
|
||||
return nil, qerr.MissingPayload
|
||||
}
|
||||
|
||||
fs := make([]wire.Frame, 0, 2)
|
||||
// Read all frames in the packet
|
||||
for {
|
||||
frame, err := wire.ParseNextFrame(r, hdr, u.version)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if frame == nil {
|
||||
break
|
||||
}
|
||||
fs = append(fs, frame)
|
||||
}
|
||||
return fs, nil
|
||||
}
|
||||
|
||||
// The packetUnpacker unpacks QUIC packets.
|
||||
type packetUnpacker struct {
|
||||
packetUnpackerBase
|
||||
aead quicAEAD
|
||||
aead quicAEAD
|
||||
version protocol.VersionNumber
|
||||
}
|
||||
|
||||
var _ unpacker = &packetUnpacker{}
|
||||
|
||||
func newPacketUnpacker(aead quicAEAD, version protocol.VersionNumber) unpacker {
|
||||
return &packetUnpacker{
|
||||
packetUnpackerBase: packetUnpackerBase{version: version},
|
||||
aead: aead,
|
||||
aead: aead,
|
||||
version: version,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,3 +72,24 @@ func (u *packetUnpacker) Unpack(headerBinary []byte, hdr *wire.Header, data []by
|
|||
frames: fs,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (u *packetUnpacker) parseFrames(decrypted []byte, hdr *wire.Header) ([]wire.Frame, error) {
|
||||
r := bytes.NewReader(decrypted)
|
||||
if r.Len() == 0 {
|
||||
return nil, qerr.MissingPayload
|
||||
}
|
||||
|
||||
fs := make([]wire.Frame, 0, 2)
|
||||
// Read all frames in the packet
|
||||
for {
|
||||
frame, err := wire.ParseNextFrame(r, hdr, u.version)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if frame == nil {
|
||||
break
|
||||
}
|
||||
fs = append(fs, frame)
|
||||
}
|
||||
return fs, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue