make PublicHeader public

This commit is contained in:
Marten Seemann 2016-08-04 15:45:11 +07:00
parent 471c5d5a33
commit 8b845fada9
9 changed files with 41 additions and 41 deletions

View file

@ -61,7 +61,7 @@ func (p *packetPacker) packPacket(stopWaitingFrame *frames.StopWaitingFrame, con
defer p.cryptoSetup.UnlockForSealing()
packetNumberLen := protocol.GetPacketNumberLengthForPublicHeader(currentPacketNumber, largestObserved)
responsePublicHeader := &publicHeader{
responsePublicHeader := &PublicHeader{
ConnectionID: p.connectionID,
PacketNumber: currentPacketNumber,
PacketNumberLen: packetNumberLen,

View file

@ -21,7 +21,7 @@ type packetUnpacker struct {
aead crypto.AEAD
}
func (u *packetUnpacker) Unpack(publicHeaderBinary []byte, hdr *publicHeader, data []byte) (*unpackedPacket, error) {
func (u *packetUnpacker) Unpack(publicHeaderBinary []byte, hdr *PublicHeader, data []byte) (*unpackedPacket, error) {
data, err := u.aead.Open(data[:0], data, hdr.PacketNumber, publicHeaderBinary)
if err != nil {
// Wrap err in quicError so that public reset is sent by session

View file

@ -15,7 +15,7 @@ import (
var _ = Describe("Packet unpacker", func() {
var (
unpacker *packetUnpacker
hdr *publicHeader
hdr *PublicHeader
hdrBin []byte
aead crypto.AEAD
data []byte
@ -24,7 +24,7 @@ var _ = Describe("Packet unpacker", func() {
BeforeEach(func() {
aead = &crypto.NullAEAD{}
hdr = &publicHeader{
hdr = &PublicHeader{
PacketNumber: 10,
PacketNumberLen: 1,
}

View file

@ -18,8 +18,8 @@ var (
errGetLengthOnlyForRegularPackets = errors.New("PublicHeader: GetLength can only be called for regular packets")
)
// The publicHeader of a QUIC packet
type publicHeader struct {
// The PublicHeader of a QUIC packet
type PublicHeader struct {
Raw []byte
VersionFlag bool
ResetFlag bool
@ -32,7 +32,7 @@ type publicHeader struct {
}
// WritePublicHeader writes a public header
func (h *publicHeader) WritePublicHeader(b *bytes.Buffer, version protocol.VersionNumber) error {
func (h *PublicHeader) WritePublicHeader(b *bytes.Buffer, version protocol.VersionNumber) error {
publicFlagByte := uint8(0x00)
if h.VersionFlag && h.ResetFlag {
return errResetAndVersionFlagSet
@ -99,8 +99,8 @@ func (h *publicHeader) WritePublicHeader(b *bytes.Buffer, version protocol.Versi
}
// parsePublicHeader parses a QUIC packet's public header
func parsePublicHeader(b io.ByteReader) (*publicHeader, error) {
header := &publicHeader{}
func parsePublicHeader(b io.ByteReader) (*PublicHeader, error) {
header := &PublicHeader{}
// First byte
publicFlagByte, err := b.ReadByte()
@ -162,7 +162,7 @@ func parsePublicHeader(b io.ByteReader) (*publicHeader, error) {
// GetLength gets the length of the publicHeader in bytes
// can only be called for regular packets
func (h *publicHeader) GetLength() (protocol.ByteCount, error) {
func (h *PublicHeader) GetLength() (protocol.ByteCount, error) {
if h.VersionFlag || h.ResetFlag {
return 0, errGetLengthOnlyForRegularPackets
}

View file

@ -79,7 +79,7 @@ var _ = Describe("Public Header", func() {
Context("when writing", func() {
It("writes a sample header", func() {
b := &bytes.Buffer{}
hdr := publicHeader{
hdr := PublicHeader{
ConnectionID: 0x4cfa9f9b668619f6,
PacketNumber: 2,
PacketNumberLen: protocol.PacketNumberLen6,
@ -90,7 +90,7 @@ var _ = Describe("Public Header", func() {
It("sets the Version Flag", func() {
b := &bytes.Buffer{}
hdr := publicHeader{
hdr := PublicHeader{
VersionFlag: true,
ConnectionID: 0x4cfa9f9b668619f6,
PacketNumber: 2,
@ -105,7 +105,7 @@ var _ = Describe("Public Header", func() {
It("sets the Reset Flag", func() {
b := &bytes.Buffer{}
hdr := publicHeader{
hdr := PublicHeader{
ResetFlag: true,
ConnectionID: 0x4cfa9f9b668619f6,
PacketNumber: 2,
@ -120,7 +120,7 @@ var _ = Describe("Public Header", func() {
It("throws an error if both Reset Flag and Version Flag are set", func() {
b := &bytes.Buffer{}
hdr := publicHeader{
hdr := PublicHeader{
VersionFlag: true,
ResetFlag: true,
ConnectionID: 0x4cfa9f9b668619f6,
@ -133,7 +133,7 @@ var _ = Describe("Public Header", func() {
It("truncates the connection ID", func() {
b := &bytes.Buffer{}
hdr := publicHeader{
hdr := PublicHeader{
ConnectionID: 0x4cfa9f9b668619f6,
TruncateConnectionID: true,
PacketNumberLen: protocol.PacketNumberLen6,
@ -146,7 +146,7 @@ var _ = Describe("Public Header", func() {
It("writes proper v33 packets", func() {
b := &bytes.Buffer{}
hdr := publicHeader{
hdr := PublicHeader{
ConnectionID: 0x4cfa9f9b668619f6,
PacketNumber: 1,
PacketNumberLen: protocol.PacketNumberLen1,
@ -158,7 +158,7 @@ var _ = Describe("Public Header", func() {
It("writes diversification nonces", func() {
b := &bytes.Buffer{}
hdr := publicHeader{
hdr := PublicHeader{
ConnectionID: 0x4cfa9f9b668619f6,
PacketNumber: 1,
PacketNumberLen: protocol.PacketNumberLen1,
@ -175,19 +175,19 @@ var _ = Describe("Public Header", func() {
Context("GetLength", func() {
It("errors when calling GetLength for Version Negotiation packets", func() {
hdr := publicHeader{VersionFlag: true}
hdr := PublicHeader{VersionFlag: true}
_, err := hdr.GetLength()
Expect(err).To(MatchError(errGetLengthOnlyForRegularPackets))
})
It("errors when calling GetLength for Public Reset packets", func() {
hdr := publicHeader{ResetFlag: true}
hdr := PublicHeader{ResetFlag: true}
_, err := hdr.GetLength()
Expect(err).To(MatchError(errGetLengthOnlyForRegularPackets))
})
It("errors when PacketNumberLen is not set", func() {
hdr := publicHeader{
hdr := PublicHeader{
ConnectionID: 0x4cfa9f9b668619f6,
PacketNumber: 0xDECAFBAD,
}
@ -196,7 +196,7 @@ var _ = Describe("Public Header", func() {
})
It("gets the length of a packet with longest packet number length and connectionID", func() {
hdr := publicHeader{
hdr := PublicHeader{
ConnectionID: 0x4cfa9f9b668619f6,
PacketNumber: 0xDECAFBAD,
PacketNumberLen: protocol.PacketNumberLen6,
@ -207,7 +207,7 @@ var _ = Describe("Public Header", func() {
})
It("gets the length of a packet with longest packet number length and truncated connectionID", func() {
hdr := publicHeader{
hdr := PublicHeader{
ConnectionID: 0x4cfa9f9b668619f6,
TruncateConnectionID: true,
PacketNumber: 0xDECAFBAD,
@ -219,7 +219,7 @@ var _ = Describe("Public Header", func() {
})
It("gets the length of a packet 2 byte packet number length ", func() {
hdr := publicHeader{
hdr := PublicHeader{
ConnectionID: 0x4cfa9f9b668619f6,
PacketNumber: 0xDECAFBAD,
PacketNumberLen: protocol.PacketNumberLen2,
@ -230,7 +230,7 @@ var _ = Describe("Public Header", func() {
})
It("works with diversification nonce", func() {
hdr := publicHeader{
hdr := PublicHeader{
DiversificationNonce: []byte("foo"),
PacketNumberLen: protocol.PacketNumberLen1,
}
@ -243,7 +243,7 @@ var _ = Describe("Public Header", func() {
Context("packet number length", func() {
It("doesn't write a header if the packet number length is not set", func() {
b := &bytes.Buffer{}
hdr := publicHeader{
hdr := PublicHeader{
ConnectionID: 0x4cfa9f9b668619f6,
PacketNumber: 0xDECAFBAD,
}
@ -253,7 +253,7 @@ var _ = Describe("Public Header", func() {
It("writes a header with a 1-byte packet number", func() {
b := &bytes.Buffer{}
hdr := publicHeader{
hdr := PublicHeader{
ConnectionID: 0x4cfa9f9b668619f6,
PacketNumber: 0xDECAFBAD,
PacketNumberLen: protocol.PacketNumberLen1,
@ -265,7 +265,7 @@ var _ = Describe("Public Header", func() {
It("writes a header with a 2-byte packet number", func() {
b := &bytes.Buffer{}
hdr := publicHeader{
hdr := PublicHeader{
ConnectionID: 0x4cfa9f9b668619f6,
PacketNumber: 0xDECAFBAD,
PacketNumberLen: protocol.PacketNumberLen2,
@ -277,7 +277,7 @@ var _ = Describe("Public Header", func() {
It("writes a header with a 4-byte packet number", func() {
b := &bytes.Buffer{}
hdr := publicHeader{
hdr := PublicHeader{
ConnectionID: 0x4cfa9f9b668619f6,
PacketNumber: 0x13DECAFBAD,
PacketNumberLen: protocol.PacketNumberLen4,
@ -289,7 +289,7 @@ var _ = Describe("Public Header", func() {
It("writes a header with a 6-byte packet number", func() {
b := &bytes.Buffer{}
hdr := publicHeader{
hdr := PublicHeader{
ConnectionID: 0x4cfa9f9b668619f6,
PacketNumber: 0xBE1337DECAFBAD,
PacketNumberLen: protocol.PacketNumberLen6,

View file

@ -16,7 +16,7 @@ import (
// packetHandler handles packets
type packetHandler interface {
handlePacket(addr interface{}, hdr *publicHeader, data []byte)
handlePacket(addr interface{}, hdr *PublicHeader, data []byte)
run()
Close(error) error
}
@ -183,7 +183,7 @@ func (s *Server) closeCallback(id protocol.ConnectionID) {
func composeVersionNegotiation(connectionID protocol.ConnectionID) []byte {
fullReply := &bytes.Buffer{}
responsePublicHeader := publicHeader{
responsePublicHeader := PublicHeader{
ConnectionID: connectionID,
PacketNumber: 1,
VersionFlag: true,

View file

@ -20,7 +20,7 @@ type mockSession struct {
closed bool
}
func (s *mockSession) handlePacket(addr interface{}, hdr *publicHeader, data []byte) {
func (s *mockSession) handlePacket(addr interface{}, hdr *PublicHeader, data []byte) {
s.packetCount++
}

View file

@ -18,12 +18,12 @@ import (
)
type unpacker interface {
Unpack(publicHeaderBinary []byte, hdr *publicHeader, data []byte) (*unpackedPacket, error)
Unpack(publicHeaderBinary []byte, hdr *PublicHeader, data []byte) (*unpackedPacket, error)
}
type receivedPacket struct {
remoteAddr interface{}
publicHeader *publicHeader
publicHeader *PublicHeader
data []byte
}
@ -234,7 +234,7 @@ func (s *Session) maybeResetTimer() {
s.currentDeadline = nextDeadline
}
func (s *Session) handlePacketImpl(remoteAddr interface{}, hdr *publicHeader, data []byte) error {
func (s *Session) handlePacketImpl(remoteAddr interface{}, hdr *PublicHeader, data []byte) error {
s.lastNetworkActivityTime = time.Now()
// Calculate packet number
@ -319,7 +319,7 @@ func (s *Session) handleFrames(fs []frames.Frame) error {
}
// handlePacket handles a packet
func (s *Session) handlePacket(remoteAddr interface{}, hdr *publicHeader, data []byte) {
func (s *Session) handlePacket(remoteAddr interface{}, hdr *PublicHeader, data []byte) {
// Discard packets once the amount of queued packets is larger than
// the channel size, protocol.MaxSessionUnprocessedPackets
select {

View file

@ -39,7 +39,7 @@ func (*mockConnection) IP() net.IP { return nil }
type mockUnpacker struct{}
func (m *mockUnpacker) Unpack(publicHeaderBinary []byte, hdr *publicHeader, data []byte) (*unpackedPacket, error) {
func (m *mockUnpacker) Unpack(publicHeaderBinary []byte, hdr *PublicHeader, data []byte) (*unpackedPacket, error) {
return &unpackedPacket{
entropyBit: false,
frames: nil,
@ -439,11 +439,11 @@ var _ = Describe("Session", func() {
})
Context("receiving packets", func() {
var hdr *publicHeader
var hdr *PublicHeader
BeforeEach(func() {
session.unpacker = &mockUnpacker{}
hdr = &publicHeader{PacketNumberLen: protocol.PacketNumberLen6}
hdr = &PublicHeader{PacketNumberLen: protocol.PacketNumberLen6}
})
It("sets the lastRcvdPacketNumber", func() {
@ -662,7 +662,7 @@ var _ = Describe("Session", func() {
It("sends public reset after too many undecryptable packets", func() {
// Write protocol.MaxUndecryptablePackets and expect a public reset to happen
for i := 0; i < protocol.MaxUndecryptablePackets; i++ {
hdr := &publicHeader{
hdr := &PublicHeader{
PacketNumber: protocol.PacketNumber(i + 1),
}
session.handlePacket(nil, hdr, []byte("foobar"))
@ -676,7 +676,7 @@ var _ = Describe("Session", func() {
It("unqueues undecryptable packets for later decryption", func() {
session.undecryptablePackets = []receivedPacket{{
nil,
&publicHeader{PacketNumber: protocol.PacketNumber(42)},
&PublicHeader{PacketNumber: protocol.PacketNumber(42)},
nil,
}}
Expect(session.receivedPackets).NotTo(Receive())