mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-22 20:59:19 +02:00
Update Vmess Warning Errors
This commit is contained in:
parent
b4cdb6075b
commit
e96e5994d0
|
@ -13,9 +13,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrCommandTypeMismatch = newError("Command type mismatch.")
|
|
||||||
ErrUnknownCommand = newError("Unknown command.")
|
|
||||||
ErrCommandTooLarge = newError("Command too large.")
|
ErrCommandTooLarge = newError("Command too large.")
|
||||||
|
ErrCommandTypeMismatch = newError("Command type mismatch.")
|
||||||
|
ErrInvalidAuth = newError("Invalid auth.")
|
||||||
|
ErrInsufficientLength = newError("Insufficient length.")
|
||||||
|
ErrUnknownCommand = newError("Unknown command.")
|
||||||
)
|
)
|
||||||
|
|
||||||
func MarshalCommand(command interface{}, writer io.Writer) error {
|
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) {
|
func UnmarshalCommand(cmdID byte, data []byte) (protocol.ResponseCommand, error) {
|
||||||
if len(data) <= 4 {
|
if len(data) <= 4 {
|
||||||
return nil, newError("insufficient length")
|
return nil, ErrInsufficientLength
|
||||||
}
|
}
|
||||||
expectedAuth := Authenticate(data[4:])
|
expectedAuth := Authenticate(data[4:])
|
||||||
actualAuth := binary.BigEndian.Uint32(data[:4])
|
actualAuth := binary.BigEndian.Uint32(data[:4])
|
||||||
if expectedAuth != actualAuth {
|
if expectedAuth != actualAuth {
|
||||||
return nil, newError("invalid auth")
|
return nil, ErrInvalidAuth
|
||||||
}
|
}
|
||||||
|
|
||||||
var factory CommandFactory
|
var factory CommandFactory
|
||||||
|
@ -109,38 +111,38 @@ func (f *CommandSwitchAccountFactory) Marshal(command interface{}, writer io.Wri
|
||||||
func (f *CommandSwitchAccountFactory) Unmarshal(data []byte) (interface{}, error) {
|
func (f *CommandSwitchAccountFactory) Unmarshal(data []byte) (interface{}, error) {
|
||||||
cmd := new(protocol.CommandSwitchAccount)
|
cmd := new(protocol.CommandSwitchAccount)
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
return nil, newError("insufficient length.")
|
return nil, ErrInsufficientLength
|
||||||
}
|
}
|
||||||
lenHost := int(data[0])
|
lenHost := int(data[0])
|
||||||
if len(data) < lenHost+1 {
|
if len(data) < lenHost+1 {
|
||||||
return nil, newError("insufficient length.")
|
return nil, ErrInsufficientLength
|
||||||
}
|
}
|
||||||
if lenHost > 0 {
|
if lenHost > 0 {
|
||||||
cmd.Host = net.ParseAddress(string(data[1 : 1+lenHost]))
|
cmd.Host = net.ParseAddress(string(data[1 : 1+lenHost]))
|
||||||
}
|
}
|
||||||
portStart := 1 + lenHost
|
portStart := 1 + lenHost
|
||||||
if len(data) < portStart+2 {
|
if len(data) < portStart+2 {
|
||||||
return nil, newError("insufficient length.")
|
return nil, ErrInsufficientLength
|
||||||
}
|
}
|
||||||
cmd.Port = net.PortFromBytes(data[portStart : portStart+2])
|
cmd.Port = net.PortFromBytes(data[portStart : portStart+2])
|
||||||
idStart := portStart + 2
|
idStart := portStart + 2
|
||||||
if len(data) < idStart+16 {
|
if len(data) < idStart+16 {
|
||||||
return nil, newError("insufficient length.")
|
return nil, ErrInsufficientLength
|
||||||
}
|
}
|
||||||
cmd.ID, _ = uuid.ParseBytes(data[idStart : idStart+16])
|
cmd.ID, _ = uuid.ParseBytes(data[idStart : idStart+16])
|
||||||
alterIDStart := idStart + 16
|
alterIDStart := idStart + 16
|
||||||
if len(data) < alterIDStart+2 {
|
if len(data) < alterIDStart+2 {
|
||||||
return nil, newError("insufficient length.")
|
return nil, ErrInsufficientLength
|
||||||
}
|
}
|
||||||
cmd.AlterIds = binary.BigEndian.Uint16(data[alterIDStart : alterIDStart+2])
|
cmd.AlterIds = binary.BigEndian.Uint16(data[alterIDStart : alterIDStart+2])
|
||||||
levelStart := alterIDStart + 2
|
levelStart := alterIDStart + 2
|
||||||
if len(data) < levelStart+1 {
|
if len(data) < levelStart+1 {
|
||||||
return nil, newError("insufficient length.")
|
return nil, ErrInsufficientLength
|
||||||
}
|
}
|
||||||
cmd.Level = uint32(data[levelStart])
|
cmd.Level = uint32(data[levelStart])
|
||||||
timeStart := levelStart + 1
|
timeStart := levelStart + 1
|
||||||
if len(data) < timeStart+1 {
|
if len(data) < timeStart+1 {
|
||||||
return nil, newError("insufficient length.")
|
return nil, ErrInsufficientLength
|
||||||
}
|
}
|
||||||
cmd.ValidMin = data[timeStart]
|
cmd.ValidMin = data[timeStart]
|
||||||
return cmd, nil
|
return cmd, nil
|
||||||
|
|
Loading…
Reference in New Issue