improve msgType lookup

This commit is contained in:
Mark Puha 2023-09-16 07:45:48 +02:00
parent 336282f299
commit df87fbfcd6

View file

@ -137,10 +137,16 @@ func (device *Device) RoutineReceiveIncoming(
packet := bufsArrs[i][:size] packet := bufsArrs[i][:size]
var msgType uint32 var msgType uint32
if device.isAdvancedSecurityOn() { if device.isAdvancedSecurityOn() {
var junkSize int if assumedMsgType, ok := packetSizeToMsgType[size]; ok {
if mapMsgType, ok := packetSizeToMsgType[size]; ok { junkSize := msgTypeToJunkSize[assumedMsgType]
junkSize = msgTypeToJunkSize[mapMsgType] // transport size can align with other header types;
msgType = mapMsgType // making sure we have the right msgType
msgType = binary.LittleEndian.Uint32(packet[junkSize:4])
if msgType == assumedMsgType {
packet = packet[junkSize:]
} else {
msgType = binary.LittleEndian.Uint32(packet[:4])
}
} else { } else {
msgType = binary.LittleEndian.Uint32(packet[:4]) msgType = binary.LittleEndian.Uint32(packet[:4])
if msgType != MessageTransportType { if msgType != MessageTransportType {
@ -148,8 +154,6 @@ func (device *Device) RoutineReceiveIncoming(
continue continue
} }
} }
// shift junk
packet = packet[junkSize:]
} else { } else {
msgType = binary.LittleEndian.Uint32(packet[:4]) msgType = binary.LittleEndian.Uint32(packet[:4])
} }