1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-02 15:36:41 -05:00

rewrite error lib

This commit is contained in:
Darien Raymond 2016-12-04 09:10:47 +01:00
parent a4019a6900
commit efb24a4d21
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
65 changed files with 251 additions and 132 deletions

View File

@ -1,11 +1,11 @@
package impl package impl
import ( import (
"errors"
"v2ray.com/core/app" "v2ray.com/core/app"
"v2ray.com/core/app/proxyman" "v2ray.com/core/app/proxyman"
"v2ray.com/core/app/router" "v2ray.com/core/app/router"
"v2ray.com/core/common/alloc" "v2ray.com/core/common/alloc"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log" "v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net" v2net "v2ray.com/core/common/net"
"v2ray.com/core/proxy" "v2ray.com/core/proxy"

View File

@ -1,13 +1,13 @@
package dns package dns
import ( import (
"errors"
"net" "net"
"sync" "sync"
"time" "time"
"v2ray.com/core/app" "v2ray.com/core/app"
"v2ray.com/core/app/dispatcher" "v2ray.com/core/app/dispatcher"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/loader" "v2ray.com/core/common/loader"
"v2ray.com/core/common/log" "v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net" v2net "v2ray.com/core/common/net"

View File

@ -1,13 +1,13 @@
package proxy package proxy
import ( import (
"errors"
"io" "io"
"net" "net"
"time" "time"
"v2ray.com/core/app" "v2ray.com/core/app"
"v2ray.com/core/app/proxyman" "v2ray.com/core/app/proxyman"
"v2ray.com/core/common/errors"
v2io "v2ray.com/core/common/io" v2io "v2ray.com/core/common/io"
"v2ray.com/core/common/log" "v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net" v2net "v2ray.com/core/common/net"

View File

@ -1,9 +1,9 @@
package router package router
import ( import (
"errors"
"net" "net"
"v2ray.com/core/common/errors"
v2net "v2ray.com/core/common/net" v2net "v2ray.com/core/common/net"
"v2ray.com/core/proxy" "v2ray.com/core/proxy"
) )

View File

@ -1,10 +1,9 @@
package router package router
import ( import (
"errors"
"v2ray.com/core/app" "v2ray.com/core/app"
"v2ray.com/core/app/dns" "v2ray.com/core/app/dns"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/loader" "v2ray.com/core/common/loader"
"v2ray.com/core/common/log" "v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net" v2net "v2ray.com/core/common/net"

View File

@ -1,9 +1,8 @@
package app package app
import ( import (
"errors"
"v2ray.com/core/common" "v2ray.com/core/common"
"v2ray.com/core/common/errors"
) )
type ID int type ID int
@ -94,7 +93,7 @@ func (v *spaceImpl) BindApp(id ID, application Application) {
func (v *spaceImpl) BindFromConfig(name string, config interface{}) error { func (v *spaceImpl) BindFromConfig(name string, config interface{}) error {
factory, found := applicationFactoryCache[name] factory, found := applicationFactoryCache[name]
if !found { if !found {
return errors.New("Space: app not registered: " + name) return errors.New("Space: app not registered: ", name)
} }
app, err := factory.Create(v, config) app, err := factory.Create(v, config)
if err != nil { if err != nil {

29
app/web/config.proto Normal file
View File

@ -0,0 +1,29 @@
syntax = "proto3";
package v2ray.core.app.web;
option go_package = "web";
option java_package = "com.v2ray.core.app.web";
option java_outer_classname = "ConfigProto";
import "v2ray.com/core/common/loader/type.proto";
message FileServer {
message Entry {
oneof FileOrDir {
string File = 1;
string Directory = 2;
}
string path = 3;
}
repeated Entry entry = 1;
}
message Server {
repeated string domain = 1;
v2ray.core.common.loader.TypedSettings settings = 2;
}
message Config {
repeated Server server = 1;
}

1
app/web/file_server.go Normal file
View File

@ -0,0 +1 @@
package web

15
app/web/web.go Normal file
View File

@ -0,0 +1,15 @@
package web
import (
"v2ray.com/core/app"
"v2ray.com/core/common"
)
const (
APP_ID = app.ID(8)
)
type Server interface {
common.Releasable
Handle()
}

View File

@ -3,7 +3,7 @@
package common package common
import ( import (
"errors" "v2ray.com/core/common/errors"
) )
var ( var (

80
common/errors/errors.go Normal file
View File

@ -0,0 +1,80 @@
package errors
import (
"fmt"
"v2ray.com/core/common/serial"
)
type HasInnerError interface {
Inner() error
}
type Error struct {
message string
inner error
}
func (v *Error) Error() string {
return v.message
}
func (v *Error) Inner() error {
if v.inner == nil {
return nil
}
return v.inner
}
func New(msg ...interface{}) error {
return &Error{
message: serial.ToString(msg),
}
}
func Base(err error) ErrorBuilder {
return ErrorBuilder{
error: err,
}
}
func Cause(err error) error {
if err == nil {
return nil
}
for {
inner, ok := err.(HasInnerError)
if !ok {
break
}
if inner.Inner() == nil {
break
}
err = inner.Inner()
}
return err
}
type ErrorBuilder struct {
error
}
func (v ErrorBuilder) Message(msg ...interface{}) error {
if v.error == nil {
return nil
}
return &Error{
message: serial.ToString(msg) + " > " + v.error.Error(),
inner: v.error,
}
}
func (v ErrorBuilder) Format(format string, values ...interface{}) error {
if v.error == nil {
return nil
}
return &Error{
message: fmt.Sprintf(format, values...) + " > " + v.error.Error(),
inner: v.error,
}
}

View File

@ -4,6 +4,7 @@ import (
"io" "io"
"sync" "sync"
"v2ray.com/core/common/alloc" "v2ray.com/core/common/alloc"
"v2ray.com/core/common/errors"
) )
type BufferedWriter struct { type BufferedWriter struct {
@ -34,7 +35,7 @@ func (v *BufferedWriter) ReadFrom(reader io.Reader) (int64, error) {
nBytes, err := v.buffer.FillFrom(reader) nBytes, err := v.buffer.FillFrom(reader)
totalBytes += int64(nBytes) totalBytes += int64(nBytes)
if err != nil { if err != nil {
if err == io.EOF { if errors.Cause(err) == io.EOF {
return totalBytes, nil return totalBytes, nil
} }
return totalBytes, err return totalBytes, err

View File

@ -2,6 +2,7 @@ package io
import ( import (
"io" "io"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log" "v2ray.com/core/common/log"
) )
@ -29,7 +30,7 @@ func Pipe(reader Reader, writer Writer) error {
func PipeUntilEOF(reader Reader, writer Writer) error { func PipeUntilEOF(reader Reader, writer Writer) error {
err := Pipe(reader, writer) err := Pipe(reader, writer)
if err != nil && err != io.EOF { if err != nil && errors.Cause(err) != io.EOF {
return err return err
} }
return nil return nil

View File

@ -1,10 +1,10 @@
package loader package loader
import ( import (
"errors"
"reflect" "reflect"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"v2ray.com/core/common/errors"
) )
func NewTypedSettings(message proto.Message) *TypedSettings { func NewTypedSettings(message proto.Message) *TypedSettings {

View File

@ -8,26 +8,6 @@ import (
"v2ray.com/core/common/serial" "v2ray.com/core/common/serial"
) )
func InterfaceToString(value interface{}) string {
if value == nil {
return " "
}
switch value := value.(type) {
case string:
return value
case *string:
return *value
case fmt.Stringer:
return value.String()
case error:
return value.Error()
case []byte:
return serial.BytesToHexString(value)
default:
return fmt.Sprintf("%+v", value)
}
}
type LogEntry interface { type LogEntry interface {
common.Releasable common.Releasable
fmt.Stringer fmt.Stringer
@ -46,12 +26,7 @@ func (v *ErrorLog) Release() {
} }
func (v *ErrorLog) String() string { func (v *ErrorLog) String() string {
values := make([]string, len(v.Values)+1) return v.Prefix + serial.Concat(v.Values...)
values[0] = v.Prefix
for i, value := range v.Values {
values[i+1] = InterfaceToString(value)
}
return strings.Join(values, "")
} }
type AccessLog struct { type AccessLog struct {
@ -68,5 +43,5 @@ func (v *AccessLog) Release() {
} }
func (v *AccessLog) String() string { func (v *AccessLog) String() string {
return strings.Join([]string{InterfaceToString(v.From), v.Status, InterfaceToString(v.To), InterfaceToString(v.Reason)}, " ") return strings.Join([]string{serial.ToString(v.From), v.Status, serial.ToString(v.To), serial.ToString(v.Reason)}, " ")
} }

View File

@ -1,7 +1,7 @@
package log package log
import ( import (
"errors" "v2ray.com/core/common/errors"
"v2ray.com/core/common/log/internal" "v2ray.com/core/common/log/internal"
) )
@ -39,7 +39,7 @@ func SetLogLevel(level LogLevel) {
func InitErrorLogger(file string) error { func InitErrorLogger(file string) error {
logger, err := internal.NewFileLogWriter(file) logger, err := internal.NewFileLogWriter(file)
if err != nil { if err != nil {
return errors.New("Log:Failed to create error logger on file (" + file + "): " + err.Error()) return errors.Base(err).Message("Log: Failed to create error logger on file (", file, ")")
} }
streamLoggerInstance = logger streamLoggerInstance = logger
return nil return nil

View File

@ -1,9 +1,9 @@
package net package net
import ( import (
"errors"
"strconv" "strconv"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/serial" "v2ray.com/core/common/serial"
) )

View File

@ -1,7 +1,7 @@
package protocol package protocol
import ( import (
"errors" "v2ray.com/core/common/errors"
) )
var ( var (

View File

@ -3,9 +3,9 @@ package protocol
import ( import (
"crypto/hmac" "crypto/hmac"
"crypto/md5" "crypto/md5"
"errors"
"hash" "hash"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/uuid" "v2ray.com/core/common/uuid"
) )

View File

@ -1,7 +1,7 @@
package protocol package protocol
import ( import (
"errors" "v2ray.com/core/common/errors"
) )
var ( var (
@ -26,7 +26,7 @@ func (v *User) GetTypedAccount() (Account, error) {
if account, ok := rawAccount.(Account); ok { if account, ok := rawAccount.(Account); ok {
return account, nil return account, nil
} }
return nil, errors.New("Unknown account type: " + v.Account.Type) return nil, errors.New("Unknown account type: ", v.Account.Type)
} }
func (v *User) GetSettings() UserSettings { func (v *User) GetSettings() UserSettings {

View File

@ -1,8 +1,8 @@
package retry package retry
import ( import (
"errors"
"time" "time"
"v2ray.com/core/common/errors"
) )
var ( var (

View File

@ -1,10 +1,10 @@
package retry_test package retry_test
import ( import (
"errors"
"testing" "testing"
"time" "time"
"v2ray.com/core/common/errors"
. "v2ray.com/core/common/retry" . "v2ray.com/core/common/retry"
"v2ray.com/core/testing/assert" "v2ray.com/core/testing/assert"
) )

35
common/serial/string.go Normal file
View File

@ -0,0 +1,35 @@
package serial
import (
"fmt"
"strings"
)
func ToString(v interface{}) string {
if v == nil {
return " "
}
switch value := v.(type) {
case string:
return value
case *string:
return *value
case fmt.Stringer:
return value.String()
case error:
return value.Error()
case []byte:
return BytesToHexString(value)
default:
return fmt.Sprintf("%+v", value)
}
}
func Concat(v ...interface{}) string {
values := make([]string, len(v))
for i, value := range v {
values[i] = ToString(value)
}
return strings.Join(values, "")
}

View File

@ -5,7 +5,7 @@ import (
"crypto/md5" "crypto/md5"
"crypto/rand" "crypto/rand"
"encoding/hex" "encoding/hex"
"errors" "v2ray.com/core/common/errors"
) )
var ( var (

View File

@ -3,10 +3,10 @@ package dokodemo
import ( import (
"sync" "sync"
"errors"
"v2ray.com/core/app" "v2ray.com/core/app"
"v2ray.com/core/app/dispatcher" "v2ray.com/core/app/dispatcher"
"v2ray.com/core/common/alloc" "v2ray.com/core/common/alloc"
"v2ray.com/core/common/errors"
v2io "v2ray.com/core/common/io" v2io "v2ray.com/core/common/io"
"v2ray.com/core/common/loader" "v2ray.com/core/common/loader"
"v2ray.com/core/common/log" "v2ray.com/core/common/log"

View File

@ -1,7 +1,7 @@
package proxy package proxy
import ( import (
"errors" "v2ray.com/core/common/errors"
) )
var ( var (

View File

@ -1,12 +1,12 @@
package freedom package freedom
import ( import (
"errors"
"io" "io"
"v2ray.com/core/app" "v2ray.com/core/app"
"v2ray.com/core/app/dns" "v2ray.com/core/app/dns"
"v2ray.com/core/common/alloc" "v2ray.com/core/common/alloc"
"v2ray.com/core/common/dice" "v2ray.com/core/common/dice"
"v2ray.com/core/common/errors"
v2io "v2ray.com/core/common/io" v2io "v2ray.com/core/common/io"
"v2ray.com/core/common/loader" "v2ray.com/core/common/loader"
"v2ray.com/core/common/log" "v2ray.com/core/common/log"

View File

@ -12,6 +12,7 @@ import (
"v2ray.com/core/app" "v2ray.com/core/app"
"v2ray.com/core/app/dispatcher" "v2ray.com/core/app/dispatcher"
"v2ray.com/core/common" "v2ray.com/core/common"
"v2ray.com/core/common/errors"
v2io "v2ray.com/core/common/io" v2io "v2ray.com/core/common/io"
"v2ray.com/core/common/loader" "v2ray.com/core/common/loader"
"v2ray.com/core/common/log" "v2ray.com/core/common/log"
@ -101,7 +102,7 @@ func (v *Server) handleConnection(conn internet.Connection) {
request, err := http.ReadRequest(reader) request, err := http.ReadRequest(reader)
if err != nil { if err != nil {
if err != io.EOF { if errors.Cause(err) != io.EOF {
log.Warning("HTTP: Failed to read http request: ", err) log.Warning("HTTP: Failed to read http request: ", err)
} }
return return

View File

@ -1,10 +1,9 @@
package registry package registry
import ( import (
"errors"
"v2ray.com/core/app" "v2ray.com/core/app"
"v2ray.com/core/common" "v2ray.com/core/common"
"v2ray.com/core/common/errors"
"v2ray.com/core/proxy" "v2ray.com/core/proxy"
"v2ray.com/core/transport/internet" "v2ray.com/core/transport/internet"
) )

View File

@ -111,7 +111,7 @@ func (v *Client) Dispatch(destination v2net.Destination, payload *alloc.Buffer,
responseReader, err := ReadTCPResponse(user, conn) responseReader, err := ReadTCPResponse(user, conn)
if err != nil { if err != nil {
log.Warning("Shadowsocks|Client: Failed to read response: " + err.Error()) log.Warning("Shadowsocks|Client: Failed to read response: ", err)
return return
} }

View File

@ -4,9 +4,8 @@ import (
"bytes" "bytes"
"crypto/cipher" "crypto/cipher"
"crypto/md5" "crypto/md5"
"errors"
"v2ray.com/core/common/crypto" "v2ray.com/core/common/crypto"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/protocol" "v2ray.com/core/common/protocol"
) )
@ -41,7 +40,7 @@ func (v *Account) GetCipher() (Cipher, error) {
func (v *Account) AsAccount() (protocol.Account, error) { func (v *Account) AsAccount() (protocol.Account, error) {
cipher, err := v.GetCipher() cipher, err := v.GetCipher()
if err != nil { if err != nil {
return nil, err return nil, errors.Base(err).Message("Shadowsocks|Account: Failed to get cipher.")
} }
return &ShadowsocksAccount{ return &ShadowsocksAccount{
Cipher: cipher, Cipher: cipher,

View File

@ -4,9 +4,9 @@ import (
"bytes" "bytes"
"crypto/hmac" "crypto/hmac"
"crypto/sha1" "crypto/sha1"
"errors"
"io" "io"
"v2ray.com/core/common/alloc" "v2ray.com/core/common/alloc"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/serial" "v2ray.com/core/common/serial"
) )

View File

@ -3,11 +3,10 @@ package shadowsocks
import ( import (
"bytes" "bytes"
"crypto/rand" "crypto/rand"
"errors"
"io" "io"
"v2ray.com/core/common/alloc" "v2ray.com/core/common/alloc"
"v2ray.com/core/common/crypto" "v2ray.com/core/common/crypto"
"v2ray.com/core/common/errors"
v2io "v2ray.com/core/common/io" v2io "v2ray.com/core/common/io"
v2net "v2ray.com/core/common/net" v2net "v2ray.com/core/common/net"
"v2ray.com/core/common/protocol" "v2ray.com/core/common/protocol"
@ -25,7 +24,7 @@ const (
func ReadTCPSession(user *protocol.User, reader io.Reader) (*protocol.RequestHeader, v2io.Reader, error) { func ReadTCPSession(user *protocol.User, reader io.Reader) (*protocol.RequestHeader, v2io.Reader, error) {
rawAccount, err := user.GetTypedAccount() rawAccount, err := user.GetTypedAccount()
if err != nil { if err != nil {
return nil, nil, errors.New("Shadowsocks|TCP: Failed to parse account: " + err.Error()) return nil, nil, errors.Base(err).Message("Shadowsocks|TCP: Failed to parse account.")
} }
account := rawAccount.(*ShadowsocksAccount) account := rawAccount.(*ShadowsocksAccount)
@ -35,14 +34,14 @@ func ReadTCPSession(user *protocol.User, reader io.Reader) (*protocol.RequestHea
ivLen := account.Cipher.IVSize() ivLen := account.Cipher.IVSize()
_, err = io.ReadFull(reader, buffer.Value[:ivLen]) _, err = io.ReadFull(reader, buffer.Value[:ivLen])
if err != nil { if err != nil {
return nil, nil, errors.New("Shadowsocks|TCP: Failed to read IV: " + err.Error()) return nil, nil, errors.Base(err).Message("Shadowsocks|TCP: Failed to read IV.")
} }
iv := append([]byte(nil), buffer.Value[:ivLen]...) iv := append([]byte(nil), buffer.Value[:ivLen]...)
stream, err := account.Cipher.NewDecodingStream(account.Key, iv) stream, err := account.Cipher.NewDecodingStream(account.Key, iv)
if err != nil { if err != nil {
return nil, nil, errors.New("Shadowsocks|TCP: Failed to initialize decoding stream: " + err.Error()) return nil, nil, errors.Base(err).Message("Shadowsocks|TCP: Failed to initialize decoding stream.")
} }
reader = crypto.NewCryptionReader(stream, reader) reader = crypto.NewCryptionReader(stream, reader)
@ -56,7 +55,7 @@ func ReadTCPSession(user *protocol.User, reader io.Reader) (*protocol.RequestHea
lenBuffer := 1 lenBuffer := 1
_, err = io.ReadFull(reader, buffer.Value[:1]) _, err = io.ReadFull(reader, buffer.Value[:1])
if err != nil { if err != nil {
return nil, nil, errors.New("Shadowsocks|TCP: Failed to read address type: " + err.Error()) return nil, nil, errors.Base(err).Message("Shadowsocks|TCP: Failed to read address type.")
} }
addrType := (buffer.Value[0] & 0x0F) addrType := (buffer.Value[0] & 0x0F)
@ -76,32 +75,32 @@ func ReadTCPSession(user *protocol.User, reader io.Reader) (*protocol.RequestHea
case AddrTypeIPv4: case AddrTypeIPv4:
_, err := io.ReadFull(reader, buffer.Value[lenBuffer:lenBuffer+4]) _, err := io.ReadFull(reader, buffer.Value[lenBuffer:lenBuffer+4])
if err != nil { if err != nil {
return nil, nil, errors.New("Shadowsocks|TCP: Failed to read IPv4 address: " + err.Error()) return nil, nil, errors.Base(err).Message("Shadowsocks|TCP: Failed to read IPv4 address.")
} }
request.Address = v2net.IPAddress(buffer.Value[lenBuffer : lenBuffer+4]) request.Address = v2net.IPAddress(buffer.Value[lenBuffer : lenBuffer+4])
lenBuffer += 4 lenBuffer += 4
case AddrTypeIPv6: case AddrTypeIPv6:
_, err := io.ReadFull(reader, buffer.Value[lenBuffer:lenBuffer+16]) _, err := io.ReadFull(reader, buffer.Value[lenBuffer:lenBuffer+16])
if err != nil { if err != nil {
return nil, nil, errors.New("Shadowsocks|TCP: Failed to read IPv6 address: " + err.Error()) return nil, nil, errors.Base(err).Message("Shadowsocks|TCP: Failed to read IPv6 address.")
} }
request.Address = v2net.IPAddress(buffer.Value[lenBuffer : lenBuffer+16]) request.Address = v2net.IPAddress(buffer.Value[lenBuffer : lenBuffer+16])
lenBuffer += 16 lenBuffer += 16
case AddrTypeDomain: case AddrTypeDomain:
_, err := io.ReadFull(reader, buffer.Value[lenBuffer:lenBuffer+1]) _, err := io.ReadFull(reader, buffer.Value[lenBuffer:lenBuffer+1])
if err != nil { if err != nil {
return nil, nil, errors.New("Shadowsocks|TCP: Failed to read domain lenth: " + err.Error()) return nil, nil, errors.Base(err).Message("Shadowsocks|TCP: Failed to read domain lenth.")
} }
domainLength := int(buffer.Value[lenBuffer]) domainLength := int(buffer.Value[lenBuffer])
lenBuffer++ lenBuffer++
_, err = io.ReadFull(reader, buffer.Value[lenBuffer:lenBuffer+domainLength]) _, err = io.ReadFull(reader, buffer.Value[lenBuffer:lenBuffer+domainLength])
if err != nil { if err != nil {
return nil, nil, errors.New("Shadowsocks|TCP: Failed to read domain: " + err.Error()) return nil, nil, errors.Base(err).Message("Shadowsocks|TCP: Failed to read domain.")
} }
request.Address = v2net.DomainAddress(string(buffer.Value[lenBuffer : lenBuffer+domainLength])) request.Address = v2net.DomainAddress(string(buffer.Value[lenBuffer : lenBuffer+domainLength]))
lenBuffer += domainLength lenBuffer += domainLength
default: default:
return nil, nil, errors.New("Shadowsocks|TCP: Unknown address type.") return nil, nil, errors.New("Shadowsocks|TCP: Unknown address type: ", addrType)
} }
_, err = io.ReadFull(reader, buffer.Value[lenBuffer:lenBuffer+2]) _, err = io.ReadFull(reader, buffer.Value[lenBuffer:lenBuffer+2])
@ -139,7 +138,7 @@ func WriteTCPRequest(request *protocol.RequestHeader, writer io.Writer) (v2io.Wr
user := request.User user := request.User
rawAccount, err := user.GetTypedAccount() rawAccount, err := user.GetTypedAccount()
if err != nil { if err != nil {
return nil, errors.New("Shadowsocks|TCP: Failed to parse account: " + err.Error()) return nil, errors.Base(err).Message("Shadowsocks|TCP: Failed to parse account.")
} }
account := rawAccount.(*ShadowsocksAccount) account := rawAccount.(*ShadowsocksAccount)
@ -147,12 +146,12 @@ func WriteTCPRequest(request *protocol.RequestHeader, writer io.Writer) (v2io.Wr
rand.Read(iv) rand.Read(iv)
_, err = writer.Write(iv) _, err = writer.Write(iv)
if err != nil { if err != nil {
return nil, errors.New("Shadowsocks|TCP: Failed to write IV: " + err.Error()) return nil, errors.Base(err).Message("Shadowsocks|TCP: Failed to write IV.")
} }
stream, err := account.Cipher.NewEncodingStream(account.Key, iv) stream, err := account.Cipher.NewEncodingStream(account.Key, iv)
if err != nil { if err != nil {
return nil, errors.New("Shadowsocks|TCP: Failed to create encoding stream: " + err.Error()) return nil, errors.Base(err).Message("Shadowsocks|TCP: Failed to create encoding stream.")
} }
writer = crypto.NewCryptionWriter(stream, writer) writer = crypto.NewCryptionWriter(stream, writer)
@ -170,7 +169,7 @@ func WriteTCPRequest(request *protocol.RequestHeader, writer io.Writer) (v2io.Wr
header.AppendBytes(AddrTypeDomain, byte(len(request.Address.Domain()))) header.AppendBytes(AddrTypeDomain, byte(len(request.Address.Domain())))
header.Append([]byte(request.Address.Domain())) header.Append([]byte(request.Address.Domain()))
default: default:
return nil, errors.New("Shadowsocks|TCP: Unsupported address type. ") return nil, errors.New("Shadowsocks|TCP: Unsupported address type: ", request.Address.Family())
} }
header.AppendUint16(uint16(request.Port)) header.AppendUint16(uint16(request.Port))
@ -184,7 +183,7 @@ func WriteTCPRequest(request *protocol.RequestHeader, writer io.Writer) (v2io.Wr
_, err = writer.Write(header.Value) _, err = writer.Write(header.Value)
if err != nil { if err != nil {
return nil, errors.New("Shadowsocks|TCP: Failed to write header: " + err.Error()) return nil, errors.Base(err).Message("Shadowsocks|TCP: Failed to write header.")
} }
var chunkWriter v2io.Writer var chunkWriter v2io.Writer

View File

@ -3,12 +3,11 @@ package shadowsocks
import ( import (
"sync" "sync"
"errors"
"v2ray.com/core/app" "v2ray.com/core/app"
"v2ray.com/core/app/dispatcher" "v2ray.com/core/app/dispatcher"
"v2ray.com/core/common" "v2ray.com/core/common"
"v2ray.com/core/common/alloc" "v2ray.com/core/common/alloc"
"v2ray.com/core/common/errors"
v2io "v2ray.com/core/common/io" v2io "v2ray.com/core/common/io"
"v2ray.com/core/common/log" "v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net" v2net "v2ray.com/core/common/net"

View File

@ -1,10 +1,10 @@
package protocol package protocol
import ( import (
"errors"
"fmt" "fmt"
"io" "io"
"v2ray.com/core/common/alloc" "v2ray.com/core/common/alloc"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log" "v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net" v2net "v2ray.com/core/common/net"
"v2ray.com/core/proxy" "v2ray.com/core/proxy"

View File

@ -1,9 +1,8 @@
package protocol package protocol
import ( import (
"errors"
"io" "io"
"v2ray.com/core/common/errors"
v2net "v2ray.com/core/common/net" v2net "v2ray.com/core/common/net"
) )

View File

@ -1,9 +1,9 @@
package protocol package protocol
import ( import (
"errors"
"fmt" "fmt"
"v2ray.com/core/common/alloc" "v2ray.com/core/common/alloc"
"v2ray.com/core/common/errors"
v2net "v2ray.com/core/common/net" v2net "v2ray.com/core/common/net"
) )

View File

@ -1,13 +1,13 @@
package socks package socks
import ( import (
"errors"
"io" "io"
"sync" "sync"
"time" "time"
"v2ray.com/core/app" "v2ray.com/core/app"
"v2ray.com/core/app/dispatcher" "v2ray.com/core/app/dispatcher"
"v2ray.com/core/common/errors"
v2io "v2ray.com/core/common/io" v2io "v2ray.com/core/common/io"
"v2ray.com/core/common/loader" "v2ray.com/core/common/loader"
"v2ray.com/core/common/log" "v2ray.com/core/common/log"
@ -112,8 +112,8 @@ func (v *Server) handleConnection(connection internet.Connection) {
defer writer.Release() defer writer.Release()
auth, auth4, err := protocol.ReadAuthentication(reader) auth, auth4, err := protocol.ReadAuthentication(reader)
if err != nil && err != protocol.Socks4Downgrade { if err != nil && errors.Cause(err) != protocol.Socks4Downgrade {
if err != io.EOF { if errors.Cause(err) != io.EOF {
log.Warning("Socks: failed to read authentication: ", err) log.Warning("Socks: failed to read authentication: ", err)
} }
return return

View File

@ -1,10 +1,10 @@
package encoding package encoding
import ( import (
"errors"
"io" "io"
"v2ray.com/core/common/alloc" "v2ray.com/core/common/alloc"
"v2ray.com/core/common/errors"
v2net "v2ray.com/core/common/net" v2net "v2ray.com/core/common/net"
"v2ray.com/core/common/protocol" "v2ray.com/core/common/protocol"
"v2ray.com/core/common/serial" "v2ray.com/core/common/serial"

View File

@ -2,10 +2,10 @@ package encoding
import ( import (
"crypto/md5" "crypto/md5"
"errors"
"hash/fnv" "hash/fnv"
"io" "io"
"v2ray.com/core/common/crypto" "v2ray.com/core/common/crypto"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log" "v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net" v2net "v2ray.com/core/common/net"
"v2ray.com/core/common/protocol" "v2ray.com/core/common/protocol"

View File

@ -9,6 +9,7 @@ import (
"v2ray.com/core/app/proxyman" "v2ray.com/core/app/proxyman"
"v2ray.com/core/common" "v2ray.com/core/common"
"v2ray.com/core/common/alloc" "v2ray.com/core/common/alloc"
"v2ray.com/core/common/errors"
v2io "v2ray.com/core/common/io" v2io "v2ray.com/core/common/io"
"v2ray.com/core/common/loader" "v2ray.com/core/common/loader"
"v2ray.com/core/common/log" "v2ray.com/core/common/log"
@ -154,7 +155,7 @@ func (v *VMessInboundHandler) HandleConnection(connection internet.Connection) {
v.RUnlock() v.RUnlock()
if err != nil { if err != nil {
if err != io.EOF { if errors.Cause(err) != io.EOF {
log.Access(connection.RemoteAddr(), "", log.AccessRejected, err) log.Access(connection.RemoteAddr(), "", log.AccessRejected, err)
log.Info("VMessIn: Invalid request from ", connection.RemoteAddr(), ": ", err) log.Info("VMessIn: Invalid request from ", connection.RemoteAddr(), ": ", err)
} }

View File

@ -7,6 +7,7 @@ import (
"testing" "testing"
"v2ray.com/core/common/alloc" "v2ray.com/core/common/alloc"
"v2ray.com/core/common/errors"
v2io "v2ray.com/core/common/io" v2io "v2ray.com/core/common/io"
. "v2ray.com/core/proxy/vmess/io" . "v2ray.com/core/proxy/vmess/io"
"v2ray.com/core/testing/assert" "v2ray.com/core/testing/assert"
@ -68,7 +69,7 @@ func TestLargeIO(t *testing.T) {
reader := NewAuthChunkReader(chunckContent) reader := NewAuthChunkReader(chunckContent)
for { for {
buffer, err := reader.Read() buffer, err := reader.Read()
if err == io.EOF { if errors.Cause(err) == io.EOF {
break break
} }
assert.Error(err).IsNil() assert.Error(err).IsNil()

View File

@ -1,11 +1,11 @@
package io package io
import ( import (
"errors"
"hash" "hash"
"hash/fnv" "hash/fnv"
"io" "io"
"v2ray.com/core/common/alloc" "v2ray.com/core/common/alloc"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/serial" "v2ray.com/core/common/serial"
) )

View File

@ -2,8 +2,7 @@ package conf
import ( import (
"encoding/json" "encoding/json"
"errors" "v2ray.com/core/common/errors"
"v2ray.com/core/common/loader" "v2ray.com/core/common/loader"
"v2ray.com/core/proxy/blackhole" "v2ray.com/core/proxy/blackhole"
) )

View File

@ -2,9 +2,8 @@ package conf
import ( import (
"encoding/json" "encoding/json"
"errors"
"strings" "strings"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log" "v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net" v2net "v2ray.com/core/common/net"
"v2ray.com/core/common/protocol" "v2ray.com/core/common/protocol"

View File

@ -2,9 +2,8 @@ package conf
import ( import (
"encoding/json" "encoding/json"
"errors"
"v2ray.com/core/common" "v2ray.com/core/common"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log" "v2ray.com/core/common/log"
) )

View File

@ -2,11 +2,11 @@ package conf
import ( import (
"encoding/json" "encoding/json"
"errors"
"strconv" "strconv"
"strings" "strings"
"v2ray.com/core/app/router" "v2ray.com/core/app/router"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log" "v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net" v2net "v2ray.com/core/common/net"
"v2ray.com/core/tools/geoip" "v2ray.com/core/tools/geoip"

View File

@ -1,9 +1,8 @@
package conf package conf
import ( import (
"errors"
"strings" "strings"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/loader" "v2ray.com/core/common/loader"
"v2ray.com/core/common/protocol" "v2ray.com/core/common/protocol"
"v2ray.com/core/proxy/shadowsocks" "v2ray.com/core/proxy/shadowsocks"

View File

@ -2,8 +2,7 @@ package conf
import ( import (
"encoding/json" "encoding/json"
"errors" "v2ray.com/core/common/errors"
"v2ray.com/core/common/loader" "v2ray.com/core/common/loader"
"v2ray.com/core/common/protocol" "v2ray.com/core/common/protocol"
"v2ray.com/core/proxy/socks" "v2ray.com/core/proxy/socks"

View File

@ -1,8 +1,7 @@
package conf package conf
import ( import (
"errors" "v2ray.com/core/common/errors"
v2net "v2ray.com/core/common/net" v2net "v2ray.com/core/common/net"
"v2ray.com/core/transport" "v2ray.com/core/transport"
"v2ray.com/core/transport/internet" "v2ray.com/core/transport/internet"

View File

@ -1,8 +1,7 @@
package conf package conf
import ( import (
"errors" "v2ray.com/core/common/errors"
"v2ray.com/core/common/loader" "v2ray.com/core/common/loader"
"v2ray.com/core/transport/internet/authenticators/http" "v2ray.com/core/transport/internet/authenticators/http"
"v2ray.com/core/transport/internet/authenticators/noop" "v2ray.com/core/transport/internet/authenticators/noop"

View File

@ -2,11 +2,10 @@ package conf
import ( import (
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"strings" "strings"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/loader" "v2ray.com/core/common/loader"
v2net "v2ray.com/core/common/net" v2net "v2ray.com/core/common/net"
"v2ray.com/core/transport/internet" "v2ray.com/core/transport/internet"

View File

@ -2,11 +2,10 @@ package conf
import ( import (
"encoding/json" "encoding/json"
"errors"
"strings"
"io" "io"
"strings"
"v2ray.com/core" "v2ray.com/core"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/loader" "v2ray.com/core/common/loader"
v2net "v2ray.com/core/common/net" v2net "v2ray.com/core/common/net"
) )

View File

@ -2,8 +2,7 @@ package conf
import ( import (
"encoding/json" "encoding/json"
"errors" "v2ray.com/core/common/errors"
"v2ray.com/core/common/loader" "v2ray.com/core/common/loader"
v2net "v2ray.com/core/common/net" v2net "v2ray.com/core/common/net"
"v2ray.com/core/common/protocol" "v2ray.com/core/common/protocol"

View File

@ -1,8 +1,7 @@
package internet package internet
import ( import (
"errors" "v2ray.com/core/common/errors"
"v2ray.com/core/common/loader" "v2ray.com/core/common/loader"
"v2ray.com/core/common/log" "v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net" v2net "v2ray.com/core/common/net"

View File

@ -1,9 +1,8 @@
package internet package internet
import ( import (
"errors"
"net" "net"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log" "v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net" v2net "v2ray.com/core/common/net"
) )

View File

@ -1,9 +1,9 @@
package internal package internal
import ( import (
"errors"
"net" "net"
"reflect" "reflect"
"v2ray.com/core/common/errors"
) )
var ( var (

View File

@ -1,13 +1,12 @@
package kcp package kcp
import ( import (
"errors"
"io" "io"
"net" "net"
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "time"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log" "v2ray.com/core/common/log"
"v2ray.com/core/common/predicate" "v2ray.com/core/common/predicate"
"v2ray.com/core/transport/internet" "v2ray.com/core/transport/internet"

View File

@ -1,10 +1,9 @@
package tcp package tcp
import ( import (
"errors"
"net"
"crypto/tls" "crypto/tls"
"net"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log" "v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net" v2net "v2ray.com/core/common/net"
"v2ray.com/core/transport/internet" "v2ray.com/core/transport/internet"

View File

@ -2,11 +2,10 @@ package tcp
import ( import (
"crypto/tls" "crypto/tls"
"errors"
"net" "net"
"sync" "sync"
"time" "time"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log" "v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net" v2net "v2ray.com/core/common/net"
"v2ray.com/core/transport/internet" "v2ray.com/core/transport/internet"

View File

@ -1,10 +1,9 @@
package internet package internet
import ( import (
"errors"
"net" "net"
"sync" "sync"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log" "v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net" v2net "v2ray.com/core/common/net"
"v2ray.com/core/common/retry" "v2ray.com/core/common/retry"

View File

@ -1,10 +1,10 @@
package ws package ws
import ( import (
"errors"
"io" "io"
"net" "net"
"time" "time"
"v2ray.com/core/common/errors"
) )
var ( var (

View File

@ -2,18 +2,19 @@ package ws
import ( import (
"crypto/tls" "crypto/tls"
"errors"
"net" "net"
"net/http" "net/http"
"strconv" "strconv"
"sync" "sync"
"time" "time"
"github.com/gorilla/websocket" "v2ray.com/core/common/errors"
"v2ray.com/core/common/log" "v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net" v2net "v2ray.com/core/common/net"
"v2ray.com/core/transport/internet" "v2ray.com/core/transport/internet"
v2tls "v2ray.com/core/transport/internet/tls" v2tls "v2ray.com/core/transport/internet/tls"
"github.com/gorilla/websocket"
) )
var ( var (

View File

@ -1,8 +1,8 @@
package ws package ws
import ( import (
"errors"
"net" "net"
"v2ray.com/core/common/errors"
) )
type StoppableListener struct { type StoppableListener struct {

View File

@ -8,6 +8,7 @@ import (
"time" "time"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log" "v2ray.com/core/common/log"
) )
@ -64,7 +65,7 @@ func (ws *wsconn) readNext(b []byte) (n int, err error) {
return n, err return n, err
} }
if err == io.EOF { if errors.Cause(err) == io.EOF {
ws.readBuffer = nil ws.readBuffer = nil
if n == 0 { if n == 0 {
return ws.readNext(b) return ws.readNext(b)