mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-10-13 22:44:02 -04:00
Update Vmess Error Warnings (#1492)
This commit is contained in:
parent
b057a37fd6
commit
ef58fde0ba
@ -16,6 +16,8 @@ var (
|
||||
ErrCommandTypeMismatch = newError("Command type mismatch.")
|
||||
ErrUnknownCommand = newError("Unknown command.")
|
||||
ErrCommandTooLarge = newError("Command too large.")
|
||||
ErrInsufficientLength = newError("Insufficient length.")
|
||||
ErrInvalidAuth = newError("Invalid auth.")
|
||||
)
|
||||
|
||||
func MarshalCommand(command interface{}, writer io.Writer) error {
|
||||
@ -54,12 +56,12 @@ func MarshalCommand(command interface{}, writer io.Writer) error {
|
||||
|
||||
func UnmarshalCommand(cmdID byte, data []byte) (protocol.ResponseCommand, error) {
|
||||
if len(data) <= 4 {
|
||||
return nil, newError("insufficient length")
|
||||
return nil, ErrInsufficientLength
|
||||
}
|
||||
expectedAuth := Authenticate(data[4:])
|
||||
actualAuth := binary.BigEndian.Uint32(data[:4])
|
||||
if expectedAuth != actualAuth {
|
||||
return nil, newError("invalid auth")
|
||||
return nil, ErrInvalidAuth
|
||||
}
|
||||
|
||||
var factory CommandFactory
|
||||
@ -109,38 +111,38 @@ func (f *CommandSwitchAccountFactory) Marshal(command interface{}, writer io.Wri
|
||||
func (f *CommandSwitchAccountFactory) Unmarshal(data []byte) (interface{}, error) {
|
||||
cmd := new(protocol.CommandSwitchAccount)
|
||||
if len(data) == 0 {
|
||||
return nil, newError("insufficient length.")
|
||||
return nil, ErrInsufficientLength
|
||||
}
|
||||
lenHost := int(data[0])
|
||||
if len(data) < lenHost+1 {
|
||||
return nil, newError("insufficient length.")
|
||||
return nil, ErrInsufficientLength
|
||||
}
|
||||
if lenHost > 0 {
|
||||
cmd.Host = net.ParseAddress(string(data[1 : 1+lenHost]))
|
||||
}
|
||||
portStart := 1 + lenHost
|
||||
if len(data) < portStart+2 {
|
||||
return nil, newError("insufficient length.")
|
||||
return nil, ErrInsufficientLength
|
||||
}
|
||||
cmd.Port = net.PortFromBytes(data[portStart : portStart+2])
|
||||
idStart := portStart + 2
|
||||
if len(data) < idStart+16 {
|
||||
return nil, newError("insufficient length.")
|
||||
return nil, ErrInsufficientLength
|
||||
}
|
||||
cmd.ID, _ = uuid.ParseBytes(data[idStart : idStart+16])
|
||||
alterIDStart := idStart + 16
|
||||
if len(data) < alterIDStart+2 {
|
||||
return nil, newError("insufficient length.")
|
||||
return nil, ErrInsufficientLength
|
||||
}
|
||||
cmd.AlterIds = binary.BigEndian.Uint16(data[alterIDStart : alterIDStart+2])
|
||||
levelStart := alterIDStart + 2
|
||||
if len(data) < levelStart+1 {
|
||||
return nil, newError("insufficient length.")
|
||||
return nil, ErrInsufficientLength
|
||||
}
|
||||
cmd.Level = uint32(data[levelStart])
|
||||
timeStart := levelStart + 1
|
||||
if len(data) < timeStart+1 {
|
||||
return nil, newError("insufficient length.")
|
||||
return nil, ErrInsufficientLength
|
||||
}
|
||||
cmd.ValidMin = data[timeStart]
|
||||
return cmd, nil
|
||||
|
Loading…
Reference in New Issue
Block a user