handle the packet length before parsing the extended header

This commit is contained in:
Marten Seemann 2018-12-12 13:06:16 +06:30
parent aaea375fb6
commit 03489f56a7
5 changed files with 20 additions and 31 deletions

View file

@ -24,8 +24,8 @@ type Header struct {
SupportedVersions []protocol.VersionNumber // sent in a Version Negotiation Packet
OrigDestConnectionID protocol.ConnectionID // sent in the Retry packet
typeByte byte
len int // how many bytes were read while parsing this header
typeByte byte
parsedLen protocol.ByteCount // how many bytes were read while parsing this header
}
// ParseHeader parses the header.
@ -39,7 +39,7 @@ func ParseHeader(b *bytes.Reader, shortHeaderConnIDLen int) (*Header, error) {
if err != nil {
return nil, err
}
h.len = startLen - b.Len()
h.parsedLen = protocol.ByteCount(startLen - b.Len())
return h, nil
}
@ -171,6 +171,11 @@ func (h *Header) IsVersionNegotiation() bool {
return h.IsLongHeader && h.Version == 0
}
// ParsedLen returns the number of bytes that were consumed when parsing the header
func (h *Header) ParsedLen() protocol.ByteCount {
return h.parsedLen
}
// ParseExtended parses the version dependent part of the header.
// The Reader has to be set such that it points to the first byte of the header.
func (h *Header) ParseExtended(b *bytes.Reader, ver protocol.VersionNumber) (*ExtendedHeader, error) {