implement packing of packets for gQUIC 44

This commit is contained in:
Marten Seemann
2018-08-26 21:23:59 +07:00
parent 73a1a0e509
commit 01100c56df
2 changed files with 54 additions and 6 deletions

View File

@@ -457,11 +457,15 @@ func (p *packetPacker) getHeader(encLevel protocol.EncryptionLevel) *wire.Header
header := &wire.Header{
PacketNumber: pnum,
PacketNumberLen: packetNumberLen,
Version: p.version,
}
if p.version.UsesTLS() && encLevel != protocol.EncryptionForwardSecure {
if p.version.UsesIETFHeaderFormat() && encLevel != protocol.EncryptionForwardSecure {
header.IsLongHeader = true
header.SrcConnectionID = p.srcConnID
if !p.version.UsesVarintPacketNumbers() {
header.PacketNumberLen = protocol.PacketNumberLen4
}
// Set the payload len to maximum size.
// Since it is encoded as a varint, this guarantees us that the header will end up at most as big as GetLength() returns.
header.PayloadLen = p.maxPacketSize
@@ -478,15 +482,11 @@ func (p *packetPacker) getHeader(encLevel protocol.EncryptionLevel) *wire.Header
}
if !p.version.UsesTLS() {
if p.perspective == protocol.PerspectiveServer && encLevel == protocol.EncryptionSecure {
header.Type = protocol.PacketType0RTT
header.DiversificationNonce = p.divNonce
}
if p.perspective == protocol.PerspectiveClient && encLevel != protocol.EncryptionForwardSecure {
header.VersionFlag = true
header.Version = p.version
}
} else {
if encLevel != protocol.EncryptionForwardSecure {
header.Version = p.version
}
}
return header

View File

@@ -103,6 +103,7 @@ var _ = Describe("Packet packer", func() {
Context("determining the maximum packet size", func() {
connID := protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8}
It("uses the minimum initial size, if it can't determine if the remote address is IPv4 or IPv6", func() {
remoteAddr := &net.TCPAddr{}
packer = newPacketPacker(connID, connID, 1, nil, remoteAddr, nil, nil, nil, nil, protocol.PerspectiveServer, protocol.VersionWhatever)
@@ -176,6 +177,7 @@ var _ = Describe("Packet packer", func() {
})
It("it omits the connection ID for forward-secure packets", func() {
packer.version = protocol.Version43
ph := packer.getHeader(protocol.EncryptionForwardSecure)
Expect(ph.DestConnectionID.Len()).ToNot(BeZero())
packer.SetOmitConnectionID()
@@ -225,6 +227,52 @@ var _ = Describe("Packet packer", func() {
})
})
Context("Header (for gQUIC 44)", func() {
BeforeEach(func() {
packer.version = protocol.Version44
})
It("sends an Initial packet as the first packets, for the client", func() {
packer.perspective = protocol.PerspectiveClient
packer.hasSentPacket = false
h := packer.getHeader(protocol.EncryptionUnencrypted)
Expect(h.IsLongHeader).To(BeTrue())
Expect(h.Type).To(Equal(protocol.PacketTypeInitial))
Expect(h.Version).To(Equal(protocol.Version44))
Expect(h.DestConnectionID).To(Equal(packer.destConnID))
Expect(h.SrcConnectionID).To(Equal(packer.srcConnID))
Expect(h.PacketNumberLen).To(Equal(protocol.PacketNumberLen4))
})
It("sends a Handshake for non-forward-secure packets, for the server", func() {
packer.perspective = protocol.PerspectiveServer
h := packer.getHeader(protocol.EncryptionUnencrypted)
Expect(h.IsLongHeader).To(BeTrue())
Expect(h.Type).To(Equal(protocol.PacketTypeHandshake))
Expect(h.Version).To(Equal(protocol.Version44))
Expect(h.DestConnectionID).To(Equal(packer.destConnID))
Expect(h.SrcConnectionID).To(Equal(packer.srcConnID))
Expect(h.PacketNumberLen).To(Equal(protocol.PacketNumberLen4))
})
It("sets the Diversification Nonce for secure packets", func() {
packer.perspective = protocol.PerspectiveServer
Expect(divNonce).ToNot(BeEmpty())
h := packer.getHeader(protocol.EncryptionSecure)
Expect(h.IsLongHeader).To(BeTrue())
Expect(h.Version).To(Equal(protocol.Version44))
Expect(h.Type).To(Equal(protocol.PacketType0RTT))
Expect(h.DiversificationNonce).To(Equal(divNonce))
})
It("uses the Short Header for forward-secure packets", func() {
h := packer.getHeader(protocol.EncryptionForwardSecure)
Expect(h.IsLongHeader).To(BeFalse())
Expect(h.IsPublicHeader).To(BeFalse())
Expect(h.DestConnectionID).To(Equal(packer.destConnID))
})
})
Context("Header (for IETF draft QUIC)", func() {
BeforeEach(func() {
packer.version = versionIETFHeader