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