mirror of
https://github.com/amnezia-vpn/amneziawg-go.git
synced 2025-08-01 09:22:51 +02:00
improve msgType lookup
This commit is contained in:
parent
336282f299
commit
df87fbfcd6
1 changed files with 10 additions and 6 deletions
|
@ -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])
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue