rename the wire.InvariantHeader to Header

This commit is contained in:
Marten Seemann 2018-11-20 17:17:43 +07:00
parent bf96707f48
commit 7b91ba56b6
8 changed files with 178 additions and 178 deletions

View file

@ -165,14 +165,14 @@ func (h *packetHandlerMap) handlePacket(addr net.Addr, data []byte) error {
rcvTime := time.Now()
r := bytes.NewReader(data)
iHdr, err := wire.ParseInvariantHeader(r, h.connIDLen)
hdr, err := wire.ParseHeader(r, h.connIDLen)
// drop the packet if we can't parse the header
if err != nil {
return fmt.Errorf("error parsing invariant header: %s", err)
return fmt.Errorf("error parsing header: %s", err)
}
h.mutex.RLock()
handlerEntry, handlerFound := h.handlers[string(iHdr.DestConnectionID)]
handlerEntry, handlerFound := h.handlers[string(hdr.DestConnectionID)]
server := h.server
var version protocol.VersionNumber
@ -183,7 +183,7 @@ func (h *packetHandlerMap) handlePacket(addr net.Addr, data []byte) error {
handlePacket = handler.handlePacket
} else { // no session found
// this might be a stateless reset
if !iHdr.IsLongHeader {
if !hdr.IsLongHeader {
if len(data) >= protocol.MinStatelessResetSize {
var token [16]byte
copy(token[:], data[len(data)-16:])
@ -194,39 +194,39 @@ func (h *packetHandlerMap) handlePacket(addr net.Addr, data []byte) error {
}
}
// TODO(#943): send a stateless reset
return fmt.Errorf("received a short header packet with an unexpected connection ID %s", iHdr.DestConnectionID)
return fmt.Errorf("received a short header packet with an unexpected connection ID %s", hdr.DestConnectionID)
}
if server == nil { // no server set
h.mutex.RUnlock()
return fmt.Errorf("received a packet with an unexpected connection ID %s", iHdr.DestConnectionID)
return fmt.Errorf("received a packet with an unexpected connection ID %s", hdr.DestConnectionID)
}
handlePacket = server.handlePacket
version = iHdr.Version
version = hdr.Version
}
h.mutex.RUnlock()
r = bytes.NewReader(data)
hdr, err := iHdr.Parse(r, version)
extHdr, err := hdr.Parse(r, version)
if err != nil {
return fmt.Errorf("error parsing header: %s", err)
return fmt.Errorf("error parsing extended header: %s", err)
}
hdr.Raw = data[:len(data)-r.Len()]
extHdr.Raw = data[:len(data)-r.Len()]
packetData := data[len(data)-r.Len():]
if hdr.IsLongHeader {
if hdr.Length < protocol.ByteCount(hdr.PacketNumberLen) {
return fmt.Errorf("packet length (%d bytes) shorter than packet number (%d bytes)", hdr.Length, hdr.PacketNumberLen)
if extHdr.IsLongHeader {
if extHdr.Length < protocol.ByteCount(extHdr.PacketNumberLen) {
return fmt.Errorf("packet length (%d bytes) shorter than packet number (%d bytes)", extHdr.Length, extHdr.PacketNumberLen)
}
if protocol.ByteCount(len(packetData))+protocol.ByteCount(hdr.PacketNumberLen) < hdr.Length {
return fmt.Errorf("packet length (%d bytes) is smaller than the expected length (%d bytes)", len(packetData)+int(hdr.PacketNumberLen), hdr.Length)
if protocol.ByteCount(len(packetData))+protocol.ByteCount(extHdr.PacketNumberLen) < extHdr.Length {
return fmt.Errorf("packet length (%d bytes) is smaller than the expected length (%d bytes)", len(packetData)+int(extHdr.PacketNumberLen), extHdr.Length)
}
packetData = packetData[:int(hdr.Length)-int(hdr.PacketNumberLen)]
packetData = packetData[:int(extHdr.Length)-int(extHdr.PacketNumberLen)]
// TODO(#1312): implement parsing of compound packets
}
handlePacket(&receivedPacket{
remoteAddr: addr,
header: hdr,
header: extHdr,
data: packetData,
rcvTime: rcvTime,
})