slightly simplify public reset writing

This commit is contained in:
Lucas Clemente 2016-05-17 17:02:42 +02:00
parent 1ef224d9bf
commit 8451fcf39b
3 changed files with 8 additions and 28 deletions

View file

@ -8,21 +8,17 @@ import (
"github.com/lucas-clemente/quic-go/utils"
)
type publicResetPacket struct {
connectionID protocol.ConnectionID
rejectedPacketNumber protocol.PacketNumber
nonceProof uint64
}
func (p *publicResetPacket) Write(b *bytes.Buffer) {
func writePublicReset(connectionID protocol.ConnectionID, rejectedPacketNumber protocol.PacketNumber, nonceProof uint64) []byte {
b := &bytes.Buffer{}
b.WriteByte(0x0a)
utils.WriteUint64(b, uint64(p.connectionID))
utils.WriteUint64(b, uint64(connectionID))
utils.WriteUint32(b, uint32(handshake.TagPRST))
utils.WriteUint32(b, 2)
utils.WriteUint32(b, uint32(handshake.TagRNON))
utils.WriteUint32(b, 8)
utils.WriteUint32(b, uint32(handshake.TagRSEQ))
utils.WriteUint32(b, 16)
utils.WriteUint64(b, p.nonceProof)
utils.WriteUint64(b, uint64(p.rejectedPacketNumber))
utils.WriteUint64(b, nonceProof)
utils.WriteUint64(b, uint64(rejectedPacketNumber))
return b.Bytes()
}

View file

@ -1,8 +1,6 @@
package quic
import (
"bytes"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
@ -10,14 +8,7 @@ import (
var _ = Describe("public reset", func() {
Context("writing", func() {
It("writes public reset packets", func() {
packet := &publicResetPacket{
connectionID: 0xdeadbeef,
rejectedPacketNumber: 0x8badf00d,
nonceProof: 0xdecafbad,
}
b := &bytes.Buffer{}
packet.Write(b)
Expect(b.Bytes()).To(Equal([]byte{
Expect(writePublicReset(0xdeadbeef, 0x8badf00d, 0xdecafbad)).To(Equal([]byte{
0x0a,
0xef, 0xbe, 0xad, 0xde, 0x00, 0x00, 0x00, 0x00,
'P', 'R', 'S', 'T',

View file

@ -607,14 +607,7 @@ func (s *Session) garbageCollectStreams() {
func (s *Session) sendPublicReset(rejectedPacketNumber protocol.PacketNumber) error {
utils.Infof("Sending public reset for connection %x, packet number %d", s.connectionID, rejectedPacketNumber)
packet := &publicResetPacket{
connectionID: s.connectionID,
rejectedPacketNumber: rejectedPacketNumber,
nonceProof: 0, // TODO: Currently ignored by chrome.
}
var b bytes.Buffer
packet.Write(&b)
return s.conn.write(b.Bytes())
return s.conn.write(writePublicReset(s.connectionID, rejectedPacketNumber, 0))
}
// scheduleSending signals that we have data for sending