mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 20:27:35 +03:00
add support for receiving BLOCKED frames
This commit is contained in:
parent
0d6642464d
commit
bd67f537c9
5 changed files with 74 additions and 6 deletions
42
frames/blocked_frame.go
Normal file
42
frames/blocked_frame.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
package frames
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
"github.com/lucas-clemente/quic-go/utils"
|
||||
)
|
||||
|
||||
// A BlockedFrame in QUIC
|
||||
type BlockedFrame struct {
|
||||
StreamID protocol.StreamID
|
||||
}
|
||||
|
||||
//Write writes a RST_STREAM frame
|
||||
func (f *BlockedFrame) Write(b *bytes.Buffer, packetNumber protocol.PacketNumber, packetNumberLen uint8) error {
|
||||
panic("BlockedFrame: Write not yet implemented")
|
||||
}
|
||||
|
||||
// MinLength of a written frame
|
||||
func (f *BlockedFrame) MinLength() int {
|
||||
panic("BlockedFrame: Write not yet implemented")
|
||||
}
|
||||
|
||||
// ParseBlockedFrame parses a BLOCKED frame
|
||||
func ParseBlockedFrame(r *bytes.Reader) (*BlockedFrame, error) {
|
||||
frame := &BlockedFrame{}
|
||||
|
||||
// read the TypeByte
|
||||
_, err := r.ReadByte()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sid, err := utils.ReadUint32(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
frame.StreamID = protocol.StreamID(sid)
|
||||
|
||||
return frame, nil
|
||||
}
|
20
frames/blocked_frame_test.go
Normal file
20
frames/blocked_frame_test.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
package frames
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("BlockedFrame", func() {
|
||||
Context("when parsing", func() {
|
||||
It("accepts sample frame", func() {
|
||||
b := bytes.NewReader([]byte{0x05, 0xEF, 0xBE, 0xAD, 0xDE})
|
||||
frame, err := ParseBlockedFrame(b)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame.StreamID).To(Equal(protocol.StreamID(0xDEADBEEF)))
|
||||
})
|
||||
})
|
||||
})
|
|
@ -63,10 +63,7 @@ ReadLoop:
|
|||
case 0x04:
|
||||
frame, err = frames.ParseWindowUpdateFrame(r)
|
||||
case 0x05:
|
||||
fmt.Println("unimplemented: BLOCKED")
|
||||
p := make([]byte, 1+4)
|
||||
_, err = r.Read(p)
|
||||
frame = nil
|
||||
frame, err = frames.ParseBlockedFrame(r)
|
||||
case 0x06:
|
||||
frame, err = frames.ParseStopWaitingFrame(r, publicHeader.PacketNumber, publicHeader.PacketNumberLen)
|
||||
case 0x07:
|
||||
|
|
|
@ -138,10 +138,14 @@ var _ = Describe("Packet unpacker", func() {
|
|||
})
|
||||
|
||||
It("accepts BLOCKED frames", func() {
|
||||
setReader([]byte{0x05, 0, 0, 0, 0})
|
||||
setReader([]byte{0x05, 0xEF, 0xBE, 0xAD, 0xDE})
|
||||
packet, err := unpacker.Unpack(hdrBin, hdr, r)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(packet.frames).To(HaveLen(0))
|
||||
Expect(packet.frames).To(Equal([]frames.Frame{
|
||||
&frames.BlockedFrame{
|
||||
StreamID: 0xDEADBEEF,
|
||||
},
|
||||
}))
|
||||
})
|
||||
|
||||
It("unpacks STOP_WAITING frames", func() {
|
||||
|
|
|
@ -30,6 +30,8 @@ type StreamCallback func(*Session, utils.Stream)
|
|||
|
||||
// A Session is a QUIC session
|
||||
type Session struct {
|
||||
connectionID protocol.ConnectionID
|
||||
|
||||
streamCallback StreamCallback
|
||||
|
||||
conn connection
|
||||
|
@ -54,6 +56,7 @@ type Session struct {
|
|||
// NewSession makes a new session
|
||||
func NewSession(conn connection, v protocol.VersionNumber, connectionID protocol.ConnectionID, sCfg *handshake.ServerConfig, streamCallback StreamCallback) PacketHandler {
|
||||
session := &Session{
|
||||
connectionID: connectionID,
|
||||
conn: conn,
|
||||
streamCallback: streamCallback,
|
||||
streams: make(map[protocol.StreamID]*stream),
|
||||
|
@ -146,6 +149,8 @@ func (s *Session) handlePacket(remoteAddr interface{}, publicHeader *PublicHeade
|
|||
err = s.handleRstStreamFrame(frame)
|
||||
case *frames.WindowUpdateFrame:
|
||||
fmt.Printf("%#v\n", frame)
|
||||
case *frames.BlockedFrame:
|
||||
fmt.Printf("BLOCKED frame received for connection %d stream %d\n", s.connectionID, frame.StreamID)
|
||||
default:
|
||||
panic("unexpected frame type")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue