mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 04:37:36 +03:00
parent
9e4f395a49
commit
5bddd84fae
2 changed files with 20 additions and 6 deletions
|
@ -33,9 +33,11 @@ func (u *packetUnpacker) Unpack(publicHeaderBinary []byte, hdr *PublicHeader, da
|
|||
fs := make([]frames.Frame, 0, 2)
|
||||
|
||||
// Read all frames in the packet
|
||||
ReadLoop:
|
||||
for r.Len() > 0 {
|
||||
typeByte, _ := r.ReadByte()
|
||||
if typeByte == 0x0 { // PADDING frame
|
||||
continue
|
||||
}
|
||||
r.UnreadByte()
|
||||
|
||||
var frame frames.Frame
|
||||
|
@ -53,8 +55,6 @@ ReadLoop:
|
|||
err = errors.New("unimplemented: CONGESTION_FEEDBACK")
|
||||
} else {
|
||||
switch typeByte {
|
||||
case 0x0: // PAD, end of frames
|
||||
break ReadLoop
|
||||
case 0x01:
|
||||
frame, err = frames.ParseRstStreamFrame(r)
|
||||
if err != nil {
|
||||
|
|
|
@ -48,7 +48,7 @@ var _ = Describe("Packet unpacker", func() {
|
|||
Expect(packet.frames).To(Equal([]frames.Frame{f}))
|
||||
})
|
||||
|
||||
It("unpacks stream frames", func() {
|
||||
It("unpacks STREAM frames", func() {
|
||||
f := &frames.StreamFrame{
|
||||
StreamID: 1,
|
||||
Data: []byte("foobar"),
|
||||
|
@ -84,13 +84,27 @@ var _ = Describe("Packet unpacker", func() {
|
|||
Expect(err).To(MatchError("unimplemented: CONGESTION_FEEDBACK"))
|
||||
})
|
||||
|
||||
It("handles pad frames", func() {
|
||||
setData([]byte{0, 0, 0})
|
||||
It("handles PADDING frames", func() {
|
||||
setData([]byte{0, 0, 0}) // 3 bytes PADDING
|
||||
packet, err := unpacker.Unpack(hdrBin, hdr, data)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(packet.frames).To(BeEmpty())
|
||||
})
|
||||
|
||||
It("handles PADDING between two other frames", func() {
|
||||
f := &frames.PingFrame{}
|
||||
err := f.Write(buf, protocol.VersionWhatever)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
_, err = buf.Write(bytes.Repeat([]byte{0}, 10)) // 10 bytes PADDING
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = f.Write(buf, protocol.VersionWhatever)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
setData(buf.Bytes())
|
||||
packet, err := unpacker.Unpack(hdrBin, hdr, data)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(packet.frames).To(HaveLen(2))
|
||||
})
|
||||
|
||||
It("unpacks RST_STREAM frames", func() {
|
||||
setData([]byte{0x01, 0xEF, 0xBE, 0xAD, 0xDE, 0x44, 0x33, 0x22, 0x11, 0xAD, 0xFB, 0xCA, 0xDE, 0x34, 0x12, 0x37, 0x13})
|
||||
packet, err := unpacker.Unpack(hdrBin, hdr, data)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue