implement public reset packet writing

This commit is contained in:
Lucas Clemente
2016-04-29 16:12:17 +02:00
parent a38735f8fc
commit 1e8d1453a8
3 changed files with 69 additions and 0 deletions

View File

@@ -71,4 +71,11 @@ const (
// TagSHLO is the server hello
TagSHLO Tag = 'S' + 'H'<<8 + 'L'<<16 + 'O'<<24
// TagPRST is the public reset tag
TagPRST Tag = 'P' + 'R'<<8 + 'S'<<16 + 'T'<<24
// TagRSEQ is the public reset rejected packet number
TagRSEQ Tag = 'R' + 'S'<<8 + 'E'<<16 + 'Q'<<24
// TagRNON is the public reset nonce
TagRNON Tag = 'R' + 'N'<<8 + 'O'<<16 + 'N'<<24
)

28
public_reset.go Normal file
View File

@@ -0,0 +1,28 @@
package quic
import (
"bytes"
"github.com/lucas-clemente/quic-go/handshake"
"github.com/lucas-clemente/quic-go/protocol"
"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) {
b.WriteByte(0x0a)
utils.WriteUint64(b, uint64(p.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))
}

34
public_reset_test.go Normal file
View File

@@ -0,0 +1,34 @@
package quic
import (
"bytes"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
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{
0x0a,
0xef, 0xbe, 0xad, 0xde, 0x00, 0x00, 0x00, 0x00,
'P', 'R', 'S', 'T',
0x02, 0x00, 0x00, 0x00,
'R', 'N', 'O', 'N',
0x08, 0x00, 0x00, 0x00,
'R', 'S', 'E', 'Q',
0x10, 0x00, 0x00, 0x00,
0xad, 0xfb, 0xca, 0xde, 0x0, 0x0, 0x0, 0x0,
0x0d, 0xf0, 0xad, 0x8b, 0x0, 0x0, 0x0, 0x0,
}))
})
})
})