mirror of https://github.com/v2ray/v2ray-core
Rename errors with Error prefix
parent
2f76680fe9
commit
f34e253ea3
|
@ -1,15 +1,9 @@
|
|||
package router
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
)
|
||||
|
||||
var (
|
||||
RouterNotFound = errors.New("Router not found.")
|
||||
)
|
||||
|
||||
type Router interface {
|
||||
TakeDetour(v2net.Destination) (string, error)
|
||||
}
|
||||
|
@ -32,5 +26,5 @@ func CreateRouter(name string, rawConfig interface{}) (Router, error) {
|
|||
if factory, found := routerCache[name]; found {
|
||||
return factory.Create(rawConfig)
|
||||
}
|
||||
return nil, RouterNotFound
|
||||
return nil, ErrorRouterNotFound
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
InvalidPortRange = errors.New("Invalid port range.")
|
||||
ErrorInvalidPortRange = errors.New("Invalid port range.")
|
||||
)
|
||||
|
||||
func (this *PortRange) UnmarshalJSON(data []byte) error {
|
||||
|
@ -22,7 +22,7 @@ func (this *PortRange) UnmarshalJSON(data []byte) error {
|
|||
if err == nil {
|
||||
if maybeint <= 0 || maybeint >= 65535 {
|
||||
log.Error("Invalid port [", serial.BytesLiteral(data), "]")
|
||||
return InvalidPortRange
|
||||
return ErrorInvalidPortRange
|
||||
}
|
||||
this.From = Port(maybeint)
|
||||
this.To = Port(maybeint)
|
||||
|
@ -37,7 +37,7 @@ func (this *PortRange) UnmarshalJSON(data []byte) error {
|
|||
value, err := strconv.Atoi(pair[0])
|
||||
if err != nil || value <= 0 || value >= 65535 {
|
||||
log.Error("Invalid from port ", pair[0])
|
||||
return InvalidPortRange
|
||||
return ErrorInvalidPortRange
|
||||
}
|
||||
this.From = Port(value)
|
||||
this.To = Port(value)
|
||||
|
@ -46,24 +46,24 @@ func (this *PortRange) UnmarshalJSON(data []byte) error {
|
|||
from, err := strconv.Atoi(pair[0])
|
||||
if err != nil || from <= 0 || from >= 65535 {
|
||||
log.Error("Invalid from port ", pair[0])
|
||||
return InvalidPortRange
|
||||
return ErrorInvalidPortRange
|
||||
}
|
||||
this.From = Port(from)
|
||||
|
||||
to, err := strconv.Atoi(pair[1])
|
||||
if err != nil || to <= 0 || to >= 65535 {
|
||||
log.Error("Invalid to port ", pair[1])
|
||||
return InvalidPortRange
|
||||
return ErrorInvalidPortRange
|
||||
}
|
||||
this.To = Port(to)
|
||||
|
||||
if this.From > this.To {
|
||||
log.Error("Invalid port range ", this.From, " -> ", this.To)
|
||||
return InvalidPortRange
|
||||
return ErrorInvalidPortRange
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return InvalidPortRange
|
||||
return ErrorInvalidPortRange
|
||||
}
|
||||
|
|
|
@ -27,10 +27,10 @@ func TestOverRangeIntPort(t *testing.T) {
|
|||
|
||||
var portRange PortRange
|
||||
err := json.Unmarshal([]byte("70000"), &portRange)
|
||||
assert.Error(err).Equals(InvalidPortRange)
|
||||
assert.Error(err).Equals(ErrorInvalidPortRange)
|
||||
|
||||
err = json.Unmarshal([]byte("-1"), &portRange)
|
||||
assert.Error(err).Equals(InvalidPortRange)
|
||||
assert.Error(err).Equals(ErrorInvalidPortRange)
|
||||
}
|
||||
|
||||
func TestSingleStringPort(t *testing.T) {
|
||||
|
@ -60,14 +60,14 @@ func TestOverRangeStringPort(t *testing.T) {
|
|||
|
||||
var portRange PortRange
|
||||
err := json.Unmarshal([]byte("\"65536\""), &portRange)
|
||||
assert.Error(err).Equals(InvalidPortRange)
|
||||
assert.Error(err).Equals(ErrorInvalidPortRange)
|
||||
|
||||
err = json.Unmarshal([]byte("\"70000-80000\""), &portRange)
|
||||
assert.Error(err).Equals(InvalidPortRange)
|
||||
assert.Error(err).Equals(ErrorInvalidPortRange)
|
||||
|
||||
err = json.Unmarshal([]byte("\"1-90000\""), &portRange)
|
||||
assert.Error(err).Equals(InvalidPortRange)
|
||||
assert.Error(err).Equals(ErrorInvalidPortRange)
|
||||
|
||||
err = json.Unmarshal([]byte("\"700-600\""), &portRange)
|
||||
assert.Error(err).Equals(InvalidPortRange)
|
||||
assert.Error(err).Equals(ErrorInvalidPortRange)
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
var (
|
||||
byteGroups = []int{8, 4, 4, 4, 12}
|
||||
|
||||
InvalidID = errors.New("Invalid ID.")
|
||||
ErrorInvalidID = errors.New("Invalid ID.")
|
||||
)
|
||||
|
||||
type UUID [16]byte
|
||||
|
@ -69,7 +69,7 @@ func New() *UUID {
|
|||
|
||||
func ParseBytes(b []byte) (*UUID, error) {
|
||||
if len(b) != 16 {
|
||||
return nil, InvalidID
|
||||
return nil, ErrorInvalidID
|
||||
}
|
||||
uuid := new(UUID)
|
||||
copy(uuid[:], b)
|
||||
|
@ -79,7 +79,7 @@ func ParseBytes(b []byte) (*UUID, error) {
|
|||
func ParseString(str string) (*UUID, error) {
|
||||
text := []byte(str)
|
||||
if len(text) < 32 {
|
||||
return nil, InvalidID
|
||||
return nil, ErrorInvalidID
|
||||
}
|
||||
|
||||
uuid := new(UUID)
|
||||
|
|
|
@ -19,7 +19,7 @@ func TestParseBytes(t *testing.T) {
|
|||
assert.String(uuid).Equals(str)
|
||||
|
||||
uuid, err = ParseBytes([]byte{1, 3, 2, 4})
|
||||
assert.Error(err).Equals(InvalidID)
|
||||
assert.Error(err).Equals(ErrorInvalidID)
|
||||
}
|
||||
|
||||
func TestParseString(t *testing.T) {
|
||||
|
@ -33,7 +33,7 @@ func TestParseString(t *testing.T) {
|
|||
assert.Bytes(uuid.Bytes()).Equals(expectedBytes)
|
||||
|
||||
uuid, err = ParseString("2418d087")
|
||||
assert.Error(err).Equals(InvalidID)
|
||||
assert.Error(err).Equals(ErrorInvalidID)
|
||||
|
||||
uuid, err = ParseString("2418d087-648k-4990-86e8-19dca1d006d3")
|
||||
assert.Error(err).IsNotNil()
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
InvalidAuthentication = errors.New("Invalid authentication.")
|
||||
InvalidProtocolVersion = errors.New("Invalid protocol version.")
|
||||
ErrorAlreadyListening = errors.New("Already listening on another port.")
|
||||
ErrorInvalidAuthentication = errors.New("Invalid authentication.")
|
||||
ErrorInvalidProtocolVersion = errors.New("Invalid protocol version.")
|
||||
ErrorAlreadyListening = errors.New("Already listening on another port.")
|
||||
)
|
||||
|
|
|
@ -66,7 +66,7 @@ func ReadAuthentication(reader io.Reader) (auth Socks5AuthenticationRequest, aut
|
|||
auth.version = buffer.Value[0]
|
||||
if auth.version != socksVersion {
|
||||
log.Warning("Socks: Unknown protocol version ", auth.version)
|
||||
err = proxy.InvalidProtocolVersion
|
||||
err = proxy.ErrorInvalidProtocolVersion
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
UnsupportedSocksCommand = errors.New("Unsupported socks command.")
|
||||
UnsupportedAuthMethod = errors.New("Unsupported auth method.")
|
||||
ErrorUnsupportedSocksCommand = errors.New("Unsupported socks command.")
|
||||
UnsupportedAuthMethod = errors.New("Unsupported auth method.")
|
||||
)
|
||||
|
||||
// SocksServer is a SOCKS 5 proxy server
|
||||
|
@ -146,7 +146,7 @@ func (this *SocksServer) handleSocks5(reader *v2net.TimeOutReader, writer io.Wri
|
|||
}
|
||||
if status != byte(0) {
|
||||
log.Warning("Socks: Invalid user account: ", upRequest.AuthDetail())
|
||||
return proxy.InvalidAuthentication
|
||||
return proxy.ErrorInvalidAuthentication
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -175,7 +175,7 @@ func (this *SocksServer) handleSocks5(reader *v2net.TimeOutReader, writer io.Wri
|
|||
return err
|
||||
}
|
||||
log.Warning("Socks: Unsupported socks command ", request.Command)
|
||||
return UnsupportedSocksCommand
|
||||
return ErrorUnsupportedSocksCommand
|
||||
}
|
||||
|
||||
response := protocol.NewSocks5Response()
|
||||
|
@ -252,7 +252,7 @@ func (this *SocksServer) handleSocks4(reader io.Reader, writer io.Writer, auth p
|
|||
|
||||
if result == protocol.Socks4RequestRejected {
|
||||
log.Warning("Socks: Unsupported socks 4 command ", auth.Command)
|
||||
return UnsupportedSocksCommand
|
||||
return ErrorUnsupportedSocksCommand
|
||||
}
|
||||
|
||||
dest := v2net.TCPDestination(v2net.IPAddress(auth.IP[:]), auth.Port)
|
||||
|
|
|
@ -77,7 +77,7 @@ func (this *VMessRequestReader) Read(reader io.Reader) (*VMessRequest, error) {
|
|||
|
||||
userObj, timeSec, valid := this.vUserSet.GetUser(buffer.Value[:nBytes])
|
||||
if !valid {
|
||||
return nil, proxy.InvalidAuthentication
|
||||
return nil, proxy.ErrorInvalidAuthentication
|
||||
}
|
||||
|
||||
timestampHash := TimestampHash()
|
||||
|
@ -105,7 +105,7 @@ func (this *VMessRequestReader) Read(reader io.Reader) (*VMessRequest, error) {
|
|||
|
||||
if request.Version != Version {
|
||||
log.Warning("VMess: Invalid protocol version ", request.Version)
|
||||
return nil, proxy.InvalidProtocolVersion
|
||||
return nil, proxy.ErrorInvalidProtocolVersion
|
||||
}
|
||||
|
||||
request.RequestIV = append([]byte(nil), buffer.Value[1:17]...) // 16 bytes
|
||||
|
|
|
@ -115,7 +115,7 @@ func (this *InboundDetourConfig) UnmarshalJSON(data []byte) error {
|
|||
}
|
||||
if jsonConfig.PortRange == nil {
|
||||
log.Error("Point: Port range not specified in InboundDetour.")
|
||||
return BadConfiguration
|
||||
return ErrorBadConfiguration
|
||||
}
|
||||
this.Protocol = jsonConfig.Protocol
|
||||
this.PortRange = *jsonConfig.PortRange
|
||||
|
|
Loading…
Reference in New Issue