implement writing and parsing of Initial packets containing a Token

This commit is contained in:
Marten Seemann 2018-07-14 22:34:52 +02:00
parent 2b3ae10b33
commit e39251c8b5
4 changed files with 136 additions and 3 deletions

View file

@ -123,6 +123,21 @@ func (iv *InvariantHeader) parseVersionNegotiationPacket(b *bytes.Reader) (*Head
func (iv *InvariantHeader) parseLongHeader(b *bytes.Reader) (*Header, error) {
h := iv.toHeader()
h.Type = protocol.PacketType(iv.typeByte & 0x7f)
if h.Type == protocol.PacketTypeInitial {
tokenLen, err := utils.ReadVarInt(b)
if err != nil {
return nil, err
}
if tokenLen > uint64(b.Len()) {
return nil, io.EOF
}
h.Token = make([]byte, tokenLen)
if _, err := io.ReadFull(b, h.Token); err != nil {
return nil, err
}
}
pl, err := utils.ReadVarInt(b)
if err != nil {
@ -135,7 +150,6 @@ func (iv *InvariantHeader) parseLongHeader(b *bytes.Reader) (*Header, error) {
}
h.PacketNumber = pn
h.PacketNumberLen = pnLen
h.Type = protocol.PacketType(iv.typeByte & 0x7f)
if h.Type != protocol.PacketTypeInitial && h.Type != protocol.PacketTypeRetry && h.Type != protocol.PacketType0RTT && h.Type != protocol.PacketTypeHandshake {
return nil, qerr.Error(qerr.InvalidPacketHeader, fmt.Sprintf("Received packet with invalid packet type: %d", h.Type))