add version number to Frame.Write

This commit is contained in:
Lucas Clemente 2016-05-09 19:50:15 +02:00
parent a219b72968
commit 14b16a429c
21 changed files with 48 additions and 46 deletions

View file

@ -21,7 +21,7 @@ type AckFrame struct {
} }
// Write writes an ACK frame. // Write writes an ACK frame.
func (f *AckFrame) Write(b *bytes.Buffer, packetNumber protocol.PacketNumber, packetNumberLen protocol.PacketNumberLen) error { func (f *AckFrame) Write(b *bytes.Buffer, packetNumber protocol.PacketNumber, packetNumberLen protocol.PacketNumberLen, version protocol.VersionNumber) error {
typeByte := uint8(0x40 | 0x0C) typeByte := uint8(0x40 | 0x0C)
if f.HasNACK() { if f.HasNACK() {

View file

@ -238,7 +238,7 @@ var _ = Describe("AckFrame", func() {
Entropy: 2, Entropy: 2,
LargestObserved: 1, LargestObserved: 1,
} }
err := frame.Write(b, 1, protocol.PacketNumberLen6) err := frame.Write(b, 1, protocol.PacketNumberLen6, 32)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(b.Bytes()).To(Equal([]byte{0x4c, 0x02, 0x01, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0})) Expect(b.Bytes()).To(Equal([]byte{0x4c, 0x02, 0x01, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0}))
}) })
@ -249,7 +249,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 4, LargestObserved: 4,
NackRanges: []NackRange{NackRange{FirstPacketNumber: 2, LastPacketNumber: 2}}, NackRanges: []NackRange{NackRange{FirstPacketNumber: 2, LastPacketNumber: 2}},
} }
err := frame.Write(b, 1, protocol.PacketNumberLen6) err := frame.Write(b, 1, protocol.PacketNumberLen6, 32)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
missingPacketBytes := b.Bytes()[b.Len()-8:] missingPacketBytes := b.Bytes()[b.Len()-8:]
Expect(missingPacketBytes[0]).To(Equal(uint8(1))) // numRanges Expect(missingPacketBytes[0]).To(Equal(uint8(1))) // numRanges
@ -267,7 +267,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 7, LargestObserved: 7,
NackRanges: []NackRange{nackRange1, nackRange2}, NackRanges: []NackRange{nackRange1, nackRange2},
} }
err := frame.Write(b, 1, protocol.PacketNumberLen6) err := frame.Write(b, 1, protocol.PacketNumberLen6, 32)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
missingPacketBytes := b.Bytes()[b.Len()-(1+2*7):] missingPacketBytes := b.Bytes()[b.Len()-(1+2*7):]
Expect(missingPacketBytes[0]).To(Equal(uint8(2))) // numRanges Expect(missingPacketBytes[0]).To(Equal(uint8(2))) // numRanges
@ -288,7 +288,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 258, LargestObserved: 258,
NackRanges: []NackRange{NackRange{FirstPacketNumber: 2, LastPacketNumber: 257}}, NackRanges: []NackRange{NackRange{FirstPacketNumber: 2, LastPacketNumber: 257}},
} }
err := frame.Write(b, 1, protocol.PacketNumberLen6) err := frame.Write(b, 1, protocol.PacketNumberLen6, 32)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
missingPacketBytes := b.Bytes()[b.Len()-(1+7):] missingPacketBytes := b.Bytes()[b.Len()-(1+7):]
Expect(missingPacketBytes[0]).To(Equal(uint8(1))) // numRanges Expect(missingPacketBytes[0]).To(Equal(uint8(1))) // numRanges
@ -302,7 +302,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 302, LargestObserved: 302,
NackRanges: []NackRange{NackRange{FirstPacketNumber: 2, LastPacketNumber: 301}}, NackRanges: []NackRange{NackRange{FirstPacketNumber: 2, LastPacketNumber: 301}},
} }
err := frame.Write(b, 1, protocol.PacketNumberLen6) err := frame.Write(b, 1, protocol.PacketNumberLen6, 32)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
missingPacketBytes := b.Bytes()[b.Len()-(1+2*7):] missingPacketBytes := b.Bytes()[b.Len()-(1+2*7):]
Expect(missingPacketBytes[0]).To(Equal(uint8(2))) // numRanges Expect(missingPacketBytes[0]).To(Equal(uint8(2))) // numRanges
@ -318,7 +318,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 259, LargestObserved: 259,
NackRanges: []NackRange{NackRange{FirstPacketNumber: 2, LastPacketNumber: 258}}, NackRanges: []NackRange{NackRange{FirstPacketNumber: 2, LastPacketNumber: 258}},
} }
err := frame.Write(b, 1, protocol.PacketNumberLen6) err := frame.Write(b, 1, protocol.PacketNumberLen6, 32)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
missingPacketBytes := b.Bytes()[b.Len()-(1+2*7):] missingPacketBytes := b.Bytes()[b.Len()-(1+2*7):]
Expect(missingPacketBytes[0]).To(Equal(uint8(2))) // numRanges Expect(missingPacketBytes[0]).To(Equal(uint8(2))) // numRanges
@ -334,7 +334,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 603, LargestObserved: 603,
NackRanges: []NackRange{NackRange{FirstPacketNumber: 2, LastPacketNumber: 601}}, NackRanges: []NackRange{NackRange{FirstPacketNumber: 2, LastPacketNumber: 601}},
} }
err := frame.Write(b, 1, protocol.PacketNumberLen6) err := frame.Write(b, 1, protocol.PacketNumberLen6, 32)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
missingPacketBytes := b.Bytes()[b.Len()-(1+3*7):] missingPacketBytes := b.Bytes()[b.Len()-(1+3*7):]
Expect(missingPacketBytes[0]).To(Equal(uint8(3))) // numRanges Expect(missingPacketBytes[0]).To(Equal(uint8(3))) // numRanges
@ -354,7 +354,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 655, LargestObserved: 655,
NackRanges: []NackRange{nackRange2, nackRange1}, NackRanges: []NackRange{nackRange2, nackRange1},
} }
err := frame.Write(b, 1, protocol.PacketNumberLen6) err := frame.Write(b, 1, protocol.PacketNumberLen6, 32)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
missingPacketBytes := b.Bytes()[b.Len()-(1+4*7):] missingPacketBytes := b.Bytes()[b.Len()-(1+4*7):]
Expect(missingPacketBytes[0]).To(Equal(uint8(4))) // numRanges Expect(missingPacketBytes[0]).To(Equal(uint8(4))) // numRanges
@ -375,7 +375,7 @@ var _ = Describe("AckFrame", func() {
Entropy: 2, Entropy: 2,
LargestObserved: 1, LargestObserved: 1,
} }
f.Write(b, 1, protocol.PacketNumberLen6) f.Write(b, 1, protocol.PacketNumberLen6, 32)
Expect(f.MinLength()).To(Equal(b.Len())) Expect(f.MinLength()).To(Equal(b.Len()))
}) })
@ -385,7 +385,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 4, LargestObserved: 4,
NackRanges: []NackRange{NackRange{FirstPacketNumber: 2, LastPacketNumber: 2}}, NackRanges: []NackRange{NackRange{FirstPacketNumber: 2, LastPacketNumber: 2}},
} }
err := f.Write(b, 1, protocol.PacketNumberLen6) err := f.Write(b, 1, protocol.PacketNumberLen6, 32)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(f.MinLength()).To(Equal(b.Len())) Expect(f.MinLength()).To(Equal(b.Len()))
}) })
@ -403,7 +403,7 @@ var _ = Describe("AckFrame", func() {
Entropy: 0xDE, Entropy: 0xDE,
LargestObserved: 6789, LargestObserved: 6789,
} }
err := frameOrig.Write(b, 1, protocol.PacketNumberLen6) err := frameOrig.Write(b, 1, protocol.PacketNumberLen6, 32)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
frame, err := ParseAckFrame(bytes.NewReader(b.Bytes())) frame, err := ParseAckFrame(bytes.NewReader(b.Bytes()))
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
@ -421,7 +421,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 15, LargestObserved: 15,
NackRanges: nackRanges, NackRanges: nackRanges,
} }
err := frameOrig.Write(b, 1, protocol.PacketNumberLen6) err := frameOrig.Write(b, 1, protocol.PacketNumberLen6, 32)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
r := bytes.NewReader(b.Bytes()) r := bytes.NewReader(b.Bytes())
frame, err := ParseAckFrame(r) frame, err := ParseAckFrame(r)
@ -441,7 +441,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 1600, LargestObserved: 1600,
NackRanges: nackRanges, NackRanges: nackRanges,
} }
err := frameOrig.Write(b, 1, protocol.PacketNumberLen6) err := frameOrig.Write(b, 1, protocol.PacketNumberLen6, 32)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
r := bytes.NewReader(b.Bytes()) r := bytes.NewReader(b.Bytes())
frame, err := ParseAckFrame(r) frame, err := ParseAckFrame(r)

View file

@ -13,7 +13,7 @@ type BlockedFrame struct {
} }
//Write writes a RST_STREAM frame //Write writes a RST_STREAM frame
func (f *BlockedFrame) Write(b *bytes.Buffer, packetNumber protocol.PacketNumber, packetNumberLen protocol.PacketNumberLen) error { func (f *BlockedFrame) Write(b *bytes.Buffer, packetNumber protocol.PacketNumber, packetNumberLen protocol.PacketNumberLen, version protocol.VersionNumber) error {
b.WriteByte(0x05) b.WriteByte(0x05)
if f.StreamID == 0 { if f.StreamID == 0 {

View file

@ -22,7 +22,7 @@ var _ = Describe("BlockedFrame", func() {
It("writes a sample frame", func() { It("writes a sample frame", func() {
b := &bytes.Buffer{} b := &bytes.Buffer{}
frame := BlockedFrame{StreamID: 0x1337} frame := BlockedFrame{StreamID: 0x1337}
frame.Write(b, 10, protocol.PacketNumberLen6) frame.Write(b, 10, protocol.PacketNumberLen6, 0)
Expect(b.Bytes()).To(Equal([]byte{0x05, 0x37, 0x13, 0x0, 0x0})) Expect(b.Bytes()).To(Equal([]byte{0x05, 0x37, 0x13, 0x0, 0x0}))
}) })

View file

@ -52,7 +52,7 @@ func (f *ConnectionCloseFrame) MinLength() int {
} }
// Write writes an CONNECTION_CLOSE frame. // Write writes an CONNECTION_CLOSE frame.
func (f *ConnectionCloseFrame) Write(b *bytes.Buffer, packetNumber protocol.PacketNumber, packetNumberLen protocol.PacketNumberLen) error { func (f *ConnectionCloseFrame) Write(b *bytes.Buffer, packetNumber protocol.PacketNumber, packetNumberLen protocol.PacketNumberLen, version protocol.VersionNumber) error {
b.WriteByte(0x02) b.WriteByte(0x02)
utils.WriteUint32(b, uint32(f.ErrorCode)) utils.WriteUint32(b, uint32(f.ErrorCode))

View file

@ -35,7 +35,7 @@ var _ = Describe("ConnectionCloseFrame", func() {
frame := &ConnectionCloseFrame{ frame := &ConnectionCloseFrame{
ErrorCode: 0xDEADBEEF, ErrorCode: 0xDEADBEEF,
} }
err := frame.Write(b, 1, protocol.PacketNumberLen6) err := frame.Write(b, 1, protocol.PacketNumberLen6, 0)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(b.Len()).To(Equal(1 + 2 + 4)) Expect(b.Len()).To(Equal(1 + 2 + 4))
Expect(b.Bytes()).To(Equal([]byte{0x02, 0xEF, 0xBE, 0xAD, 0xDE, 0x00, 0x00})) Expect(b.Bytes()).To(Equal([]byte{0x02, 0xEF, 0xBE, 0xAD, 0xDE, 0x00, 0x00}))
@ -47,7 +47,7 @@ var _ = Describe("ConnectionCloseFrame", func() {
ErrorCode: 0xDEADBEEF, ErrorCode: 0xDEADBEEF,
ReasonPhrase: "foobar", ReasonPhrase: "foobar",
} }
err := frame.Write(b, 1, protocol.PacketNumberLen6) err := frame.Write(b, 1, protocol.PacketNumberLen6, 0)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(b.Len()).To(Equal(1 + 2 + 4 + len(frame.ReasonPhrase))) Expect(b.Len()).To(Equal(1 + 2 + 4 + len(frame.ReasonPhrase)))
Expect(b.Bytes()[:5]).To(Equal([]byte{0x02, 0xEF, 0xBE, 0xAD, 0xDE})) Expect(b.Bytes()[:5]).To(Equal([]byte{0x02, 0xEF, 0xBE, 0xAD, 0xDE}))
@ -67,7 +67,7 @@ var _ = Describe("ConnectionCloseFrame", func() {
ErrorCode: 0xDEADBEEF, ErrorCode: 0xDEADBEEF,
ReasonPhrase: reasonPhrase, ReasonPhrase: reasonPhrase,
} }
err := frame.Write(b, 1, protocol.PacketNumberLen6) err := frame.Write(b, 1, protocol.PacketNumberLen6, 0)
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
}) })
@ -77,7 +77,7 @@ var _ = Describe("ConnectionCloseFrame", func() {
ErrorCode: 0xDEADBEEF, ErrorCode: 0xDEADBEEF,
ReasonPhrase: "foobar", ReasonPhrase: "foobar",
} }
f.Write(b, 1, protocol.PacketNumberLen6) f.Write(b, 1, protocol.PacketNumberLen6, 0)
Expect(f.MinLength()).To(Equal(b.Len())) Expect(f.MinLength()).To(Equal(b.Len()))
}) })
}) })
@ -88,7 +88,7 @@ var _ = Describe("ConnectionCloseFrame", func() {
ErrorCode: 0xDEADBEEF, ErrorCode: 0xDEADBEEF,
ReasonPhrase: "Lorem ipsum dolor sit amet.", ReasonPhrase: "Lorem ipsum dolor sit amet.",
} }
err := frame.Write(b, 1, protocol.PacketNumberLen6) err := frame.Write(b, 1, protocol.PacketNumberLen6, 0)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
readframe, err := ParseConnectionCloseFrame(bytes.NewReader(b.Bytes())) readframe, err := ParseConnectionCloseFrame(bytes.NewReader(b.Bytes()))
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())

View file

@ -8,6 +8,6 @@ import (
// A Frame in QUIC // A Frame in QUIC
type Frame interface { type Frame interface {
Write(b *bytes.Buffer, packetNumber protocol.PacketNumber, packetNumberLen protocol.PacketNumberLen) error Write(b *bytes.Buffer, packetNumber protocol.PacketNumber, packetNumberLen protocol.PacketNumberLen, version protocol.VersionNumber) error
MinLength() int MinLength() int
} }

View file

@ -21,7 +21,7 @@ func ParsePingFrame(r *bytes.Reader) (*PingFrame, error) {
return frame, nil return frame, nil
} }
func (f *PingFrame) Write(b *bytes.Buffer, packetNumber protocol.PacketNumber, packetNumberLen protocol.PacketNumberLen) error { func (f *PingFrame) Write(b *bytes.Buffer, packetNumber protocol.PacketNumber, packetNumberLen protocol.PacketNumberLen, version protocol.VersionNumber) error {
typeByte := uint8(0x07) typeByte := uint8(0x07)
b.WriteByte(typeByte) b.WriteByte(typeByte)
return nil return nil

View file

@ -22,7 +22,7 @@ var _ = Describe("PingFrame", func() {
It("writes a sample frame", func() { It("writes a sample frame", func() {
b := &bytes.Buffer{} b := &bytes.Buffer{}
frame := PingFrame{} frame := PingFrame{}
frame.Write(b, 10, protocol.PacketNumberLen6) frame.Write(b, 10, protocol.PacketNumberLen6, 0)
Expect(b.Bytes()).To(Equal([]byte{0x07})) Expect(b.Bytes()).To(Equal([]byte{0x07}))
}) })

View file

@ -15,7 +15,7 @@ type RstStreamFrame struct {
} }
//Write writes a RST_STREAM frame //Write writes a RST_STREAM frame
func (f *RstStreamFrame) Write(b *bytes.Buffer, packetNumber protocol.PacketNumber, packetNumberLen protocol.PacketNumberLen) error { func (f *RstStreamFrame) Write(b *bytes.Buffer, packetNumber protocol.PacketNumber, packetNumberLen protocol.PacketNumberLen, version protocol.VersionNumber) error {
panic("RstStreamFrame: Write not yet implemented") panic("RstStreamFrame: Write not yet implemented")
} }

View file

@ -14,7 +14,7 @@ type StopWaitingFrame struct {
LeastUnacked protocol.PacketNumber LeastUnacked protocol.PacketNumber
} }
func (f *StopWaitingFrame) Write(b *bytes.Buffer, packetNumber protocol.PacketNumber, packetNumberLen protocol.PacketNumberLen) error { func (f *StopWaitingFrame) Write(b *bytes.Buffer, packetNumber protocol.PacketNumber, packetNumberLen protocol.PacketNumberLen, version protocol.VersionNumber) error {
// packetNumber is the packet number of the packet that this StopWaitingFrame will be sent with // packetNumber is the packet number of the packet that this StopWaitingFrame will be sent with
typeByte := uint8(0x06) typeByte := uint8(0x06)
b.WriteByte(typeByte) b.WriteByte(typeByte)

View file

@ -34,7 +34,7 @@ var _ = Describe("StopWaitingFrame", func() {
LeastUnacked: 10, LeastUnacked: 10,
Entropy: 0xE, Entropy: 0xE,
} }
frame.Write(b, packetNumber, protocol.PacketNumberLen6) frame.Write(b, packetNumber, protocol.PacketNumberLen6, 0)
Expect(b.Bytes()[0]).To(Equal(uint8(0x06))) Expect(b.Bytes()[0]).To(Equal(uint8(0x06)))
// todo: check more // todo: check more
}) })
@ -48,7 +48,7 @@ var _ = Describe("StopWaitingFrame", func() {
Entropy: 0xE, Entropy: 0xE,
} }
b := &bytes.Buffer{} b := &bytes.Buffer{}
frame.Write(b, packetNumber, protocol.PacketNumberLen6) frame.Write(b, packetNumber, protocol.PacketNumberLen6, 0)
readframe, err := ParseStopWaitingFrame(bytes.NewReader(b.Bytes()), packetNumber, 6) readframe, err := ParseStopWaitingFrame(bytes.NewReader(b.Bytes()), packetNumber, 6)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(readframe.Entropy).To(Equal(frame.Entropy)) Expect(readframe.Entropy).To(Equal(frame.Entropy))

View file

@ -70,7 +70,7 @@ func ParseStreamFrame(r *bytes.Reader) (*StreamFrame, error) {
} }
// WriteStreamFrame writes a stream frame. // WriteStreamFrame writes a stream frame.
func (f *StreamFrame) Write(b *bytes.Buffer, packetNumber protocol.PacketNumber, packetNumberLen protocol.PacketNumberLen) error { func (f *StreamFrame) Write(b *bytes.Buffer, packetNumber protocol.PacketNumber, packetNumberLen protocol.PacketNumberLen, version protocol.VersionNumber) error {
typeByte := uint8(0x80) typeByte := uint8(0x80)
if f.FinBit { if f.FinBit {
typeByte ^= 0x40 typeByte ^= 0x40

View file

@ -37,7 +37,7 @@ var _ = Describe("StreamFrame", func() {
(&StreamFrame{ (&StreamFrame{
StreamID: 1, StreamID: 1,
Data: []byte("foobar"), Data: []byte("foobar"),
}).Write(b, 1, protocol.PacketNumberLen6) }).Write(b, 1, protocol.PacketNumberLen6, 0)
Expect(b.Bytes()).To(Equal([]byte{0xa3, 0x1, 0, 0, 0, 0x06, 0x00, 'f', 'o', 'o', 'b', 'a', 'r'})) Expect(b.Bytes()).To(Equal([]byte{0xa3, 0x1, 0, 0, 0, 0x06, 0x00, 'f', 'o', 'o', 'b', 'a', 'r'}))
}) })
@ -47,7 +47,7 @@ var _ = Describe("StreamFrame", func() {
StreamID: 1, StreamID: 1,
Offset: 16, Offset: 16,
Data: []byte("foobar"), Data: []byte("foobar"),
}).Write(b, 1, protocol.PacketNumberLen6) }).Write(b, 1, protocol.PacketNumberLen6, 0)
Expect(b.Bytes()).To(Equal([]byte{0xbf, 0x1, 0, 0, 0, 0x10, 0, 0, 0, 0, 0, 0, 0, 0x06, 0x00, 'f', 'o', 'o', 'b', 'a', 'r'})) Expect(b.Bytes()).To(Equal([]byte{0xbf, 0x1, 0, 0, 0, 0x10, 0, 0, 0, 0, 0, 0, 0, 0x06, 0x00, 'f', 'o', 'o', 'b', 'a', 'r'}))
}) })
@ -58,7 +58,7 @@ var _ = Describe("StreamFrame", func() {
Data: []byte("f"), Data: []byte("f"),
Offset: 1, Offset: 1,
} }
f.Write(b, 1, protocol.PacketNumberLen6) f.Write(b, 1, protocol.PacketNumberLen6, 0)
Expect(f.MinLength()).To(Equal(b.Len())) Expect(f.MinLength()).To(Equal(b.Len()))
}) })
}) })

View file

@ -14,7 +14,7 @@ type WindowUpdateFrame struct {
} }
//Write writes a RST_STREAM frame //Write writes a RST_STREAM frame
func (f *WindowUpdateFrame) Write(b *bytes.Buffer, packetNumber protocol.PacketNumber, packetNumberLen protocol.PacketNumberLen) error { func (f *WindowUpdateFrame) Write(b *bytes.Buffer, packetNumber protocol.PacketNumber, packetNumberLen protocol.PacketNumberLen, version protocol.VersionNumber) error {
panic("WindowUpdateFrame: Write not yet implemented") panic("WindowUpdateFrame: Write not yet implemented")
} }

View file

@ -19,7 +19,9 @@ type packedPacket struct {
} }
type packetPacker struct { type packetPacker struct {
connectionID protocol.ConnectionID connectionID protocol.ConnectionID
version protocol.VersionNumber
aead crypto.AEAD aead crypto.AEAD
connectionParametersManager *handshake.ConnectionParametersManager connectionParametersManager *handshake.ConnectionParametersManager
@ -95,7 +97,7 @@ func (p *packetPacker) getPayload(frames []frames.Frame, currentPacketNumber pro
var payload bytes.Buffer var payload bytes.Buffer
payload.WriteByte(0) // The entropy bit is set in sendPayload payload.WriteByte(0) // The entropy bit is set in sendPayload
for _, frame := range frames { for _, frame := range frames {
frame.Write(&payload, currentPacketNumber, 6) frame.Write(&payload, currentPacketNumber, 6, p.version)
} }
return payload.Bytes(), nil return payload.Bytes(), nil
} }

View file

@ -37,7 +37,7 @@ var _ = Describe("Packet packer", func() {
Expect(p).ToNot(BeNil()) Expect(p).ToNot(BeNil())
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
b := &bytes.Buffer{} b := &bytes.Buffer{}
f.Write(b, 1, 6) f.Write(b, 1, 6, 0)
Expect(len(p.frames)).To(Equal(1)) Expect(len(p.frames)).To(Equal(1))
Expect(p.raw).To(ContainSubstring(string(b.Bytes()))) Expect(p.raw).To(ContainSubstring(string(b.Bytes())))
}) })
@ -80,7 +80,7 @@ var _ = Describe("Packet packer", func() {
It("packs many control frames into 1 packets", func() { It("packs many control frames into 1 packets", func() {
f := &frames.AckFrame{LargestObserved: 1} f := &frames.AckFrame{LargestObserved: 1}
b := &bytes.Buffer{} b := &bytes.Buffer{}
f.Write(b, 3, 6) f.Write(b, 3, 6, 32)
maxFramesPerPacket := protocol.MaxFrameSize / b.Len() maxFramesPerPacket := protocol.MaxFrameSize / b.Len()
var controlFrames []frames.Frame var controlFrames []frames.Frame
for i := 0; i < maxFramesPerPacket; i++ { for i := 0; i < maxFramesPerPacket; i++ {
@ -146,8 +146,8 @@ var _ = Describe("Packet packer", func() {
Expect(p).ToNot(BeNil()) Expect(p).ToNot(BeNil())
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
b := &bytes.Buffer{} b := &bytes.Buffer{}
f1.Write(b, 2, 6) f1.Write(b, 2, 6, 0)
f2.Write(b, 2, 6) f2.Write(b, 2, 6, 0)
Expect(len(p.frames)).To(Equal(2)) Expect(len(p.frames)).To(Equal(2))
Expect(p.raw).To(ContainSubstring(string(b.Bytes()))) Expect(p.raw).To(ContainSubstring(string(b.Bytes())))
}) })

View file

@ -50,7 +50,7 @@ var _ = Describe("Packet unpacker", func() {
StreamID: 1, StreamID: 1,
Data: []byte("foobar"), Data: []byte("foobar"),
} }
err := f.Write(buf, 3, 6) err := f.Write(buf, 3, 6, 0)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
setReader(buf.Bytes()) setReader(buf.Bytes())
packet, err := unpacker.Unpack(hdrBin, hdr, r) packet, err := unpacker.Unpack(hdrBin, hdr, r)
@ -63,7 +63,7 @@ var _ = Describe("Packet unpacker", func() {
LargestObserved: 1, LargestObserved: 1,
DelayTime: time.Microsecond, DelayTime: time.Microsecond,
} }
err := f.Write(buf, 3, 6) err := f.Write(buf, 3, 6, 32)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
setReader(buf.Bytes()) setReader(buf.Bytes())
packet, err := unpacker.Unpack(hdrBin, hdr, r) packet, err := unpacker.Unpack(hdrBin, hdr, r)
@ -99,7 +99,7 @@ var _ = Describe("Packet unpacker", func() {
It("unpacks CONNECTION_CLOSE frames", func() { It("unpacks CONNECTION_CLOSE frames", func() {
f := &frames.ConnectionCloseFrame{ReasonPhrase: "foo"} f := &frames.ConnectionCloseFrame{ReasonPhrase: "foo"}
err := f.Write(buf, 6, 6) err := f.Write(buf, 6, 6, 0)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
setReader(buf.Bytes()) setReader(buf.Bytes())
packet, err := unpacker.Unpack(hdrBin, hdr, r) packet, err := unpacker.Unpack(hdrBin, hdr, r)

View file

@ -11,7 +11,7 @@ type VersionNumber int
// SupportedVersions lists the versions that the server supports // SupportedVersions lists the versions that the server supports
var SupportedVersions = []VersionNumber{ var SupportedVersions = []VersionNumber{
32, 31, 32,
} }
// SupportedVersionsAsTags is needed for the SHLO crypto message // SupportedVersionsAsTags is needed for the SHLO crypto message

View file

@ -19,7 +19,7 @@ var _ = Describe("Version", func() {
}) })
It("has proper tag list", func() { It("has proper tag list", func() {
Expect(protocol.SupportedVersionsAsTags).To(Equal([]byte("Q032"))) Expect(protocol.SupportedVersionsAsTags).To(Equal([]byte("Q031Q032")))
}) })
It("recognizes supported versions", func() { It("recognizes supported versions", func() {

View file

@ -95,7 +95,7 @@ func NewSession(conn connection, v protocol.VersionNumber, connectionID protocol
} }
}() }()
session.packer = &packetPacker{aead: cryptoSetup, connectionParametersManager: session.connectionParametersManager, connectionID: connectionID} session.packer = &packetPacker{aead: cryptoSetup, connectionParametersManager: session.connectionParametersManager, connectionID: connectionID, version: v}
session.unpacker = &packetUnpacker{aead: cryptoSetup} session.unpacker = &packetUnpacker{aead: cryptoSetup}
session.congestion = congestion.NewCubicSender( session.congestion = congestion.NewCubicSender(