mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-06 05:37:36 +03:00
wire: use constants for frame types (#3739)
This commit is contained in:
parent
48e18b922d
commit
7a393315bd
35 changed files with 118 additions and 100 deletions
|
@ -23,7 +23,7 @@ type AckFrame struct {
|
||||||
|
|
||||||
// parseAckFrame reads an ACK frame
|
// parseAckFrame reads an ACK frame
|
||||||
func parseAckFrame(r *bytes.Reader, typ uint64, ackDelayExponent uint8, _ protocol.VersionNumber) (*AckFrame, error) {
|
func parseAckFrame(r *bytes.Reader, typ uint64, ackDelayExponent uint8, _ protocol.VersionNumber) (*AckFrame, error) {
|
||||||
ecn := typ&0x1 > 0
|
ecn := typ == ackECNFrameType
|
||||||
|
|
||||||
frame := GetAckFrame()
|
frame := GetAckFrame()
|
||||||
|
|
||||||
|
@ -106,9 +106,9 @@ func parseAckFrame(r *bytes.Reader, typ uint64, ackDelayExponent uint8, _ protoc
|
||||||
func (f *AckFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
|
func (f *AckFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
|
||||||
hasECN := f.ECT0 > 0 || f.ECT1 > 0 || f.ECNCE > 0
|
hasECN := f.ECT0 > 0 || f.ECT1 > 0 || f.ECNCE > 0
|
||||||
if hasECN {
|
if hasECN {
|
||||||
b = append(b, 0b11)
|
b = append(b, ackECNFrameType)
|
||||||
} else {
|
} else {
|
||||||
b = append(b, 0b10)
|
b = append(b, ackFrameType)
|
||||||
}
|
}
|
||||||
b = quicvarint.Append(b, uint64(f.LargestAcked()))
|
b = quicvarint.Append(b, uint64(f.LargestAcked()))
|
||||||
b = quicvarint.Append(b, encodeAckDelay(f.DelayTime))
|
b = quicvarint.Append(b, encodeAckDelay(f.DelayTime))
|
||||||
|
|
|
@ -21,7 +21,7 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
|
||||||
data = append(data, encodeVarInt(0)...) // num blocks
|
data = append(data, encodeVarInt(0)...) // num blocks
|
||||||
data = append(data, encodeVarInt(10)...) // first ack block
|
data = append(data, encodeVarInt(10)...) // first ack block
|
||||||
b := bytes.NewReader(data)
|
b := bytes.NewReader(data)
|
||||||
frame, err := parseAckFrame(b, 0x2, protocol.AckDelayExponent, protocol.Version1)
|
frame, err := parseAckFrame(b, ackFrameType, protocol.AckDelayExponent, protocol.Version1)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(100)))
|
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(100)))
|
||||||
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(90)))
|
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(90)))
|
||||||
|
@ -35,7 +35,7 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
|
||||||
data = append(data, encodeVarInt(0)...) // num blocks
|
data = append(data, encodeVarInt(0)...) // num blocks
|
||||||
data = append(data, encodeVarInt(0)...) // first ack block
|
data = append(data, encodeVarInt(0)...) // first ack block
|
||||||
b := bytes.NewReader(data)
|
b := bytes.NewReader(data)
|
||||||
frame, err := parseAckFrame(b, 0x2, protocol.AckDelayExponent, protocol.Version1)
|
frame, err := parseAckFrame(b, ackFrameType, protocol.AckDelayExponent, protocol.Version1)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(55)))
|
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(55)))
|
||||||
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(55)))
|
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(55)))
|
||||||
|
@ -49,7 +49,7 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
|
||||||
data = append(data, encodeVarInt(0)...) // num blocks
|
data = append(data, encodeVarInt(0)...) // num blocks
|
||||||
data = append(data, encodeVarInt(20)...) // first ack block
|
data = append(data, encodeVarInt(20)...) // first ack block
|
||||||
b := bytes.NewReader(data)
|
b := bytes.NewReader(data)
|
||||||
frame, err := parseAckFrame(b, 0x2, protocol.AckDelayExponent, protocol.Version1)
|
frame, err := parseAckFrame(b, ackFrameType, protocol.AckDelayExponent, protocol.Version1)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(20)))
|
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(20)))
|
||||||
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(0)))
|
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(0)))
|
||||||
|
@ -62,7 +62,7 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
|
||||||
data = append(data, encodeVarInt(0)...) // delay
|
data = append(data, encodeVarInt(0)...) // delay
|
||||||
data = append(data, encodeVarInt(0)...) // num blocks
|
data = append(data, encodeVarInt(0)...) // num blocks
|
||||||
data = append(data, encodeVarInt(21)...) // first ack block
|
data = append(data, encodeVarInt(21)...) // first ack block
|
||||||
_, err := parseAckFrame(bytes.NewReader(data), 0x2, protocol.AckDelayExponent, protocol.Version1)
|
_, err := parseAckFrame(bytes.NewReader(data), ackFrameType, protocol.AckDelayExponent, protocol.Version1)
|
||||||
Expect(err).To(MatchError("invalid first ACK range"))
|
Expect(err).To(MatchError("invalid first ACK range"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
|
||||||
data = append(data, encodeVarInt(98)...) // gap
|
data = append(data, encodeVarInt(98)...) // gap
|
||||||
data = append(data, encodeVarInt(50)...) // ack block
|
data = append(data, encodeVarInt(50)...) // ack block
|
||||||
b := bytes.NewReader(data)
|
b := bytes.NewReader(data)
|
||||||
frame, err := parseAckFrame(b, 0x2, protocol.AckDelayExponent, protocol.Version1)
|
frame, err := parseAckFrame(b, ackFrameType, protocol.AckDelayExponent, protocol.Version1)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(1000)))
|
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(1000)))
|
||||||
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(750)))
|
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(750)))
|
||||||
|
@ -96,7 +96,7 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
|
||||||
data = append(data, encodeVarInt(1)...) // gap
|
data = append(data, encodeVarInt(1)...) // gap
|
||||||
data = append(data, encodeVarInt(1)...) // ack block
|
data = append(data, encodeVarInt(1)...) // ack block
|
||||||
b := bytes.NewReader(data)
|
b := bytes.NewReader(data)
|
||||||
frame, err := parseAckFrame(b, 0x2, protocol.AckDelayExponent, protocol.Version1)
|
frame, err := parseAckFrame(b, ackFrameType, protocol.AckDelayExponent, protocol.Version1)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(100)))
|
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(100)))
|
||||||
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(94)))
|
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(94)))
|
||||||
|
@ -133,7 +133,7 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
|
||||||
data = append(data, encodeVarInt(0)...) // num blocks
|
data = append(data, encodeVarInt(0)...) // num blocks
|
||||||
data = append(data, encodeVarInt(0)...) // first ack block
|
data = append(data, encodeVarInt(0)...) // first ack block
|
||||||
b := bytes.NewReader(data)
|
b := bytes.NewReader(data)
|
||||||
frame, err := parseAckFrame(b, 0x2, protocol.AckDelayExponent, protocol.Version1)
|
frame, err := parseAckFrame(b, ackFrameType, protocol.AckDelayExponent, protocol.Version1)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(frame.DelayTime).To(BeNumerically(">", 0))
|
Expect(frame.DelayTime).To(BeNumerically(">", 0))
|
||||||
// The maximum encodable duration is ~292 years.
|
// The maximum encodable duration is ~292 years.
|
||||||
|
@ -141,17 +141,16 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("errors on EOF", func() {
|
It("errors on EOF", func() {
|
||||||
const typ = 0x2
|
|
||||||
data := encodeVarInt(1000) // largest acked
|
data := encodeVarInt(1000) // largest acked
|
||||||
data = append(data, encodeVarInt(0)...) // delay
|
data = append(data, encodeVarInt(0)...) // delay
|
||||||
data = append(data, encodeVarInt(1)...) // num blocks
|
data = append(data, encodeVarInt(1)...) // num blocks
|
||||||
data = append(data, encodeVarInt(100)...) // first ack block
|
data = append(data, encodeVarInt(100)...) // first ack block
|
||||||
data = append(data, encodeVarInt(98)...) // gap
|
data = append(data, encodeVarInt(98)...) // gap
|
||||||
data = append(data, encodeVarInt(50)...) // ack block
|
data = append(data, encodeVarInt(50)...) // ack block
|
||||||
_, err := parseAckFrame(bytes.NewReader(data), typ, protocol.AckDelayExponent, protocol.Version1)
|
_, err := parseAckFrame(bytes.NewReader(data), ackFrameType, protocol.AckDelayExponent, protocol.Version1)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
for i := range data {
|
for i := range data {
|
||||||
_, err := parseAckFrame(bytes.NewReader(data[:i]), typ, protocol.AckDelayExponent, protocol.Version1)
|
_, err := parseAckFrame(bytes.NewReader(data[:i]), ackFrameType, protocol.AckDelayExponent, protocol.Version1)
|
||||||
Expect(err).To(MatchError(io.EOF))
|
Expect(err).To(MatchError(io.EOF))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -166,7 +165,7 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
|
||||||
data = append(data, encodeVarInt(0x12345)...) // ECT(1)
|
data = append(data, encodeVarInt(0x12345)...) // ECT(1)
|
||||||
data = append(data, encodeVarInt(0x12345678)...) // ECN-CE
|
data = append(data, encodeVarInt(0x12345678)...) // ECN-CE
|
||||||
b := bytes.NewReader(data)
|
b := bytes.NewReader(data)
|
||||||
frame, err := parseAckFrame(b, 0x3, protocol.AckDelayExponent, protocol.Version1)
|
frame, err := parseAckFrame(b, ackECNFrameType, protocol.AckDelayExponent, protocol.Version1)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(100)))
|
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(100)))
|
||||||
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(90)))
|
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(90)))
|
||||||
|
@ -175,7 +174,6 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("errors on EOF", func() {
|
It("errors on EOF", func() {
|
||||||
const typ = 0x3
|
|
||||||
data := encodeVarInt(1000) // largest acked
|
data := encodeVarInt(1000) // largest acked
|
||||||
data = append(data, encodeVarInt(0)...) // delay
|
data = append(data, encodeVarInt(0)...) // delay
|
||||||
data = append(data, encodeVarInt(1)...) // num blocks
|
data = append(data, encodeVarInt(1)...) // num blocks
|
||||||
|
@ -185,10 +183,10 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
|
||||||
data = append(data, encodeVarInt(0x42)...) // ECT(0)
|
data = append(data, encodeVarInt(0x42)...) // ECT(0)
|
||||||
data = append(data, encodeVarInt(0x12345)...) // ECT(1)
|
data = append(data, encodeVarInt(0x12345)...) // ECT(1)
|
||||||
data = append(data, encodeVarInt(0x12345678)...) // ECN-CE
|
data = append(data, encodeVarInt(0x12345678)...) // ECN-CE
|
||||||
_, err := parseAckFrame(bytes.NewReader(data), typ, protocol.AckDelayExponent, protocol.Version1)
|
_, err := parseAckFrame(bytes.NewReader(data), ackECNFrameType, protocol.AckDelayExponent, protocol.Version1)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
for i := range data {
|
for i := range data {
|
||||||
_, err = parseAckFrame(bytes.NewReader(data[:i]), typ, protocol.AckDelayExponent, protocol.Version1)
|
_, err = parseAckFrame(bytes.NewReader(data[:i]), ackECNFrameType, protocol.AckDelayExponent, protocol.Version1)
|
||||||
Expect(err).To(MatchError(io.EOF))
|
Expect(err).To(MatchError(io.EOF))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -202,7 +200,7 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
|
||||||
}
|
}
|
||||||
b, err := f.Append(nil, protocol.Version1)
|
b, err := f.Append(nil, protocol.Version1)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
expected := []byte{0x2}
|
expected := []byte{ackFrameType}
|
||||||
expected = append(expected, encodeVarInt(1337)...) // largest acked
|
expected = append(expected, encodeVarInt(1337)...) // largest acked
|
||||||
expected = append(expected, 0) // delay
|
expected = append(expected, 0) // delay
|
||||||
expected = append(expected, encodeVarInt(0)...) // num ranges
|
expected = append(expected, encodeVarInt(0)...) // num ranges
|
||||||
|
@ -220,7 +218,7 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
|
||||||
b, err := f.Append(nil, protocol.Version1)
|
b, err := f.Append(nil, protocol.Version1)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(b).To(HaveLen(int(f.Length(protocol.Version1))))
|
Expect(b).To(HaveLen(int(f.Length(protocol.Version1))))
|
||||||
expected := []byte{0x3}
|
expected := []byte{ackECNFrameType}
|
||||||
expected = append(expected, encodeVarInt(2000)...) // largest acked
|
expected = append(expected, encodeVarInt(2000)...) // largest acked
|
||||||
expected = append(expected, 0) // delay
|
expected = append(expected, 0) // delay
|
||||||
expected = append(expected, encodeVarInt(0)...) // num ranges
|
expected = append(expected, encodeVarInt(0)...) // num ranges
|
||||||
|
|
|
@ -17,7 +17,7 @@ type ConnectionCloseFrame struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseConnectionCloseFrame(r *bytes.Reader, typ uint64, _ protocol.VersionNumber) (*ConnectionCloseFrame, error) {
|
func parseConnectionCloseFrame(r *bytes.Reader, typ uint64, _ protocol.VersionNumber) (*ConnectionCloseFrame, error) {
|
||||||
f := &ConnectionCloseFrame{IsApplicationError: typ == 0x1d}
|
f := &ConnectionCloseFrame{IsApplicationError: typ == applicationCloseFrameType}
|
||||||
ec, err := quicvarint.Read(r)
|
ec, err := quicvarint.Read(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -63,9 +63,9 @@ func (f *ConnectionCloseFrame) Length(protocol.VersionNumber) protocol.ByteCount
|
||||||
|
|
||||||
func (f *ConnectionCloseFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
|
func (f *ConnectionCloseFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
|
||||||
if f.IsApplicationError {
|
if f.IsApplicationError {
|
||||||
b = append(b, 0x1d)
|
b = append(b, applicationCloseFrameType)
|
||||||
} else {
|
} else {
|
||||||
b = append(b, 0x1c)
|
b = append(b, connectionCloseFrameType)
|
||||||
}
|
}
|
||||||
|
|
||||||
b = quicvarint.Append(b, f.ErrorCode)
|
b = quicvarint.Append(b, f.ErrorCode)
|
||||||
|
|
|
@ -19,7 +19,7 @@ var _ = Describe("CONNECTION_CLOSE Frame", func() {
|
||||||
data = append(data, encodeVarInt(uint64(len(reason)))...) // reason phrase length
|
data = append(data, encodeVarInt(uint64(len(reason)))...) // reason phrase length
|
||||||
data = append(data, []byte(reason)...)
|
data = append(data, []byte(reason)...)
|
||||||
b := bytes.NewReader(data)
|
b := bytes.NewReader(data)
|
||||||
frame, err := parseConnectionCloseFrame(b, 0x1c, protocol.Version1)
|
frame, err := parseConnectionCloseFrame(b, connectionCloseFrameType, protocol.Version1)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(frame.IsApplicationError).To(BeFalse())
|
Expect(frame.IsApplicationError).To(BeFalse())
|
||||||
Expect(frame.ErrorCode).To(BeEquivalentTo(0x19))
|
Expect(frame.ErrorCode).To(BeEquivalentTo(0x19))
|
||||||
|
@ -34,7 +34,7 @@ var _ = Describe("CONNECTION_CLOSE Frame", func() {
|
||||||
data = append(data, encodeVarInt(uint64(len(reason)))...) // reason phrase length
|
data = append(data, encodeVarInt(uint64(len(reason)))...) // reason phrase length
|
||||||
data = append(data, reason...)
|
data = append(data, reason...)
|
||||||
b := bytes.NewReader(data)
|
b := bytes.NewReader(data)
|
||||||
frame, err := parseConnectionCloseFrame(b, 0x1d, protocol.Version1)
|
frame, err := parseConnectionCloseFrame(b, applicationCloseFrameType, protocol.Version1)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(frame.IsApplicationError).To(BeTrue())
|
Expect(frame.IsApplicationError).To(BeTrue())
|
||||||
Expect(frame.ErrorCode).To(BeEquivalentTo(0xcafe))
|
Expect(frame.ErrorCode).To(BeEquivalentTo(0xcafe))
|
||||||
|
@ -46,23 +46,22 @@ var _ = Describe("CONNECTION_CLOSE Frame", func() {
|
||||||
data := encodeVarInt(0xcafe)
|
data := encodeVarInt(0xcafe)
|
||||||
data = append(data, encodeVarInt(0x42)...) // frame type
|
data = append(data, encodeVarInt(0x42)...) // frame type
|
||||||
data = append(data, encodeVarInt(0xffff)...) // reason phrase length
|
data = append(data, encodeVarInt(0xffff)...) // reason phrase length
|
||||||
_, err := parseConnectionCloseFrame(bytes.NewReader(data), 0x1c, protocol.Version1)
|
_, err := parseConnectionCloseFrame(bytes.NewReader(data), connectionCloseFrameType, protocol.Version1)
|
||||||
Expect(err).To(MatchError(io.EOF))
|
Expect(err).To(MatchError(io.EOF))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("errors on EOFs", func() {
|
It("errors on EOFs", func() {
|
||||||
const typ = 0x1c
|
|
||||||
reason := "No recent network activity."
|
reason := "No recent network activity."
|
||||||
data := encodeVarInt(0x19)
|
data := encodeVarInt(0x19)
|
||||||
data = append(data, encodeVarInt(0x1337)...) // frame type
|
data = append(data, encodeVarInt(0x1337)...) // frame type
|
||||||
data = append(data, encodeVarInt(uint64(len(reason)))...) // reason phrase length
|
data = append(data, encodeVarInt(uint64(len(reason)))...) // reason phrase length
|
||||||
data = append(data, []byte(reason)...)
|
data = append(data, []byte(reason)...)
|
||||||
b := bytes.NewReader(data)
|
b := bytes.NewReader(data)
|
||||||
_, err := parseConnectionCloseFrame(b, typ, protocol.Version1)
|
_, err := parseConnectionCloseFrame(b, connectionCloseFrameType, protocol.Version1)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
for i := range data {
|
for i := range data {
|
||||||
b := bytes.NewReader(data[:i])
|
b := bytes.NewReader(data[:i])
|
||||||
_, err = parseConnectionCloseFrame(b, typ, protocol.Version1)
|
_, err = parseConnectionCloseFrame(b, connectionCloseFrameType, protocol.Version1)
|
||||||
Expect(err).To(MatchError(io.EOF))
|
Expect(err).To(MatchError(io.EOF))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -72,7 +71,7 @@ var _ = Describe("CONNECTION_CLOSE Frame", func() {
|
||||||
data = append(data, encodeVarInt(0x42)...) // frame type
|
data = append(data, encodeVarInt(0x42)...) // frame type
|
||||||
data = append(data, encodeVarInt(0)...)
|
data = append(data, encodeVarInt(0)...)
|
||||||
b := bytes.NewReader(data)
|
b := bytes.NewReader(data)
|
||||||
frame, err := parseConnectionCloseFrame(b, 0x1c, protocol.Version1)
|
frame, err := parseConnectionCloseFrame(b, connectionCloseFrameType, protocol.Version1)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(frame.ReasonPhrase).To(BeEmpty())
|
Expect(frame.ReasonPhrase).To(BeEmpty())
|
||||||
Expect(b.Len()).To(BeZero())
|
Expect(b.Len()).To(BeZero())
|
||||||
|
@ -87,7 +86,7 @@ var _ = Describe("CONNECTION_CLOSE Frame", func() {
|
||||||
}
|
}
|
||||||
b, err := frame.Append(nil, protocol.Version1)
|
b, err := frame.Append(nil, protocol.Version1)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
expected := []byte{0x1c}
|
expected := []byte{connectionCloseFrameType}
|
||||||
expected = append(expected, encodeVarInt(0xbeef)...)
|
expected = append(expected, encodeVarInt(0xbeef)...)
|
||||||
expected = append(expected, encodeVarInt(0x12345)...) // frame type
|
expected = append(expected, encodeVarInt(0x12345)...) // frame type
|
||||||
expected = append(expected, encodeVarInt(0)...) // reason phrase length
|
expected = append(expected, encodeVarInt(0)...) // reason phrase length
|
||||||
|
@ -101,7 +100,7 @@ var _ = Describe("CONNECTION_CLOSE Frame", func() {
|
||||||
}
|
}
|
||||||
b, err := frame.Append(nil, protocol.Version1)
|
b, err := frame.Append(nil, protocol.Version1)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
expected := []byte{0x1c}
|
expected := []byte{connectionCloseFrameType}
|
||||||
expected = append(expected, encodeVarInt(0xdead)...)
|
expected = append(expected, encodeVarInt(0xdead)...)
|
||||||
expected = append(expected, encodeVarInt(0)...) // frame type
|
expected = append(expected, encodeVarInt(0)...) // frame type
|
||||||
expected = append(expected, encodeVarInt(6)...) // reason phrase length
|
expected = append(expected, encodeVarInt(6)...) // reason phrase length
|
||||||
|
@ -117,7 +116,7 @@ var _ = Describe("CONNECTION_CLOSE Frame", func() {
|
||||||
}
|
}
|
||||||
b, err := frame.Append(nil, protocol.Version1)
|
b, err := frame.Append(nil, protocol.Version1)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
expected := []byte{0x1d}
|
expected := []byte{applicationCloseFrameType}
|
||||||
expected = append(expected, encodeVarInt(0xdead)...)
|
expected = append(expected, encodeVarInt(0xdead)...)
|
||||||
expected = append(expected, encodeVarInt(6)...) // reason phrase length
|
expected = append(expected, encodeVarInt(6)...) // reason phrase length
|
||||||
expected = append(expected, []byte("foobar")...)
|
expected = append(expected, []byte("foobar")...)
|
||||||
|
|
|
@ -39,7 +39,7 @@ func parseCryptoFrame(r *bytes.Reader, _ protocol.VersionNumber) (*CryptoFrame,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *CryptoFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
|
func (f *CryptoFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
|
||||||
b = append(b, 0x6)
|
b = append(b, cryptoFrameType)
|
||||||
b = quicvarint.Append(b, uint64(f.Offset))
|
b = quicvarint.Append(b, uint64(f.Offset))
|
||||||
b = quicvarint.Append(b, uint64(len(f.Data)))
|
b = quicvarint.Append(b, uint64(len(f.Data)))
|
||||||
b = append(b, f.Data...)
|
b = append(b, f.Data...)
|
||||||
|
|
|
@ -47,7 +47,7 @@ var _ = Describe("CRYPTO frame", func() {
|
||||||
}
|
}
|
||||||
b, err := f.Append(nil, protocol.Version1)
|
b, err := f.Append(nil, protocol.Version1)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
expected := []byte{0x6}
|
expected := []byte{cryptoFrameType}
|
||||||
expected = append(expected, encodeVarInt(0x123456)...) // offset
|
expected = append(expected, encodeVarInt(0x123456)...) // offset
|
||||||
expected = append(expected, encodeVarInt(6)...) // length
|
expected = append(expected, encodeVarInt(6)...) // length
|
||||||
expected = append(expected, []byte("foobar")...)
|
expected = append(expected, []byte("foobar")...)
|
||||||
|
|
|
@ -17,15 +17,12 @@ func parseDataBlockedFrame(r *bytes.Reader, _ protocol.VersionNumber) (*DataBloc
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &DataBlockedFrame{
|
return &DataBlockedFrame{MaximumData: protocol.ByteCount(offset)}, nil
|
||||||
MaximumData: protocol.ByteCount(offset),
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *DataBlockedFrame) Append(b []byte, version protocol.VersionNumber) ([]byte, error) {
|
func (f *DataBlockedFrame) Append(b []byte, version protocol.VersionNumber) ([]byte, error) {
|
||||||
b = append(b, 0x14)
|
b = append(b, dataBlockedFrameType)
|
||||||
b = quicvarint.Append(b, uint64(f.MaximumData))
|
return quicvarint.Append(b, uint64(f.MaximumData)), nil
|
||||||
return b, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Length of a written frame
|
// Length of a written frame
|
||||||
|
|
|
@ -38,7 +38,7 @@ var _ = Describe("DATA_BLOCKED frame", func() {
|
||||||
frame := DataBlockedFrame{MaximumData: 0xdeadbeef}
|
frame := DataBlockedFrame{MaximumData: 0xdeadbeef}
|
||||||
b, err := frame.Append(nil, protocol.VersionWhatever)
|
b, err := frame.Append(nil, protocol.VersionWhatever)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
expected := []byte{0x14}
|
expected := []byte{dataBlockedFrameType}
|
||||||
expected = append(expected, encodeVarInt(0xdeadbeef)...)
|
expected = append(expected, encodeVarInt(0xdeadbeef)...)
|
||||||
Expect(b).To(Equal(expected))
|
Expect(b).To(Equal(expected))
|
||||||
})
|
})
|
||||||
|
|
|
@ -11,6 +11,31 @@ import (
|
||||||
"github.com/quic-go/quic-go/quicvarint"
|
"github.com/quic-go/quic-go/quicvarint"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
pingFrameType = 0x1
|
||||||
|
ackFrameType = 0x2
|
||||||
|
ackECNFrameType = 0x3
|
||||||
|
resetStreamFrameType = 0x4
|
||||||
|
stopSendingFrameType = 0x5
|
||||||
|
cryptoFrameType = 0x6
|
||||||
|
newTokenFrameType = 0x7
|
||||||
|
maxDataFrameType = 0x10
|
||||||
|
maxStreamDataFrameType = 0x11
|
||||||
|
bidiMaxStreamsFrameType = 0x12
|
||||||
|
uniMaxStreamsFrameType = 0x13
|
||||||
|
dataBlockedFrameType = 0x14
|
||||||
|
streamDataBlockedFrameType = 0x15
|
||||||
|
bidiStreamBlockedFrameType = 0x16
|
||||||
|
uniStreamBlockedFrameType = 0x17
|
||||||
|
newConnectionIDFrameType = 0x18
|
||||||
|
retireConnectionIDFrameType = 0x19
|
||||||
|
pathChallengeFrameType = 0x1a
|
||||||
|
pathResponseFrameType = 0x1b
|
||||||
|
connectionCloseFrameType = 0x1c
|
||||||
|
applicationCloseFrameType = 0x1d
|
||||||
|
handshakeDoneFrameType = 0x1e
|
||||||
|
)
|
||||||
|
|
||||||
type frameParser struct {
|
type frameParser struct {
|
||||||
r bytes.Reader // cached bytes.Reader, so we don't have to repeatedly allocate them
|
r bytes.Reader // cached bytes.Reader, so we don't have to repeatedly allocate them
|
||||||
|
|
||||||
|
@ -73,45 +98,45 @@ func (p *frameParser) parseFrame(r *bytes.Reader, typ uint64, encLevel protocol.
|
||||||
frame, err = parseStreamFrame(r, typ, v)
|
frame, err = parseStreamFrame(r, typ, v)
|
||||||
} else {
|
} else {
|
||||||
switch typ {
|
switch typ {
|
||||||
case 0x1:
|
case pingFrameType:
|
||||||
frame = &PingFrame{}
|
frame = &PingFrame{}
|
||||||
case 0x2, 0x3:
|
case ackFrameType, ackECNFrameType:
|
||||||
ackDelayExponent := p.ackDelayExponent
|
ackDelayExponent := p.ackDelayExponent
|
||||||
if encLevel != protocol.Encryption1RTT {
|
if encLevel != protocol.Encryption1RTT {
|
||||||
ackDelayExponent = protocol.DefaultAckDelayExponent
|
ackDelayExponent = protocol.DefaultAckDelayExponent
|
||||||
}
|
}
|
||||||
frame, err = parseAckFrame(r, typ, ackDelayExponent, v)
|
frame, err = parseAckFrame(r, typ, ackDelayExponent, v)
|
||||||
case 0x4:
|
case resetStreamFrameType:
|
||||||
frame, err = parseResetStreamFrame(r, v)
|
frame, err = parseResetStreamFrame(r, v)
|
||||||
case 0x5:
|
case stopSendingFrameType:
|
||||||
frame, err = parseStopSendingFrame(r, v)
|
frame, err = parseStopSendingFrame(r, v)
|
||||||
case 0x6:
|
case cryptoFrameType:
|
||||||
frame, err = parseCryptoFrame(r, v)
|
frame, err = parseCryptoFrame(r, v)
|
||||||
case 0x7:
|
case newTokenFrameType:
|
||||||
frame, err = parseNewTokenFrame(r, v)
|
frame, err = parseNewTokenFrame(r, v)
|
||||||
case 0x10:
|
case maxDataFrameType:
|
||||||
frame, err = parseMaxDataFrame(r, v)
|
frame, err = parseMaxDataFrame(r, v)
|
||||||
case 0x11:
|
case maxStreamDataFrameType:
|
||||||
frame, err = parseMaxStreamDataFrame(r, v)
|
frame, err = parseMaxStreamDataFrame(r, v)
|
||||||
case 0x12, 0x13:
|
case bidiMaxStreamsFrameType, uniMaxStreamsFrameType:
|
||||||
frame, err = parseMaxStreamsFrame(r, typ, v)
|
frame, err = parseMaxStreamsFrame(r, typ, v)
|
||||||
case 0x14:
|
case dataBlockedFrameType:
|
||||||
frame, err = parseDataBlockedFrame(r, v)
|
frame, err = parseDataBlockedFrame(r, v)
|
||||||
case 0x15:
|
case streamDataBlockedFrameType:
|
||||||
frame, err = parseStreamDataBlockedFrame(r, v)
|
frame, err = parseStreamDataBlockedFrame(r, v)
|
||||||
case 0x16, 0x17:
|
case bidiStreamBlockedFrameType, uniStreamBlockedFrameType:
|
||||||
frame, err = parseStreamsBlockedFrame(r, typ, v)
|
frame, err = parseStreamsBlockedFrame(r, typ, v)
|
||||||
case 0x18:
|
case newConnectionIDFrameType:
|
||||||
frame, err = parseNewConnectionIDFrame(r, v)
|
frame, err = parseNewConnectionIDFrame(r, v)
|
||||||
case 0x19:
|
case retireConnectionIDFrameType:
|
||||||
frame, err = parseRetireConnectionIDFrame(r, v)
|
frame, err = parseRetireConnectionIDFrame(r, v)
|
||||||
case 0x1a:
|
case pathChallengeFrameType:
|
||||||
frame, err = parsePathChallengeFrame(r, v)
|
frame, err = parsePathChallengeFrame(r, v)
|
||||||
case 0x1b:
|
case pathResponseFrameType:
|
||||||
frame, err = parsePathResponseFrame(r, v)
|
frame, err = parsePathResponseFrame(r, v)
|
||||||
case 0x1c, 0x1d:
|
case connectionCloseFrameType, applicationCloseFrameType:
|
||||||
frame, err = parseConnectionCloseFrame(r, typ, v)
|
frame, err = parseConnectionCloseFrame(r, typ, v)
|
||||||
case 0x1e:
|
case handshakeDoneFrameType:
|
||||||
frame = &HandshakeDoneFrame{}
|
frame = &HandshakeDoneFrame{}
|
||||||
case 0x30, 0x31:
|
case 0x30, 0x31:
|
||||||
if p.supportsDatagrams {
|
if p.supportsDatagrams {
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
type HandshakeDoneFrame struct{}
|
type HandshakeDoneFrame struct{}
|
||||||
|
|
||||||
func (f *HandshakeDoneFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
|
func (f *HandshakeDoneFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
|
||||||
return append(b, 0x1e), nil
|
return append(b, handshakeDoneFrameType), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Length of a written frame
|
// Length of a written frame
|
||||||
|
|
|
@ -13,7 +13,7 @@ var _ = Describe("HANDSHAKE_DONE frame", func() {
|
||||||
frame := HandshakeDoneFrame{}
|
frame := HandshakeDoneFrame{}
|
||||||
b, err := frame.Append(nil, protocol.VersionWhatever)
|
b, err := frame.Append(nil, protocol.VersionWhatever)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(b).To(Equal([]byte{0x1e}))
|
Expect(b).To(Equal([]byte{handshakeDoneFrameType}))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("has the correct min length", func() {
|
It("has the correct min length", func() {
|
||||||
|
|
|
@ -23,9 +23,8 @@ func parseMaxDataFrame(r *bytes.Reader, _ protocol.VersionNumber) (*MaxDataFrame
|
||||||
return frame, nil
|
return frame, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write writes a MAX_STREAM_DATA frame
|
|
||||||
func (f *MaxDataFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
|
func (f *MaxDataFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
|
||||||
b = append(b, 0x10)
|
b = append(b, maxDataFrameType)
|
||||||
b = quicvarint.Append(b, uint64(f.MaximumData))
|
b = quicvarint.Append(b, uint64(f.MaximumData))
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ var _ = Describe("MAX_DATA frame", func() {
|
||||||
}
|
}
|
||||||
b, err := f.Append(nil, protocol.Version1)
|
b, err := f.Append(nil, protocol.Version1)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
expected := []byte{0x10}
|
expected := []byte{maxDataFrameType}
|
||||||
expected = append(expected, encodeVarInt(0xdeadbeefcafe)...)
|
expected = append(expected, encodeVarInt(0xdeadbeefcafe)...)
|
||||||
Expect(b).To(Equal(expected))
|
Expect(b).To(Equal(expected))
|
||||||
})
|
})
|
||||||
|
|
|
@ -30,7 +30,7 @@ func parseMaxStreamDataFrame(r *bytes.Reader, _ protocol.VersionNumber) (*MaxStr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *MaxStreamDataFrame) Append(b []byte, version protocol.VersionNumber) ([]byte, error) {
|
func (f *MaxStreamDataFrame) Append(b []byte, version protocol.VersionNumber) ([]byte, error) {
|
||||||
b = append(b, 0x11)
|
b = append(b, maxStreamDataFrameType)
|
||||||
b = quicvarint.Append(b, uint64(f.StreamID))
|
b = quicvarint.Append(b, uint64(f.StreamID))
|
||||||
b = quicvarint.Append(b, uint64(f.MaximumStreamData))
|
b = quicvarint.Append(b, uint64(f.MaximumStreamData))
|
||||||
return b, nil
|
return b, nil
|
||||||
|
|
|
@ -51,7 +51,7 @@ var _ = Describe("MAX_STREAM_DATA frame", func() {
|
||||||
StreamID: 0xdecafbad,
|
StreamID: 0xdecafbad,
|
||||||
MaximumStreamData: 0xdeadbeefcafe42,
|
MaximumStreamData: 0xdeadbeefcafe42,
|
||||||
}
|
}
|
||||||
expected := []byte{0x11}
|
expected := []byte{maxStreamDataFrameType}
|
||||||
expected = append(expected, encodeVarInt(0xdecafbad)...)
|
expected = append(expected, encodeVarInt(0xdecafbad)...)
|
||||||
expected = append(expected, encodeVarInt(0xdeadbeefcafe42)...)
|
expected = append(expected, encodeVarInt(0xdeadbeefcafe42)...)
|
||||||
b, err := f.Append(nil, protocol.Version1)
|
b, err := f.Append(nil, protocol.Version1)
|
||||||
|
|
|
@ -17,9 +17,9 @@ type MaxStreamsFrame struct {
|
||||||
func parseMaxStreamsFrame(r *bytes.Reader, typ uint64, _ protocol.VersionNumber) (*MaxStreamsFrame, error) {
|
func parseMaxStreamsFrame(r *bytes.Reader, typ uint64, _ protocol.VersionNumber) (*MaxStreamsFrame, error) {
|
||||||
f := &MaxStreamsFrame{}
|
f := &MaxStreamsFrame{}
|
||||||
switch typ {
|
switch typ {
|
||||||
case 0x12:
|
case bidiMaxStreamsFrameType:
|
||||||
f.Type = protocol.StreamTypeBidi
|
f.Type = protocol.StreamTypeBidi
|
||||||
case 0x13:
|
case uniMaxStreamsFrameType:
|
||||||
f.Type = protocol.StreamTypeUni
|
f.Type = protocol.StreamTypeUni
|
||||||
}
|
}
|
||||||
streamID, err := quicvarint.Read(r)
|
streamID, err := quicvarint.Read(r)
|
||||||
|
@ -36,9 +36,9 @@ func parseMaxStreamsFrame(r *bytes.Reader, typ uint64, _ protocol.VersionNumber)
|
||||||
func (f *MaxStreamsFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
|
func (f *MaxStreamsFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
|
||||||
switch f.Type {
|
switch f.Type {
|
||||||
case protocol.StreamTypeBidi:
|
case protocol.StreamTypeBidi:
|
||||||
b = append(b, 0x12)
|
b = append(b, bidiMaxStreamsFrameType)
|
||||||
case protocol.StreamTypeUni:
|
case protocol.StreamTypeUni:
|
||||||
b = append(b, 0x13)
|
b = append(b, uniMaxStreamsFrameType)
|
||||||
}
|
}
|
||||||
b = quicvarint.Append(b, uint64(f.MaxStreamNum))
|
b = quicvarint.Append(b, uint64(f.MaxStreamNum))
|
||||||
return b, nil
|
return b, nil
|
||||||
|
|
|
@ -17,7 +17,7 @@ var _ = Describe("MAX_STREAMS frame", func() {
|
||||||
It("accepts a frame for a bidirectional stream", func() {
|
It("accepts a frame for a bidirectional stream", func() {
|
||||||
data := encodeVarInt(0xdecaf)
|
data := encodeVarInt(0xdecaf)
|
||||||
b := bytes.NewReader(data)
|
b := bytes.NewReader(data)
|
||||||
f, err := parseMaxStreamsFrame(b, 0x12, protocol.VersionWhatever)
|
f, err := parseMaxStreamsFrame(b, bidiMaxStreamsFrameType, protocol.VersionWhatever)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(f.Type).To(Equal(protocol.StreamTypeBidi))
|
Expect(f.Type).To(Equal(protocol.StreamTypeBidi))
|
||||||
Expect(f.MaxStreamNum).To(BeEquivalentTo(0xdecaf))
|
Expect(f.MaxStreamNum).To(BeEquivalentTo(0xdecaf))
|
||||||
|
@ -27,7 +27,7 @@ var _ = Describe("MAX_STREAMS frame", func() {
|
||||||
It("accepts a frame for a bidirectional stream", func() {
|
It("accepts a frame for a bidirectional stream", func() {
|
||||||
data := encodeVarInt(0xdecaf)
|
data := encodeVarInt(0xdecaf)
|
||||||
b := bytes.NewReader(data)
|
b := bytes.NewReader(data)
|
||||||
f, err := parseMaxStreamsFrame(b, 0x13, protocol.VersionWhatever)
|
f, err := parseMaxStreamsFrame(b, uniMaxStreamsFrameType, protocol.VersionWhatever)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(f.Type).To(Equal(protocol.StreamTypeUni))
|
Expect(f.Type).To(Equal(protocol.StreamTypeUni))
|
||||||
Expect(f.MaxStreamNum).To(BeEquivalentTo(0xdecaf))
|
Expect(f.MaxStreamNum).To(BeEquivalentTo(0xdecaf))
|
||||||
|
@ -87,7 +87,7 @@ var _ = Describe("MAX_STREAMS frame", func() {
|
||||||
}
|
}
|
||||||
b, err := f.Append(nil, protocol.VersionWhatever)
|
b, err := f.Append(nil, protocol.VersionWhatever)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
expected := []byte{0x12}
|
expected := []byte{bidiMaxStreamsFrameType}
|
||||||
expected = append(expected, encodeVarInt(0xdeadbeef)...)
|
expected = append(expected, encodeVarInt(0xdeadbeef)...)
|
||||||
Expect(b).To(Equal(expected))
|
Expect(b).To(Equal(expected))
|
||||||
})
|
})
|
||||||
|
@ -99,7 +99,7 @@ var _ = Describe("MAX_STREAMS frame", func() {
|
||||||
}
|
}
|
||||||
b, err := f.Append(nil, protocol.VersionWhatever)
|
b, err := f.Append(nil, protocol.VersionWhatever)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
expected := []byte{0x13}
|
expected := []byte{uniMaxStreamsFrameType}
|
||||||
expected = append(expected, encodeVarInt(0xdecafbad)...)
|
expected = append(expected, encodeVarInt(0xdecafbad)...)
|
||||||
Expect(b).To(Equal(expected))
|
Expect(b).To(Equal(expected))
|
||||||
})
|
})
|
||||||
|
|
|
@ -54,7 +54,7 @@ func parseNewConnectionIDFrame(r *bytes.Reader, _ protocol.VersionNumber) (*NewC
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *NewConnectionIDFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
|
func (f *NewConnectionIDFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
|
||||||
b = append(b, 0x18)
|
b = append(b, newConnectionIDFrameType)
|
||||||
b = quicvarint.Append(b, f.SequenceNumber)
|
b = quicvarint.Append(b, f.SequenceNumber)
|
||||||
b = quicvarint.Append(b, f.RetirePriorTo)
|
b = quicvarint.Append(b, f.RetirePriorTo)
|
||||||
connIDLen := f.ConnectionID.Len()
|
connIDLen := f.ConnectionID.Len()
|
||||||
|
|
|
@ -74,7 +74,7 @@ var _ = Describe("NEW_CONNECTION_ID frame", func() {
|
||||||
}
|
}
|
||||||
b, err := frame.Append(nil, protocol.Version1)
|
b, err := frame.Append(nil, protocol.Version1)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
expected := []byte{0x18}
|
expected := []byte{newConnectionIDFrameType}
|
||||||
expected = append(expected, encodeVarInt(0x1337)...)
|
expected = append(expected, encodeVarInt(0x1337)...)
|
||||||
expected = append(expected, encodeVarInt(0x42)...)
|
expected = append(expected, encodeVarInt(0x42)...)
|
||||||
expected = append(expected, 6)
|
expected = append(expected, 6)
|
||||||
|
|
|
@ -33,7 +33,7 @@ func parseNewTokenFrame(r *bytes.Reader, _ protocol.VersionNumber) (*NewTokenFra
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *NewTokenFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
|
func (f *NewTokenFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
|
||||||
b = append(b, 0x7)
|
b = append(b, newTokenFrameType)
|
||||||
b = quicvarint.Append(b, uint64(len(f.Token)))
|
b = quicvarint.Append(b, uint64(len(f.Token)))
|
||||||
b = append(b, f.Token...)
|
b = append(b, f.Token...)
|
||||||
return b, nil
|
return b, nil
|
||||||
|
|
|
@ -51,7 +51,7 @@ var _ = Describe("NEW_TOKEN frame", func() {
|
||||||
f := &NewTokenFrame{Token: []byte(token)}
|
f := &NewTokenFrame{Token: []byte(token)}
|
||||||
b, err := f.Append(nil, protocol.VersionWhatever)
|
b, err := f.Append(nil, protocol.VersionWhatever)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
expected := []byte{0x7}
|
expected := []byte{newTokenFrameType}
|
||||||
expected = append(expected, encodeVarInt(uint64(len(token)))...)
|
expected = append(expected, encodeVarInt(uint64(len(token)))...)
|
||||||
expected = append(expected, token...)
|
expected = append(expected, token...)
|
||||||
Expect(b).To(Equal(expected))
|
Expect(b).To(Equal(expected))
|
||||||
|
|
|
@ -24,7 +24,7 @@ func parsePathChallengeFrame(r *bytes.Reader, _ protocol.VersionNumber) (*PathCh
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *PathChallengeFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
|
func (f *PathChallengeFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
|
||||||
b = append(b, 0x1a)
|
b = append(b, pathChallengeFrameType)
|
||||||
b = append(b, f.Data[:]...)
|
b = append(b, f.Data[:]...)
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ var _ = Describe("PATH_CHALLENGE frame", func() {
|
||||||
frame := PathChallengeFrame{Data: [8]byte{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37}}
|
frame := PathChallengeFrame{Data: [8]byte{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37}}
|
||||||
b, err := frame.Append(nil, protocol.VersionWhatever)
|
b, err := frame.Append(nil, protocol.VersionWhatever)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(b).To(Equal([]byte{0x1a, 0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37}))
|
Expect(b).To(Equal([]byte{pathChallengeFrameType, 0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37}))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("has the correct length", func() {
|
It("has the correct length", func() {
|
||||||
|
|
|
@ -24,7 +24,7 @@ func parsePathResponseFrame(r *bytes.Reader, _ protocol.VersionNumber) (*PathRes
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *PathResponseFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
|
func (f *PathResponseFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
|
||||||
b = append(b, 0x1b)
|
b = append(b, pathResponseFrameType)
|
||||||
b = append(b, f.Data[:]...)
|
b = append(b, f.Data[:]...)
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ var _ = Describe("PATH_RESPONSE frame", func() {
|
||||||
frame := PathResponseFrame{Data: [8]byte{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37}}
|
frame := PathResponseFrame{Data: [8]byte{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37}}
|
||||||
b, err := frame.Append(nil, protocol.VersionWhatever)
|
b, err := frame.Append(nil, protocol.VersionWhatever)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(b).To(Equal([]byte{0x1b, 0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37}))
|
Expect(b).To(Equal([]byte{pathResponseFrameType, 0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37}))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("has the correct length", func() {
|
It("has the correct length", func() {
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
type PingFrame struct{}
|
type PingFrame struct{}
|
||||||
|
|
||||||
func (f *PingFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
|
func (f *PingFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
|
||||||
return append(b, 0x1), nil
|
return append(b, pingFrameType), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Length of a written frame
|
// Length of a written frame
|
||||||
|
|
|
@ -41,7 +41,7 @@ func parseResetStreamFrame(r *bytes.Reader, _ protocol.VersionNumber) (*ResetStr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *ResetStreamFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
|
func (f *ResetStreamFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
|
||||||
b = append(b, 0x4)
|
b = append(b, resetStreamFrameType)
|
||||||
b = quicvarint.Append(b, uint64(f.StreamID))
|
b = quicvarint.Append(b, uint64(f.StreamID))
|
||||||
b = quicvarint.Append(b, uint64(f.ErrorCode))
|
b = quicvarint.Append(b, uint64(f.ErrorCode))
|
||||||
b = quicvarint.Append(b, uint64(f.FinalSize))
|
b = quicvarint.Append(b, uint64(f.FinalSize))
|
||||||
|
|
|
@ -47,7 +47,7 @@ var _ = Describe("RESET_STREAM frame", func() {
|
||||||
}
|
}
|
||||||
b, err := frame.Append(nil, protocol.Version1)
|
b, err := frame.Append(nil, protocol.Version1)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
expected := []byte{0x4}
|
expected := []byte{resetStreamFrameType}
|
||||||
expected = append(expected, encodeVarInt(0x1337)...)
|
expected = append(expected, encodeVarInt(0x1337)...)
|
||||||
expected = append(expected, encodeVarInt(0xcafe)...)
|
expected = append(expected, encodeVarInt(0xcafe)...)
|
||||||
expected = append(expected, encodeVarInt(0x11223344decafbad)...)
|
expected = append(expected, encodeVarInt(0x11223344decafbad)...)
|
||||||
|
|
|
@ -21,7 +21,7 @@ func parseRetireConnectionIDFrame(r *bytes.Reader, _ protocol.VersionNumber) (*R
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *RetireConnectionIDFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
|
func (f *RetireConnectionIDFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
|
||||||
b = append(b, 0x19)
|
b = append(b, retireConnectionIDFrameType)
|
||||||
b = quicvarint.Append(b, f.SequenceNumber)
|
b = quicvarint.Append(b, f.SequenceNumber)
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ var _ = Describe("NEW_CONNECTION_ID frame", func() {
|
||||||
frame := &RetireConnectionIDFrame{SequenceNumber: 0x1337}
|
frame := &RetireConnectionIDFrame{SequenceNumber: 0x1337}
|
||||||
b, err := frame.Append(nil, protocol.Version1)
|
b, err := frame.Append(nil, protocol.Version1)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
expected := []byte{0x19}
|
expected := []byte{retireConnectionIDFrameType}
|
||||||
expected = append(expected, encodeVarInt(0x1337)...)
|
expected = append(expected, encodeVarInt(0x1337)...)
|
||||||
Expect(b).To(Equal(expected))
|
Expect(b).To(Equal(expected))
|
||||||
})
|
})
|
||||||
|
|
|
@ -37,7 +37,7 @@ func (f *StopSendingFrame) Length(_ protocol.VersionNumber) protocol.ByteCount {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *StopSendingFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
|
func (f *StopSendingFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
|
||||||
b = append(b, 0x5)
|
b = append(b, stopSendingFrameType)
|
||||||
b = quicvarint.Append(b, uint64(f.StreamID))
|
b = quicvarint.Append(b, uint64(f.StreamID))
|
||||||
b = quicvarint.Append(b, uint64(f.ErrorCode))
|
b = quicvarint.Append(b, uint64(f.ErrorCode))
|
||||||
return b, nil
|
return b, nil
|
||||||
|
|
|
@ -46,7 +46,7 @@ var _ = Describe("STOP_SENDING frame", func() {
|
||||||
}
|
}
|
||||||
b, err := frame.Append(nil, protocol.Version1)
|
b, err := frame.Append(nil, protocol.Version1)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
expected := []byte{0x5}
|
expected := []byte{stopSendingFrameType}
|
||||||
expected = append(expected, encodeVarInt(0xdeadbeefcafe)...)
|
expected = append(expected, encodeVarInt(0xdeadbeefcafe)...)
|
||||||
expected = append(expected, encodeVarInt(0xdecafbad)...)
|
expected = append(expected, encodeVarInt(0xdecafbad)...)
|
||||||
Expect(b).To(Equal(expected))
|
Expect(b).To(Equal(expected))
|
||||||
|
|
|
@ -52,7 +52,7 @@ var _ = Describe("STREAM_DATA_BLOCKED frame", func() {
|
||||||
}
|
}
|
||||||
b, err := f.Append(nil, protocol.Version1)
|
b, err := f.Append(nil, protocol.Version1)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
expected := []byte{0x15}
|
expected := []byte{streamDataBlockedFrameType}
|
||||||
expected = append(expected, encodeVarInt(uint64(f.StreamID))...)
|
expected = append(expected, encodeVarInt(uint64(f.StreamID))...)
|
||||||
expected = append(expected, encodeVarInt(uint64(f.MaximumStreamData))...)
|
expected = append(expected, encodeVarInt(uint64(f.MaximumStreamData))...)
|
||||||
Expect(b).To(Equal(expected))
|
Expect(b).To(Equal(expected))
|
||||||
|
|
|
@ -17,9 +17,9 @@ type StreamsBlockedFrame struct {
|
||||||
func parseStreamsBlockedFrame(r *bytes.Reader, typ uint64, _ protocol.VersionNumber) (*StreamsBlockedFrame, error) {
|
func parseStreamsBlockedFrame(r *bytes.Reader, typ uint64, _ protocol.VersionNumber) (*StreamsBlockedFrame, error) {
|
||||||
f := &StreamsBlockedFrame{}
|
f := &StreamsBlockedFrame{}
|
||||||
switch typ {
|
switch typ {
|
||||||
case 0x16:
|
case bidiStreamBlockedFrameType:
|
||||||
f.Type = protocol.StreamTypeBidi
|
f.Type = protocol.StreamTypeBidi
|
||||||
case 0x17:
|
case uniStreamBlockedFrameType:
|
||||||
f.Type = protocol.StreamTypeUni
|
f.Type = protocol.StreamTypeUni
|
||||||
}
|
}
|
||||||
streamLimit, err := quicvarint.Read(r)
|
streamLimit, err := quicvarint.Read(r)
|
||||||
|
@ -36,9 +36,9 @@ func parseStreamsBlockedFrame(r *bytes.Reader, typ uint64, _ protocol.VersionNum
|
||||||
func (f *StreamsBlockedFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
|
func (f *StreamsBlockedFrame) Append(b []byte, _ protocol.VersionNumber) ([]byte, error) {
|
||||||
switch f.Type {
|
switch f.Type {
|
||||||
case protocol.StreamTypeBidi:
|
case protocol.StreamTypeBidi:
|
||||||
b = append(b, 0x16)
|
b = append(b, bidiStreamBlockedFrameType)
|
||||||
case protocol.StreamTypeUni:
|
case protocol.StreamTypeUni:
|
||||||
b = append(b, 0x17)
|
b = append(b, uniStreamBlockedFrameType)
|
||||||
}
|
}
|
||||||
b = quicvarint.Append(b, uint64(f.StreamLimit))
|
b = quicvarint.Append(b, uint64(f.StreamLimit))
|
||||||
return b, nil
|
return b, nil
|
||||||
|
|
|
@ -17,7 +17,7 @@ var _ = Describe("STREAMS_BLOCKED frame", func() {
|
||||||
It("accepts a frame for bidirectional streams", func() {
|
It("accepts a frame for bidirectional streams", func() {
|
||||||
expected := encodeVarInt(0x1337)
|
expected := encodeVarInt(0x1337)
|
||||||
b := bytes.NewReader(expected)
|
b := bytes.NewReader(expected)
|
||||||
f, err := parseStreamsBlockedFrame(b, 0x16, protocol.VersionWhatever)
|
f, err := parseStreamsBlockedFrame(b, bidiStreamBlockedFrameType, protocol.VersionWhatever)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(f.Type).To(Equal(protocol.StreamTypeBidi))
|
Expect(f.Type).To(Equal(protocol.StreamTypeBidi))
|
||||||
Expect(f.StreamLimit).To(BeEquivalentTo(0x1337))
|
Expect(f.StreamLimit).To(BeEquivalentTo(0x1337))
|
||||||
|
@ -27,7 +27,7 @@ var _ = Describe("STREAMS_BLOCKED frame", func() {
|
||||||
It("accepts a frame for unidirectional streams", func() {
|
It("accepts a frame for unidirectional streams", func() {
|
||||||
expected := encodeVarInt(0x7331)
|
expected := encodeVarInt(0x7331)
|
||||||
b := bytes.NewReader(expected)
|
b := bytes.NewReader(expected)
|
||||||
f, err := parseStreamsBlockedFrame(b, 0x17, protocol.VersionWhatever)
|
f, err := parseStreamsBlockedFrame(b, uniStreamBlockedFrameType, protocol.VersionWhatever)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(f.Type).To(Equal(protocol.StreamTypeUni))
|
Expect(f.Type).To(Equal(protocol.StreamTypeUni))
|
||||||
Expect(f.StreamLimit).To(BeEquivalentTo(0x7331))
|
Expect(f.StreamLimit).To(BeEquivalentTo(0x7331))
|
||||||
|
@ -37,10 +37,10 @@ var _ = Describe("STREAMS_BLOCKED frame", func() {
|
||||||
It("errors on EOFs", func() {
|
It("errors on EOFs", func() {
|
||||||
data := encodeVarInt(0x12345678)
|
data := encodeVarInt(0x12345678)
|
||||||
b := bytes.NewReader(data)
|
b := bytes.NewReader(data)
|
||||||
_, err := parseStreamsBlockedFrame(b, 0x16, protocol.Version1)
|
_, err := parseStreamsBlockedFrame(b, bidiStreamBlockedFrameType, protocol.Version1)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
for i := range data {
|
for i := range data {
|
||||||
_, err := parseStreamsBlockedFrame(bytes.NewReader(data[:i]), 0x16, protocol.Version1)
|
_, err := parseStreamsBlockedFrame(bytes.NewReader(data[:i]), bidiStreamBlockedFrameType, protocol.Version1)
|
||||||
Expect(err).To(MatchError(io.EOF))
|
Expect(err).To(MatchError(io.EOF))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -87,7 +87,7 @@ var _ = Describe("STREAMS_BLOCKED frame", func() {
|
||||||
}
|
}
|
||||||
b, err := f.Append(nil, protocol.VersionWhatever)
|
b, err := f.Append(nil, protocol.VersionWhatever)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
expected := []byte{0x16}
|
expected := []byte{bidiStreamBlockedFrameType}
|
||||||
expected = append(expected, encodeVarInt(0xdeadbeefcafe)...)
|
expected = append(expected, encodeVarInt(0xdeadbeefcafe)...)
|
||||||
Expect(b).To(Equal(expected))
|
Expect(b).To(Equal(expected))
|
||||||
})
|
})
|
||||||
|
@ -99,7 +99,7 @@ var _ = Describe("STREAMS_BLOCKED frame", func() {
|
||||||
}
|
}
|
||||||
b, err := f.Append(nil, protocol.VersionWhatever)
|
b, err := f.Append(nil, protocol.VersionWhatever)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
expected := []byte{0x17}
|
expected := []byte{uniStreamBlockedFrameType}
|
||||||
expected = append(expected, encodeVarInt(0xdeadbeefcafe)...)
|
expected = append(expected, encodeVarInt(0xdeadbeefcafe)...)
|
||||||
Expect(b).To(Equal(expected))
|
Expect(b).To(Equal(expected))
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue