remove PacketNumber from Frame interface Write method

This commit is contained in:
Marten Seemann 2016-05-12 16:17:55 +07:00
parent e782f28b2b
commit 2f6e2c1201
18 changed files with 96 additions and 69 deletions

View file

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

View file

@ -249,7 +249,7 @@ var _ = Describe("AckFrame", func() {
Entropy: 2,
LargestObserved: 1,
}
err := frame.Write(b, 1, 32)
err := frame.Write(b, 32)
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}))
})
@ -260,7 +260,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 4,
NackRanges: []NackRange{NackRange{FirstPacketNumber: 2, LastPacketNumber: 2}},
}
err := frame.Write(b, 1, 32)
err := frame.Write(b, 32)
Expect(err).ToNot(HaveOccurred())
missingPacketBytes := b.Bytes()[b.Len()-8:]
Expect(missingPacketBytes[0]).To(Equal(uint8(1))) // numRanges
@ -276,7 +276,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 4,
NackRanges: []NackRange{NackRange{FirstPacketNumber: 2, LastPacketNumber: 2}},
}
err := frame.Write(b, 1, 31)
err := frame.Write(b, 31)
Expect(err).ToNot(HaveOccurred())
missingPacketBytes := b.Bytes()[b.Len()-9:]
Expect(missingPacketBytes[0]).To(Equal(uint8(1))) // numRanges
@ -295,7 +295,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 7,
NackRanges: []NackRange{nackRange1, nackRange2},
}
err := frame.Write(b, 1, 32)
err := frame.Write(b, 32)
Expect(err).ToNot(HaveOccurred())
missingPacketBytes := b.Bytes()[b.Len()-(1+2*7):]
Expect(missingPacketBytes[0]).To(Equal(uint8(2))) // numRanges
@ -316,7 +316,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 258,
NackRanges: []NackRange{NackRange{FirstPacketNumber: 2, LastPacketNumber: 257}},
}
err := frame.Write(b, 1, 32)
err := frame.Write(b, 32)
Expect(err).ToNot(HaveOccurred())
missingPacketBytes := b.Bytes()[b.Len()-(1+7):]
Expect(missingPacketBytes[0]).To(Equal(uint8(1))) // numRanges
@ -330,7 +330,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 302,
NackRanges: []NackRange{NackRange{FirstPacketNumber: 2, LastPacketNumber: 301}},
}
err := frame.Write(b, 1, 32)
err := frame.Write(b, 32)
Expect(err).ToNot(HaveOccurred())
missingPacketBytes := b.Bytes()[b.Len()-(1+2*7):]
Expect(missingPacketBytes[0]).To(Equal(uint8(2))) // numRanges
@ -346,7 +346,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 259,
NackRanges: []NackRange{NackRange{FirstPacketNumber: 2, LastPacketNumber: 258}},
}
err := frame.Write(b, 1, 32)
err := frame.Write(b, 32)
Expect(err).ToNot(HaveOccurred())
missingPacketBytes := b.Bytes()[b.Len()-(1+2*7):]
Expect(missingPacketBytes[0]).To(Equal(uint8(2))) // numRanges
@ -362,7 +362,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 603,
NackRanges: []NackRange{NackRange{FirstPacketNumber: 2, LastPacketNumber: 601}},
}
err := frame.Write(b, 1, 32)
err := frame.Write(b, 32)
Expect(err).ToNot(HaveOccurred())
missingPacketBytes := b.Bytes()[b.Len()-(1+3*7):]
Expect(missingPacketBytes[0]).To(Equal(uint8(3))) // numRanges
@ -382,7 +382,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 655,
NackRanges: []NackRange{nackRange2, nackRange1},
}
err := frame.Write(b, 1, 32)
err := frame.Write(b, 32)
Expect(err).ToNot(HaveOccurred())
missingPacketBytes := b.Bytes()[b.Len()-(1+4*7):]
Expect(missingPacketBytes[0]).To(Equal(uint8(4))) // numRanges
@ -403,7 +403,7 @@ var _ = Describe("AckFrame", func() {
Entropy: 2,
LargestObserved: 1,
}
f.Write(b, 1, 2)
f.Write(b, 2)
Expect(f.MinLength()).To(Equal(protocol.ByteCount(b.Len())))
})
@ -413,7 +413,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 4,
NackRanges: []NackRange{NackRange{FirstPacketNumber: 2, LastPacketNumber: 2}},
}
err := f.Write(b, 1, 31)
err := f.Write(b, 31)
Expect(err).ToNot(HaveOccurred())
Expect(f.MinLength()).To(Equal(protocol.ByteCount(b.Len())))
})
@ -431,7 +431,7 @@ var _ = Describe("AckFrame", func() {
Entropy: 0xDE,
LargestObserved: 6789,
}
err := frameOrig.Write(b, 1, 32)
err := frameOrig.Write(b, 32)
Expect(err).ToNot(HaveOccurred())
frame, err := ParseAckFrame(bytes.NewReader(b.Bytes()), 32)
Expect(err).ToNot(HaveOccurred())
@ -449,7 +449,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 15,
NackRanges: nackRanges,
}
err := frameOrig.Write(b, 1, 32)
err := frameOrig.Write(b, 32)
Expect(err).ToNot(HaveOccurred())
r := bytes.NewReader(b.Bytes())
frame, err := ParseAckFrame(r, 32)
@ -469,7 +469,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 1600,
NackRanges: nackRanges,
}
err := frameOrig.Write(b, 1, 32)
err := frameOrig.Write(b, 32)
Expect(err).ToNot(HaveOccurred())
r := bytes.NewReader(b.Bytes())
frame, err := ParseAckFrame(r, 32)

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -13,25 +13,32 @@ type StopWaitingFrame struct {
LeastUnacked protocol.PacketNumber
Entropy byte
PacketNumberLen protocol.PacketNumberLen
PacketNumber protocol.PacketNumber
}
var (
errLeastUnackedHigherThanPacketNumber = errors.New("StopWaitingFrame: LeastUnacked can't be greater than the packet number")
errPacketNumberNotSet = errors.New("StopWaitingFrame: PacketNumber not set")
errPacketNumberLenNotSet = errors.New("StopWaitingFrame: PacketNumberLen not set")
)
func (f *StopWaitingFrame) Write(b *bytes.Buffer, packetNumber protocol.PacketNumber, version protocol.VersionNumber) error {
func (f *StopWaitingFrame) Write(b *bytes.Buffer, version protocol.VersionNumber) error {
// packetNumber is the packet number of the packet that this StopWaitingFrame will be sent with
typeByte := uint8(0x06)
b.WriteByte(typeByte)
b.WriteByte(f.Entropy)
if f.LeastUnacked > packetNumber {
// make sure the PacketNumber was set
if f.PacketNumber == protocol.PacketNumber(0) {
return errPacketNumberNotSet
}
if f.LeastUnacked > f.PacketNumber {
return errLeastUnackedHigherThanPacketNumber
}
leastUnackedDelta := uint64(packetNumber - f.LeastUnacked)
leastUnackedDelta := uint64(f.PacketNumber - f.LeastUnacked)
switch f.PacketNumberLen {
case protocol.PacketNumberLen1:

View file

@ -29,25 +29,38 @@ var _ = Describe("StopWaitingFrame", func() {
Context("when writing", func() {
It("writes a sample frame", func() {
b := &bytes.Buffer{}
packetNumber := protocol.PacketNumber(13)
frame := &StopWaitingFrame{
LeastUnacked: 10,
PacketNumber: 13,
Entropy: 0xAD,
PacketNumberLen: protocol.PacketNumberLen6,
}
frame.Write(b, packetNumber, 0)
frame.Write(b, 0)
Expect(b.Bytes()[0]).To(Equal(uint8(0x06)))
Expect(b.Bytes()[1]).To(Equal(uint8(frame.Entropy)))
Expect(b.Bytes()[2:8]).To(Equal([]byte{3, 0, 0, 0, 0, 0}))
})
It("errors when PacketNumber was not set", func() {
b := &bytes.Buffer{}
frame := &StopWaitingFrame{
LeastUnacked: 10,
PacketNumberLen: protocol.PacketNumberLen1,
Entropy: 0xAD,
}
err := frame.Write(b, 0)
Expect(err).To(HaveOccurred())
Expect(err).To(Equal(errPacketNumberNotSet))
})
It("errors when PacketNumberLen was not set", func() {
b := &bytes.Buffer{}
frame := &StopWaitingFrame{
LeastUnacked: 10,
PacketNumber: 13,
Entropy: 0xAD,
}
err := frame.Write(b, 13, 0)
err := frame.Write(b, 0)
Expect(err).To(HaveOccurred())
Expect(err).To(Equal(errPacketNumberLenNotSet))
})
@ -56,9 +69,10 @@ var _ = Describe("StopWaitingFrame", func() {
b := &bytes.Buffer{}
frame := &StopWaitingFrame{
LeastUnacked: 10,
PacketNumber: 5,
PacketNumberLen: protocol.PacketNumberLen1,
}
err := frame.Write(b, 5, 0)
err := frame.Write(b, 0)
Expect(err).To(HaveOccurred())
Expect(err).To(Equal(errLeastUnackedHigherThanPacketNumber))
})
@ -68,9 +82,10 @@ var _ = Describe("StopWaitingFrame", func() {
b := &bytes.Buffer{}
frame := &StopWaitingFrame{
LeastUnacked: 10,
PacketNumber: 13,
PacketNumberLen: protocol.PacketNumberLen1,
}
frame.Write(b, 13, 0)
frame.Write(b, 0)
Expect(b.Len()).To(Equal(3))
Expect(b.Bytes()[2]).To(Equal(uint8(3)))
})
@ -79,9 +94,10 @@ var _ = Describe("StopWaitingFrame", func() {
b := &bytes.Buffer{}
frame := &StopWaitingFrame{
LeastUnacked: 0x10,
PacketNumber: 0x1300,
PacketNumberLen: protocol.PacketNumberLen2,
}
frame.Write(b, 0x1300, 0)
frame.Write(b, 0)
Expect(b.Len()).To(Equal(4))
Expect(b.Bytes()[2:4]).To(Equal([]byte{0xF0, 0x12}))
})
@ -90,9 +106,10 @@ var _ = Describe("StopWaitingFrame", func() {
b := &bytes.Buffer{}
frame := &StopWaitingFrame{
LeastUnacked: 0x1000,
PacketNumber: 0x12345678,
PacketNumberLen: protocol.PacketNumberLen4,
}
frame.Write(b, 0x12345678, 0)
frame.Write(b, 0)
Expect(b.Len()).To(Equal(6))
Expect(b.Bytes()[2:6]).To(Equal([]byte{0x78, 0x46, 0x34, 0x12}))
})
@ -101,9 +118,10 @@ var _ = Describe("StopWaitingFrame", func() {
b := &bytes.Buffer{}
frame := &StopWaitingFrame{
LeastUnacked: 0x10,
PacketNumber: 0x123456789ABC,
PacketNumberLen: protocol.PacketNumberLen6,
}
frame.Write(b, 0x123456789ABC, 0)
frame.Write(b, 0)
Expect(b.Len()).To(Equal(8))
Expect(b.Bytes()[2:8]).To(Equal([]byte{0xAC, 0x9A, 0x78, 0x56, 0x34, 0x12}))
})
@ -136,11 +154,12 @@ var _ = Describe("StopWaitingFrame", func() {
packetNumber := protocol.PacketNumber(13)
frame := &StopWaitingFrame{
LeastUnacked: 10,
PacketNumber: packetNumber,
Entropy: 0xAC,
PacketNumberLen: protocol.PacketNumberLen4,
}
b := &bytes.Buffer{}
frame.Write(b, packetNumber, 0)
frame.Write(b, 0)
readframe, err := ParseStopWaitingFrame(bytes.NewReader(b.Bytes()), packetNumber, protocol.PacketNumberLen4)
Expect(err).ToNot(HaveOccurred())
Expect(readframe.Entropy).To(Equal(frame.Entropy))

View file

@ -78,7 +78,7 @@ func ParseStreamFrame(r *bytes.Reader) (*StreamFrame, error) {
}
// WriteStreamFrame writes a stream frame.
func (f *StreamFrame) Write(b *bytes.Buffer, packetNumber protocol.PacketNumber, version protocol.VersionNumber) error {
func (f *StreamFrame) Write(b *bytes.Buffer, version protocol.VersionNumber) error {
typeByte := uint8(0x80) // sets the leftmost bit to 1
if f.FinBit {

View file

@ -40,7 +40,7 @@ var _ = Describe("StreamFrame", func() {
StreamID: 1,
Data: []byte("foobar"),
DataLenPresent: true,
}).Write(b, 1, 0)
}).Write(b, 0)
Expect(b.Bytes()).To(Equal([]byte{0xa0, 0x1, 0x06, 0x00, 'f', 'o', 'o', 'b', 'a', 'r'}))
})
@ -51,7 +51,7 @@ var _ = Describe("StreamFrame", func() {
Data: []byte("f"),
Offset: 0,
}
f.Write(b, 1, 0)
f.Write(b, 0)
Expect(f.MinLength()).To(Equal(protocol.ByteCount(b.Len())))
})
@ -62,7 +62,7 @@ var _ = Describe("StreamFrame", func() {
Data: []byte("f"),
Offset: 0xDEADBEEFCAFE,
}
f.Write(b, 1, 0)
f.Write(b, 0)
Expect(f.MinLength()).To(Equal(protocol.ByteCount(b.Len())))
})
@ -76,7 +76,7 @@ var _ = Describe("StreamFrame", func() {
DataLenPresent: true,
Offset: 0,
}
f.Write(b, 1, 0)
f.Write(b, 0)
minLength, _ := f.MinLength()
headerLength := minLength - 1
Expect(b.Bytes()[0] & 0x20).To(Equal(uint8(0x20)))
@ -92,7 +92,7 @@ var _ = Describe("StreamFrame", func() {
DataLenPresent: false,
Offset: 0,
}
f.Write(b, 1, 0)
f.Write(b, 0)
Expect(b.Bytes()[0] & 0x20).To(Equal(uint8(0)))
Expect(b.Bytes()[1 : b.Len()-dataLen]).ToNot(ContainSubstring(string([]byte{0x37, 0x13})))
minLength, _ := f.MinLength()
@ -121,7 +121,7 @@ var _ = Describe("StreamFrame", func() {
StreamID: 1,
Data: []byte("foobar"),
Offset: 0,
}).Write(b, 1, 0)
}).Write(b, 0)
Expect(b.Bytes()[0] & 0x1c).To(Equal(uint8(0x0)))
})
@ -131,7 +131,7 @@ var _ = Describe("StreamFrame", func() {
StreamID: 1,
Data: []byte("foobar"),
Offset: 0x1337,
}).Write(b, 1, 0)
}).Write(b, 0)
Expect(b.Bytes()[0] & 0x1c).To(Equal(uint8(0x1 << 2)))
Expect(b.Bytes()[2:4]).To(Equal([]byte{0x37, 0x13}))
})
@ -142,7 +142,7 @@ var _ = Describe("StreamFrame", func() {
StreamID: 1,
Data: []byte("foobar"),
Offset: 0x13CAFE,
}).Write(b, 1, 0)
}).Write(b, 0)
Expect(b.Bytes()[0] & 0x1c).To(Equal(uint8(0x2 << 2)))
Expect(b.Bytes()[2:5]).To(Equal([]byte{0xFE, 0xCA, 0x13}))
})
@ -153,7 +153,7 @@ var _ = Describe("StreamFrame", func() {
StreamID: 1,
Data: []byte("foobar"),
Offset: 0xDEADBEEF,
}).Write(b, 1, 0)
}).Write(b, 0)
Expect(b.Bytes()[0] & 0x1c).To(Equal(uint8(0x3 << 2)))
Expect(b.Bytes()[2:6]).To(Equal([]byte{0xEF, 0xBE, 0xAD, 0xDE}))
})
@ -164,7 +164,7 @@ var _ = Describe("StreamFrame", func() {
StreamID: 1,
Data: []byte("foobar"),
Offset: 0x13DEADBEEF,
}).Write(b, 1, 0)
}).Write(b, 0)
Expect(b.Bytes()[0] & 0x1c).To(Equal(uint8(0x4 << 2)))
Expect(b.Bytes()[2:7]).To(Equal([]byte{0xEF, 0xBE, 0xAD, 0xDE, 0x13}))
})
@ -175,7 +175,7 @@ var _ = Describe("StreamFrame", func() {
StreamID: 1,
Data: []byte("foobar"),
Offset: 0xDEADBEEFCAFE,
}).Write(b, 1, 0)
}).Write(b, 0)
Expect(b.Bytes()[0] & 0x1c).To(Equal(uint8(0x5 << 2)))
Expect(b.Bytes()[2:8]).To(Equal([]byte{0xFE, 0xCA, 0xEF, 0xBE, 0xAD, 0xDE}))
})
@ -186,7 +186,7 @@ var _ = Describe("StreamFrame", func() {
StreamID: 1,
Data: []byte("foobar"),
Offset: 0x13DEADBEEFCAFE,
}).Write(b, 1, 0)
}).Write(b, 0)
Expect(b.Bytes()[0] & 0x1c).To(Equal(uint8(0x6 << 2)))
Expect(b.Bytes()[2:9]).To(Equal([]byte{0xFE, 0xCA, 0xEF, 0xBE, 0xAD, 0xDE, 0x13}))
})
@ -197,7 +197,7 @@ var _ = Describe("StreamFrame", func() {
StreamID: 1,
Data: []byte("foobar"),
Offset: 0x1337DEADBEEFCAFE,
}).Write(b, 1, 0)
}).Write(b, 0)
Expect(b.Bytes()[0] & 0x1c).To(Equal(uint8(0x7 << 2)))
Expect(b.Bytes()[2:10]).To(Equal([]byte{0xFE, 0xCA, 0xEF, 0xBE, 0xAD, 0xDE, 0x37, 0x13}))
})
@ -210,7 +210,7 @@ var _ = Describe("StreamFrame", func() {
StreamID: 1,
streamIDLen: 13,
Data: []byte("foobar"),
}).Write(b, 1, 0)
}).Write(b, 0)
Expect(err).To(HaveOccurred())
Expect(err).To(Equal(errInvalidStreamIDLen))
})
@ -220,7 +220,7 @@ var _ = Describe("StreamFrame", func() {
(&StreamFrame{
StreamID: 13,
Data: []byte("foobar"),
}).Write(b, 1, 0)
}).Write(b, 0)
Expect(b.Bytes()[0] & 0x3).To(Equal(uint8(0x0)))
Expect(b.Bytes()[1]).To(Equal(uint8(13)))
})
@ -230,7 +230,7 @@ var _ = Describe("StreamFrame", func() {
(&StreamFrame{
StreamID: 0xCAFE,
Data: []byte("foobar"),
}).Write(b, 1, 0)
}).Write(b, 0)
Expect(b.Bytes()[0] & 0x3).To(Equal(uint8(0x1)))
Expect(b.Bytes()[1:3]).To(Equal([]byte{0xFE, 0xCA}))
})
@ -240,7 +240,7 @@ var _ = Describe("StreamFrame", func() {
(&StreamFrame{
StreamID: 0x13BEEF,
Data: []byte("foobar"),
}).Write(b, 1, 0)
}).Write(b, 0)
Expect(b.Bytes()[0] & 0x3).To(Equal(uint8(0x2)))
Expect(b.Bytes()[1:4]).To(Equal([]byte{0xEF, 0xBE, 0x13}))
})
@ -250,7 +250,7 @@ var _ = Describe("StreamFrame", func() {
(&StreamFrame{
StreamID: 0xDECAFBAD,
Data: []byte("foobar"),
}).Write(b, 1, 0)
}).Write(b, 0)
Expect(b.Bytes()[0] & 0x3).To(Equal(uint8(0x3)))
Expect(b.Bytes()[1:5]).To(Equal([]byte{0xAD, 0xFB, 0xCA, 0xDE}))
})

View file

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

View file

@ -67,6 +67,7 @@ func (p *packetPacker) PackPacket(stopWaitingFrame *frames.StopWaitingFrame, con
}
if stopWaitingFrame != nil {
stopWaitingFrame.PacketNumber = currentPacketNumber
stopWaitingFrame.PacketNumberLen = packetNumberLen
}
@ -112,7 +113,7 @@ func (p *packetPacker) getPayload(frames []frames.Frame, currentPacketNumber pro
var payload bytes.Buffer
payload.WriteByte(0) // The entropy bit is set in sendPayload
for _, frame := range frames {
frame.Write(&payload, currentPacketNumber, p.version)
frame.Write(&payload, p.version)
}
return payload.Bytes(), nil
}

View file

@ -75,7 +75,7 @@ var _ = Describe("Packet packer", func() {
Expect(err).ToNot(HaveOccurred())
Expect(p).ToNot(BeNil())
b := &bytes.Buffer{}
f.Write(b, 1, 0)
f.Write(b, 0)
Expect(len(p.frames)).To(Equal(1))
Expect(p.raw).To(ContainSubstring(string(b.Bytes())))
})
@ -127,7 +127,7 @@ var _ = Describe("Packet packer", func() {
It("packs many control frames into 1 packets", func() {
f := &frames.AckFrame{LargestObserved: 1}
b := &bytes.Buffer{}
f.Write(b, 3, 32)
f.Write(b, 32)
maxFramesPerPacket := int(protocol.MaxFrameAndPublicHeaderSize-publicHeaderLen) / b.Len()
var controlFrames []frames.Frame
for i := 0; i < maxFramesPerPacket; i++ {
@ -223,9 +223,9 @@ var _ = Describe("Packet packer", func() {
Expect(p).ToNot(BeNil())
Expect(err).ToNot(HaveOccurred())
b := &bytes.Buffer{}
f1.Write(b, 2, 0)
f2.Write(b, 2, 0)
f3.Write(b, 2, 0)
f1.Write(b, 0)
f2.Write(b, 0)
f3.Write(b, 0)
Expect(len(p.frames)).To(Equal(3))
Expect(p.frames[0].(*frames.StreamFrame).DataLenPresent).To(BeTrue())
Expect(p.frames[1].(*frames.StreamFrame).DataLenPresent).To(BeTrue())

View file

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