pull/330/head
Darien Raymond 2016-12-13 11:15:11 +01:00
parent 76da31c755
commit 031b1c14b8
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 11 additions and 11 deletions

View File

@ -195,7 +195,7 @@ func (v *ClientSession) DecodeResponseHeader(reader io.Reader) (*protocol.Respon
} }
if buffer[2] != 0 { if buffer[2] != 0 {
cmdId := buffer[2] cmdID := buffer[2]
dataLen := int(buffer[3]) dataLen := int(buffer[3])
_, err := io.ReadFull(v.responseReader, buffer[:dataLen]) _, err := io.ReadFull(v.responseReader, buffer[:dataLen])
if err != nil { if err != nil {
@ -203,7 +203,7 @@ func (v *ClientSession) DecodeResponseHeader(reader io.Reader) (*protocol.Respon
return nil, err return nil, err
} }
data := buffer[:dataLen] data := buffer[:dataLen]
command, err := UnmarshalCommand(cmdId, data) command, err := UnmarshalCommand(cmdID, data)
if err == nil { if err == nil {
header.Command = command header.Command = command
} }

View File

@ -22,12 +22,12 @@ func MarshalCommand(command interface{}, writer io.Writer) error {
return ErrUnknownCommand return ErrUnknownCommand
} }
var cmdId byte var cmdID byte
var factory CommandFactory var factory CommandFactory
switch command.(type) { switch command.(type) {
case *protocol.CommandSwitchAccount: case *protocol.CommandSwitchAccount:
factory = new(CommandSwitchAccountFactory) factory = new(CommandSwitchAccountFactory)
cmdId = 1 cmdID = 1
default: default:
return ErrUnknownCommand return ErrUnknownCommand
} }
@ -46,12 +46,12 @@ func MarshalCommand(command interface{}, writer io.Writer) error {
return ErrCommandTooLarge return ErrCommandTooLarge
} }
writer.Write([]byte{cmdId, byte(len), byte(auth >> 24), byte(auth >> 16), byte(auth >> 8), byte(auth)}) writer.Write([]byte{cmdID, byte(len), byte(auth >> 24), byte(auth >> 16), byte(auth >> 8), byte(auth)})
writer.Write(buffer.Bytes()) writer.Write(buffer.Bytes())
return nil return nil
} }
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, errors.New("VMess|Command: Insufficient length.") return nil, errors.New("VMess|Command: Insufficient length.")
} }
@ -62,7 +62,7 @@ func UnmarshalCommand(cmdId byte, data []byte) (protocol.ResponseCommand, error)
} }
var factory CommandFactory var factory CommandFactory
switch cmdId { switch cmdID {
case 1: case 1:
factory = new(CommandSwitchAccountFactory) factory = new(CommandSwitchAccountFactory)
default: default:
@ -129,12 +129,12 @@ func (v *CommandSwitchAccountFactory) Unmarshal(data []byte) (interface{}, error
return nil, errors.New("VMess|SwitchAccountCommand: Insufficient length.") return nil, errors.New("VMess|SwitchAccountCommand: Insufficient length.")
} }
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, errors.New("VMess|SwitchAccountCommand: Insufficient length.") return nil, errors.New("VMess|SwitchAccountCommand: Insufficient length.")
} }
cmd.AlterIds = serial.BytesToUint16(data[alterIdStart : alterIdStart+2]) cmd.AlterIds = serial.BytesToUint16(data[alterIDStart : alterIDStart+2])
levelStart := alterIdStart + 2 levelStart := alterIDStart + 2
if len(data) < levelStart+1 { if len(data) < levelStart+1 {
return nil, errors.New("VMess|SwitchAccountCommand: Insufficient length.") return nil, errors.New("VMess|SwitchAccountCommand: Insufficient length.")
} }