rename Error to Err

This commit is contained in:
v2ray committed 2016-06-27 08:53:35 +02:00
1 parent 5ee87404fd
commit 7f661f5215
41 files changed
+118 -118

No files matched your search

+1 -1
View File
@@ -114,7 +114,7 @@ func (this *ClientSession) DecodeResponseHeader(reader io.Reader) (*protocol.Res
if buffer.Value[0] != this.responseHeader {
log.Info("Raw: Unexpected response header. Expecting ", this.responseHeader, " but actually ", buffer.Value[0])
return nil, transport.ErrorCorruptedPacket
return nil, transport.ErrCorruptedPacket
}
header := &protocol.ResponseHeader{
+17 -17
View File
@@ -13,14 +13,14 @@ import (
)
var (
ErrorCommandTypeMismatch = errors.New("Command type mismatch.")
ErrorUnknownCommand = errors.New("Unknown command.")
ErrorCommandTooLarge = errors.New("Command too large.")
ErrCommandTypeMismatch = errors.New("Command type mismatch.")
ErrUnknownCommand = errors.New("Unknown command.")
ErrCommandTooLarge = errors.New("Command too large.")
)
func MarshalCommand(command interface{}, writer io.Writer) error {
if command == nil {
return ErrorUnknownCommand
return ErrUnknownCommand
}
var cmdId byte
@@ -30,7 +30,7 @@ func MarshalCommand(command interface{}, writer io.Writer) error {
factory = new(CommandSwitchAccountFactory)
cmdId = 1
default:
return ErrorUnknownCommand
return ErrUnknownCommand
}
buffer := alloc.NewSmallBuffer().Clear()
@@ -42,7 +42,7 @@ func MarshalCommand(command interface{}, writer io.Writer) error {
auth := Authenticate(buffer.Value)
len := buffer.Len() + 4
if len > 255 {
return ErrorCommandTooLarge
return ErrCommandTooLarge
}
writer.Write([]byte{cmdId, byte(len), byte(auth >> 24), byte(auth >> 16), byte(auth >> 8), byte(auth)})
@@ -52,12 +52,12 @@ func MarshalCommand(command interface{}, writer io.Writer) error {
func UnmarshalCommand(cmdId byte, data []byte) (protocol.ResponseCommand, error) {
if len(data) <= 4 {
return nil, transport.ErrorCorruptedPacket
return nil, transport.ErrCorruptedPacket
}
expectedAuth := Authenticate(data[4:])
actualAuth := serial.BytesToUint32(data[:4])
if expectedAuth != actualAuth {
return nil, transport.ErrorCorruptedPacket
return nil, transport.ErrCorruptedPacket
}
var factory CommandFactory
@@ -65,7 +65,7 @@ func UnmarshalCommand(cmdId byte, data []byte) (protocol.ResponseCommand, error)
case 1:
factory = new(CommandSwitchAccountFactory)
default:
return nil, ErrorUnknownCommand
return nil, ErrUnknownCommand
}
return factory.Unmarshal(data[4:])
}
@@ -81,7 +81,7 @@ type CommandSwitchAccountFactory struct {
func (this *CommandSwitchAccountFactory) Marshal(command interface{}, writer io.Writer) error {
cmd, ok := command.(*protocol.CommandSwitchAccount)
if !ok {
return ErrorCommandTypeMismatch
return ErrCommandTypeMismatch
}
hostStr := ""
@@ -109,38 +109,38 @@ func (this *CommandSwitchAccountFactory) Marshal(command interface{}, writer io.
func (this *CommandSwitchAccountFactory) Unmarshal(data []byte) (interface{}, error) {
cmd := new(protocol.CommandSwitchAccount)
if len(data) == 0 {
return nil, transport.ErrorCorruptedPacket
return nil, transport.ErrCorruptedPacket
}
lenHost := int(data[0])
if len(data) < lenHost+1 {
return nil, transport.ErrorCorruptedPacket
return nil, transport.ErrCorruptedPacket
}
if lenHost > 0 {
cmd.Host = v2net.ParseAddress(string(data[1 : 1+lenHost]))
}
portStart := 1 + lenHost
if len(data) < portStart+2 {
return nil, transport.ErrorCorruptedPacket
return nil, transport.ErrCorruptedPacket
}
cmd.Port = v2net.PortFromBytes(data[portStart : portStart+2])
idStart := portStart + 2
if len(data) < idStart+16 {
return nil, transport.ErrorCorruptedPacket
return nil, transport.ErrCorruptedPacket
}
cmd.ID, _ = uuid.ParseBytes(data[idStart : idStart+16])
alterIdStart := idStart + 16
if len(data) < alterIdStart+2 {
return nil, transport.ErrorCorruptedPacket
return nil, transport.ErrCorruptedPacket
}
cmd.AlterIds = serial.BytesToUint16(data[alterIdStart : alterIdStart+2])
levelStart := alterIdStart + 2
if len(data) < levelStart+1 {
return nil, transport.ErrorCorruptedPacket
return nil, transport.ErrCorruptedPacket
}
cmd.Level = protocol.UserLevel(data[levelStart])
timeStart := levelStart + 1
if len(data) < timeStart {
return nil, transport.ErrorCorruptedPacket
return nil, transport.ErrCorruptedPacket
}
cmd.ValidMin = data[timeStart]
return cmd, nil
+4 -4
View File
@@ -54,7 +54,7 @@ func (this *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Requ
user, timestamp, valid := this.userValidator.Get(buffer.Value[:protocol.IDBytesLen])
if !valid {
return nil, protocol.ErrorInvalidUser
return nil, protocol.ErrInvalidUser
}
timestampHash := md5.New()
@@ -78,7 +78,7 @@ func (this *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Requ
if request.Version != Version {
log.Info("Raw: Invalid protocol version ", request.Version)
return nil, protocol.ErrorInvalidVersion
return nil, protocol.ErrInvalidVersion
}
this.requestBodyIV = append([]byte(nil), buffer.Value[1:17]...) // 16 bytes
@@ -114,7 +114,7 @@ func (this *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Requ
}
domainLength := int(buffer.Value[41])
if domainLength == 0 {
return nil, transport.ErrorCorruptedPacket
return nil, transport.ErrCorruptedPacket
}
nBytes, err = io.ReadFull(decryptor, buffer.Value[42:42+domainLength])
if err != nil {
@@ -138,7 +138,7 @@ func (this *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Requ
expectedHash := serial.BytesToUint32(buffer.Value[bufferLen : bufferLen+4])
if actualHash != expectedHash {
return nil, transport.ErrorCorruptedPacket
return nil, transport.ErrCorruptedPacket
}
return request, nil