Compare commits

..

12 Commits
v2.8.1 ... v2.9

Author SHA1 Message Date
Darien Raymond
abe8ffda68 fix buffered writer 2016-12-04 21:34:22 +01:00
Darien Raymond
e46bad3f18 format errors 2016-12-04 09:43:33 +01:00
Darien Raymond
efb24a4d21 rewrite error lib 2016-12-04 09:10:47 +01:00
Darien Raymond
a4019a6900 fast return on zero ack list 2016-12-02 21:40:58 +01:00
Darien Raymond
207c7aa8a7 flush acklist when dirty 2016-12-02 16:49:33 +01:00
Darien Raymond
60697e4e4f fix test break 2016-12-02 15:10:48 +01:00
Darien Raymond
3ba5ab3291 bring back high volumn mode in adaptive reader 2016-12-02 15:06:04 +01:00
Darien Raymond
b575de2a55 limit size of written data 2016-12-02 14:35:28 +01:00
Darien Raymond
2cf44393fb increase ray buffer size 2016-12-02 14:22:46 +01:00
Darien Raymond
5007d0cd55 fix git operation 2016-12-02 13:42:42 +01:00
Darien Raymond
ea27f7c434 trigger official docker release on new tag 2016-12-02 13:12:45 +01:00
Darien Raymond
1186b0e733 fix label name 2016-12-02 00:09:57 +01:00
77 changed files with 449 additions and 222 deletions

View File

@@ -32,3 +32,7 @@ deploy:
skip_cleanup: true
on:
tags: true
env:
global:
- secure: GQrOIEosXGR8NXQVeRmNuyz0TSDPyq0UHtpObhA0ZKHvhO4eNWUVRTwF/V1vrcNxMDcNQBeTVHIdWJYTaq8iG0qtEPiCCt3wVqX8jRssRNjw7dY1a/LK7Jj1c3py7vZPWnEC+i4x0sJJLeDTnY/f+YaScAnEQrVwEaRSH3A0TDMPMG7/7UJVfPtFYkqt3BSDGSBOgKsh9IJzaZ6zFARiQJLxuGz9pEpKwgWlErKwcs5JuHxXBdLXh84DE7kBmMi5j5zdp9O77Ed+bjZ2MZ3WHLSZyab2OlJICt8Wy0b8dzvqefek0t9TTu1M+GxtQjPfr//cToK0wzOQSOKX5hSUcygGJB7xcTs4xzArDWtDBBsiX/v1s965enODEjhqyvb2yGl5VrlN2SEOHAXsLgnlY+0NMieeY0i1GA/d0pgoRmQphfXuoaVVRlCFQT85lF62ieg1Uzob8hra2jAkumrsOcFZyYbDFQdWwqswbz2Z+S79YBmcdYucHqYuGwYQuZEmasv0p8F/LF0hQ8VaY57lZ3OIfegM+hIo9yf/wlTgnXt2UWe0U1ktQcjz6O6obVu0vnV/Q5LzIjhB++agABdk/kzM+m2+79+59IqEyymiMH38kXDOU7YCxAQkQDzsP662MEVdbst8/IpWhHwhys8ezdsKM98vg3uLd391E8vwhKI=
- secure: i+BVZ0oC1YnQb/2EprCFlQh3uzO2Kwu0LSyelFF0mfsIR7nSbVEP1T5gvBxyM8ZsuTfGW+70FLdfvntkwXXJ7sQm5bJlKlIQa0G5eC8G6dqpGknEgX5PZ1h+BoGkhZHDp12T0bJF3McoECMERAV/R6uFqn5LlTO5M0LSTmeqQRPlaRQnt4Qh0PD3REHCY4MrNZZuhUOxOA6cttJwUUtr6ECTSfRYxK7Dg2s/dUeBrfbPOvNhQkPbosv5Wft3S5+WYtin/4DRZO/T1Gd2WsOdEL8BqqXAfA1s4qW+U0zmp+vIG2hTlKS1fHWEfM9bpqShHSO/DKqPbwI0v8dIkTbEShOrF/+aZ2HnWSMbyXJBjtVKh2h8uDLqHCRuVXuQix2cS/5+RRj8vPoAWIa09Z60g4SrtJe1BKTPj3PLXlcN8KRIIXaJq9Lh+SDqxlWsK2m18AYVtAwkAAdyDPHOi0wy79mF1sSweD3/um+S+pmgOlmRoYOpXb17SR6RkOgETEzeihrG0Qmrlvsgp94IswDN+AvVFp17w3wFVd+tApHYTXoxuEl8qoqsNBtAE778hgrUt1cwaWM3Vw5x3EuXWYYxMjlNNC5lURpBL6jlStPFTrE4UnK5KEyIE7GZQOeJV9SplxYGUvagerv1mREtYob6S1hcOedyUAo6EIsAzJ8l4Ek=

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

@@ -167,8 +167,11 @@ func (b *Buffer) IsFull() bool {
// Write implements Write method in io.Writer.
func (b *Buffer) Write(data []byte) (int, error) {
b.Append(data)
return len(data), nil
begin := b.Len()
b.Value = b.Value[:cap(b.Value)]
nBytes := copy(b.Value[begin:], data)
b.Value = b.Value[:begin+nBytes]
return nBytes, nil
}
// Read implements io.Reader.Read().

View File

@@ -59,6 +59,19 @@ func TestBufferString(t *testing.T) {
assert.String(buffer.String()).Equals("Test String")
}
func TestBufferWrite(t *testing.T) {
assert := assert.On(t)
buffer := NewLocalBuffer(24).Clear() // 16 + 8
nBytes, err := buffer.Write([]byte("abcd"))
assert.Error(err).IsNil()
assert.Int(nBytes).Equals(4)
nBytes, err = buffer.Write([]byte("abcde"))
assert.Error(err).IsNil()
assert.Int(nBytes).Equals(4)
assert.String(buffer.String()).Equals("abcdabcd")
}
func BenchmarkNewBuffer8192(b *testing.B) {
for i := 0; i < b.N; i++ {
buffer := NewBuffer()

View File

@@ -3,7 +3,7 @@
package common
import (
"errors"
"v2ray.com/core/common/errors"
)
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"
"sync"
"v2ray.com/core/common/alloc"
"v2ray.com/core/common/errors"
)
type BufferedWriter struct {
@@ -16,7 +17,7 @@ type BufferedWriter struct {
func NewBufferedWriter(rawWriter io.Writer) *BufferedWriter {
return &BufferedWriter{
writer: rawWriter,
buffer: alloc.NewBuffer().Clear(),
buffer: alloc.NewSmallBuffer().Clear(),
cached: true,
}
}
@@ -34,7 +35,7 @@ func (v *BufferedWriter) ReadFrom(reader io.Reader) (int64, error) {
nBytes, err := v.buffer.FillFrom(reader)
totalBytes += int64(nBytes)
if err != nil {
if err == io.EOF {
if errors.Cause(err) == io.EOF {
return totalBytes, nil
}
return totalBytes, err
@@ -54,11 +55,22 @@ func (v *BufferedWriter) Write(b []byte) (int, error) {
if !v.cached {
return v.writer.Write(b)
}
nBytes, _ := v.buffer.Write(b)
if v.buffer.IsFull() {
v.FlushWithoutLock()
nBytes, err := v.buffer.Write(b)
if err != nil {
return 0, err
}
return nBytes, nil
if v.buffer.IsFull() {
err := v.FlushWithoutLock()
if err != nil {
return 0, err
}
if nBytes < len(b) {
if _, err := v.writer.Write(b[nBytes:]); err != nil {
return nBytes, err
}
}
}
return len(b), nil
}
func (v *BufferedWriter) Flush() error {

View File

@@ -1,6 +1,7 @@
package io_test
import (
"crypto/rand"
"testing"
"v2ray.com/core/common/alloc"
@@ -27,3 +28,26 @@ func TestBufferedWriter(t *testing.T) {
writer.SetCached(false)
assert.Int(content.Len()).Equals(16)
}
func TestBufferedWriterLargePayload(t *testing.T) {
assert := assert.On(t)
content := alloc.NewLocalBuffer(128 * 1024).Clear()
writer := NewBufferedWriter(content)
assert.Bool(writer.Cached()).IsTrue()
payload := make([]byte, 64*1024)
rand.Read(payload)
nBytes, err := writer.Write(payload[:1024])
assert.Int(nBytes).Equals(1024)
assert.Error(err).IsNil()
assert.Bool(content.IsEmpty()).IsTrue()
nBytes, err = writer.Write(payload[1024:])
assert.Error(err).IsNil()
assert.Int(nBytes).Equals(63 * 1024)
assert.Bytes(content.Value).Equals(payload)
}

View File

@@ -16,28 +16,50 @@ type Reader interface {
// AdaptiveReader is a Reader that adjusts its reading speed automatically.
type AdaptiveReader struct {
reader io.Reader
allocate func() *alloc.Buffer
reader io.Reader
largeBuffer *alloc.Buffer
highVolumn bool
}
// NewAdaptiveReader creates a new AdaptiveReader.
// The AdaptiveReader instance doesn't take the ownership of reader.
func NewAdaptiveReader(reader io.Reader) *AdaptiveReader {
return &AdaptiveReader{
reader: reader,
allocate: alloc.NewBuffer,
reader: reader,
}
}
// Read implements Reader.Read().
func (v *AdaptiveReader) Read() (*alloc.Buffer, error) {
buffer := v.allocate().Clear()
if v.highVolumn && v.largeBuffer.IsEmpty() {
if v.largeBuffer == nil {
v.largeBuffer = alloc.NewLocalBuffer(256 * 1024).Clear()
}
nBytes, err := v.largeBuffer.FillFrom(v.reader)
if err != nil {
return nil, err
}
if nBytes < alloc.BufferSize {
v.highVolumn = false
}
}
buffer := alloc.NewBuffer().Clear()
if !v.largeBuffer.IsEmpty() {
buffer.FillFrom(v.largeBuffer)
return buffer, nil
}
_, err := buffer.FillFrom(v.reader)
if err != nil {
buffer.Release()
return nil, err
}
if buffer.IsFull() {
v.highVolumn = true
}
return buffer, nil
}

View File

@@ -13,10 +13,17 @@ func TestAdaptiveReader(t *testing.T) {
assert := assert.On(t)
rawContent := make([]byte, 1024*1024)
buffer := bytes.NewBuffer(rawContent)
reader := NewAdaptiveReader(bytes.NewBuffer(rawContent))
reader := NewAdaptiveReader(buffer)
b1, err := reader.Read()
assert.Error(err).IsNil()
assert.Bool(b1.IsFull()).IsTrue()
assert.Int(b1.Len()).Equals(alloc.BufferSize)
assert.Int(buffer.Len()).Equals(cap(rawContent) - alloc.BufferSize)
b2, err := reader.Read()
assert.Error(err).IsNil()
assert.Bool(b2.IsFull()).IsTrue()
assert.Int(buffer.Len()).Equals(778272)
}

View File

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

View File

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

View File

@@ -8,26 +8,6 @@ import (
"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 {
common.Releasable
fmt.Stringer
@@ -46,12 +26,7 @@ func (v *ErrorLog) Release() {
}
func (v *ErrorLog) String() string {
values := make([]string, len(v.Values)+1)
values[0] = v.Prefix
for i, value := range v.Values {
values[i+1] = InterfaceToString(value)
}
return strings.Join(values, "")
return v.Prefix + serial.Concat(v.Values...)
}
type AccessLog struct {
@@ -68,5 +43,5 @@ func (v *AccessLog) Release() {
}
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
import (
"errors"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log/internal"
)
@@ -39,7 +39,7 @@ func SetLogLevel(level LogLevel) {
func InitErrorLogger(file string) error {
logger, err := internal.NewFileLogWriter(file)
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
return nil

View File

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

View File

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

View File

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

View File

@@ -1,7 +1,7 @@
package protocol
import (
"errors"
"v2ray.com/core/common/errors"
)
var (
@@ -26,7 +26,7 @@ func (v *User) GetTypedAccount() (Account, error) {
if account, ok := rawAccount.(Account); ok {
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 {

View File

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

View File

@@ -1,10 +1,10 @@
package retry_test
import (
"errors"
"testing"
"time"
"v2ray.com/core/common/errors"
. "v2ray.com/core/common/retry"
"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/rand"
"encoding/hex"
"errors"
"v2ray.com/core/common/errors"
)
var (

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,10 +1,9 @@
package registry
import (
"errors"
"v2ray.com/core/app"
"v2ray.com/core/common"
"v2ray.com/core/common/errors"
"v2ray.com/core/proxy"
"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)
if err != nil {
log.Warning("Shadowsocks|Client: Failed to read response: " + err.Error())
log.Warning("Shadowsocks|Client: Failed to read response: ", err)
return
}

View File

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

View File

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

View File

@@ -3,11 +3,10 @@ package shadowsocks
import (
"bytes"
"crypto/rand"
"errors"
"io"
"v2ray.com/core/common/alloc"
"v2ray.com/core/common/crypto"
"v2ray.com/core/common/errors"
v2io "v2ray.com/core/common/io"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/common/protocol"
@@ -25,7 +24,7 @@ const (
func ReadTCPSession(user *protocol.User, reader io.Reader) (*protocol.RequestHeader, v2io.Reader, error) {
rawAccount, err := user.GetTypedAccount()
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)
@@ -35,14 +34,14 @@ func ReadTCPSession(user *protocol.User, reader io.Reader) (*protocol.RequestHea
ivLen := account.Cipher.IVSize()
_, err = io.ReadFull(reader, buffer.Value[:ivLen])
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]...)
stream, err := account.Cipher.NewDecodingStream(account.Key, iv)
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)
@@ -56,7 +55,7 @@ func ReadTCPSession(user *protocol.User, reader io.Reader) (*protocol.RequestHea
lenBuffer := 1
_, err = io.ReadFull(reader, buffer.Value[:1])
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)
@@ -76,37 +75,37 @@ func ReadTCPSession(user *protocol.User, reader io.Reader) (*protocol.RequestHea
case AddrTypeIPv4:
_, err := io.ReadFull(reader, buffer.Value[lenBuffer:lenBuffer+4])
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])
lenBuffer += 4
case AddrTypeIPv6:
_, err := io.ReadFull(reader, buffer.Value[lenBuffer:lenBuffer+16])
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])
lenBuffer += 16
case AddrTypeDomain:
_, err := io.ReadFull(reader, buffer.Value[lenBuffer:lenBuffer+1])
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])
lenBuffer++
_, err = io.ReadFull(reader, buffer.Value[lenBuffer:lenBuffer+domainLength])
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]))
lenBuffer += domainLength
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])
if err != nil {
return nil, nil, errors.New("Shadowsocks|TCP: Failed to read port: " + err.Error())
return nil, nil, errors.Base(err).Message("Shadowsocks|TCP: Failed to read port.")
}
request.Port = v2net.PortFromBytes(buffer.Value[lenBuffer : lenBuffer+2])
@@ -116,7 +115,7 @@ func ReadTCPSession(user *protocol.User, reader io.Reader) (*protocol.RequestHea
authBytes := buffer.Value[lenBuffer : lenBuffer+AuthSize]
_, err = io.ReadFull(reader, authBytes)
if err != nil {
return nil, nil, errors.New("Shadowsocks|TCP: Failed to read OTA: " + err.Error())
return nil, nil, errors.Base(err).Message("Shadowsocks|TCP: Failed to read OTA.")
}
actualAuth := authenticator.Authenticate(nil, buffer.Value[0:lenBuffer])
@@ -139,7 +138,7 @@ func WriteTCPRequest(request *protocol.RequestHeader, writer io.Writer) (v2io.Wr
user := request.User
rawAccount, err := user.GetTypedAccount()
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)
@@ -147,12 +146,12 @@ func WriteTCPRequest(request *protocol.RequestHeader, writer io.Writer) (v2io.Wr
rand.Read(iv)
_, err = writer.Write(iv)
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)
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)
@@ -170,7 +169,7 @@ func WriteTCPRequest(request *protocol.RequestHeader, writer io.Writer) (v2io.Wr
header.AppendBytes(AddrTypeDomain, byte(len(request.Address.Domain())))
header.Append([]byte(request.Address.Domain()))
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))
@@ -184,7 +183,7 @@ func WriteTCPRequest(request *protocol.RequestHeader, writer io.Writer) (v2io.Wr
_, err = writer.Write(header.Value)
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
@@ -200,19 +199,19 @@ func WriteTCPRequest(request *protocol.RequestHeader, writer io.Writer) (v2io.Wr
func ReadTCPResponse(user *protocol.User, reader io.Reader) (v2io.Reader, error) {
rawAccount, err := user.GetTypedAccount()
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)
iv := make([]byte, account.Cipher.IVSize())
_, err = io.ReadFull(reader, iv)
if err != nil {
return nil, errors.New("Shadowsocks|TCP: Failed to read IV: " + err.Error())
return nil, errors.Base(err).Message("Shadowsocks|TCP: Failed to read IV.")
}
stream, err := account.Cipher.NewDecodingStream(account.Key, iv)
if err != nil {
return nil, errors.New("Shadowsocks|TCP: Failed to initialize decoding stream: " + err.Error())
return nil, errors.Base(err).Message("Shadowsocks|TCP: Failed to initialize decoding stream.")
}
return v2io.NewAdaptiveReader(crypto.NewCryptionReader(stream, reader)), nil
}
@@ -221,7 +220,7 @@ func WriteTCPResponse(request *protocol.RequestHeader, writer io.Writer) (v2io.W
user := request.User
rawAccount, err := user.GetTypedAccount()
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)
@@ -229,12 +228,12 @@ func WriteTCPResponse(request *protocol.RequestHeader, writer io.Writer) (v2io.W
rand.Read(iv)
_, err = writer.Write(iv)
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)
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.")
}
return v2io.NewAdaptiveWriter(crypto.NewCryptionWriter(stream, writer)), nil
@@ -244,7 +243,7 @@ func EncodeUDPPacket(request *protocol.RequestHeader, payload *alloc.Buffer) (*a
user := request.User
rawAccount, err := user.GetTypedAccount()
if err != nil {
return nil, errors.New("Shadowsocks|UDP: Failed to parse account: " + err.Error())
return nil, errors.Base(err).Message("Shadowsocks|UDP: Failed to parse account.")
}
account := rawAccount.(*ShadowsocksAccount)
@@ -265,7 +264,7 @@ func EncodeUDPPacket(request *protocol.RequestHeader, payload *alloc.Buffer) (*a
buffer.AppendBytes(AddrTypeDomain, byte(len(request.Address.Domain())))
buffer.Append([]byte(request.Address.Domain()))
default:
return nil, errors.New("Shadowsocks|UDP: Unsupported address type. ")
return nil, errors.New("Shadowsocks|UDP: Unsupported address type: ", request.Address.Family())
}
buffer.AppendUint16(uint16(request.Port))
@@ -280,7 +279,7 @@ func EncodeUDPPacket(request *protocol.RequestHeader, payload *alloc.Buffer) (*a
stream, err := account.Cipher.NewEncodingStream(account.Key, iv)
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.")
}
stream.XORKeyStream(buffer.Value[ivLen:], buffer.Value[ivLen:])
@@ -290,7 +289,7 @@ func EncodeUDPPacket(request *protocol.RequestHeader, payload *alloc.Buffer) (*a
func DecodeUDPPacket(user *protocol.User, payload *alloc.Buffer) (*protocol.RequestHeader, *alloc.Buffer, error) {
rawAccount, err := user.GetTypedAccount()
if err != nil {
return nil, nil, errors.New("Shadowsocks|UDP: Failed to parse account: " + err.Error())
return nil, nil, errors.Base(err).Message("Shadowsocks|UDP: Failed to parse account.")
}
account := rawAccount.(*ShadowsocksAccount)
@@ -300,7 +299,7 @@ func DecodeUDPPacket(user *protocol.User, payload *alloc.Buffer) (*protocol.Requ
stream, err := account.Cipher.NewDecodingStream(account.Key, iv)
if err != nil {
return nil, nil, errors.New("Shadowsocks|UDP: Failed to initialize decoding stream: " + err.Error())
return nil, nil, errors.Base(err).Message("Shadowsocks|UDP: Failed to initialize decoding stream.")
}
stream.XORKeyStream(payload.Value, payload.Value)
@@ -350,7 +349,7 @@ func DecodeUDPPacket(user *protocol.User, payload *alloc.Buffer) (*protocol.Requ
request.Address = v2net.DomainAddress(string(payload.Value[1 : 1+domainLength]))
payload.SliceFrom(1 + domainLength)
default:
return nil, nil, errors.New("Shadowsocks|UDP: Unknown address type")
return nil, nil, errors.New("Shadowsocks|UDP: Unknown address type: ", addrType)
}
request.Port = v2net.PortFromBytes(payload.Value[:2])

View File

@@ -3,12 +3,11 @@ package shadowsocks
import (
"sync"
"errors"
"v2ray.com/core/app"
"v2ray.com/core/app/dispatcher"
"v2ray.com/core/common"
"v2ray.com/core/common/alloc"
"v2ray.com/core/common/errors"
v2io "v2ray.com/core/common/io"
"v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net"
@@ -37,7 +36,7 @@ func NewServer(config *ServerConfig, space app.Space, meta *proxy.InboundHandler
rawAccount, err := config.User.GetTypedAccount()
if err != nil {
return nil, errors.New("Shadowsocks|Server: Failed to get user account: " + err.Error())
return nil, errors.Base(err).Message("Shadowsocks|Server: Failed to get user account.")
}
account := rawAccount.(*ShadowsocksAccount)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -2,10 +2,10 @@ package encoding
import (
"crypto/md5"
"errors"
"hash/fnv"
"io"
"v2ray.com/core/common/crypto"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/common/protocol"
@@ -60,7 +60,7 @@ func (v *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
iv := timestampHash.Sum(nil)
account, err := user.GetTypedAccount()
if err != nil {
return nil, errors.New("VMess|Server: Failed to get user account: " + err.Error())
return nil, errors.Base(err).Message("VMess|Server: Failed to get user account.")
}
aesStream := crypto.NewAesDecryptionStream(account.(*vmess.InternalAccount).ID.CmdKey(), iv)
@@ -68,7 +68,7 @@ func (v *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
nBytes, err := io.ReadFull(decryptor, buffer[:41])
if err != nil {
return nil, errors.New("VMess|Server: Failed to read request header: " + err.Error())
return nil, errors.Base(err).Message("VMess|Server: Failed to read request header.")
}
bufferLen := nBytes
@@ -78,8 +78,7 @@ func (v *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
}
if request.Version != Version {
log.Info("VMess|Server: Invalid protocol version ", request.Version)
return nil, protocol.ErrInvalidVersion
return nil, errors.New("VMess|Server: Invalid protocol version ", request.Version)
}
v.requestBodyIV = append([]byte(nil), buffer[1:17]...) // 16 bytes
@@ -95,28 +94,28 @@ func (v *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
_, err = io.ReadFull(decryptor, buffer[41:45]) // 4 bytes
bufferLen += 4
if err != nil {
return nil, errors.New("VMess|Server: Failed to read IPv4: " + err.Error())
return nil, errors.Base(err).Message("VMess|Server: Failed to read IPv4.")
}
request.Address = v2net.IPAddress(buffer[41:45])
case AddrTypeIPv6:
_, err = io.ReadFull(decryptor, buffer[41:57]) // 16 bytes
bufferLen += 16
if err != nil {
return nil, errors.New("VMess|Server: Failed to read IPv6 address: " + err.Error())
return nil, errors.Base(err).Message("VMess|Server: Failed to read IPv6 address.")
}
request.Address = v2net.IPAddress(buffer[41:57])
case AddrTypeDomain:
_, err = io.ReadFull(decryptor, buffer[41:42])
if err != nil {
return nil, errors.New("VMess:Server: Failed to read domain: " + err.Error())
return nil, errors.Base(err).Message("VMess:Server: Failed to read domain.")
}
domainLength := int(buffer[41])
if domainLength == 0 {
return nil, errors.New("VMess|Server: Zero domain length.")
return nil, errors.New("VMess|Server: Zero length domain.")
}
_, err = io.ReadFull(decryptor, buffer[42:42+domainLength])
if err != nil {
return nil, errors.New("VMess|Server: Failed to read domain: " + err.Error())
return nil, errors.Base(err).Message("VMess|Server: Failed to read domain.")
}
bufferLen += 1 + domainLength
request.Address = v2net.DomainAddress(string(buffer[42 : 42+domainLength]))
@@ -124,7 +123,7 @@ func (v *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
_, err = io.ReadFull(decryptor, buffer[bufferLen:bufferLen+4])
if err != nil {
return nil, errors.New("VMess|Server: Failed to read checksum: " + err.Error())
return nil, errors.Base(err).Message("VMess|Server: Failed to read checksum.")
}
fnv1a := fnv.New32a()

View File

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

View File

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

View File

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

View File

@@ -2,8 +2,7 @@ package conf
import (
"encoding/json"
"errors"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/loader"
"v2ray.com/core/proxy/blackhole"
)
@@ -29,7 +28,7 @@ func (v *BlackholeConfig) Build() (*loader.TypedSettings, error) {
if v.Response != nil {
response, _, err := configLoader.Load(v.Response)
if err != nil {
return nil, errors.New("Blackhole: Failed to parse response config: " + err.Error())
return nil, errors.Base(err).Message("Blackhole: Failed to parse response config.")
}
responseSettings, err := response.(Buildable).Build()
if err != nil {

View File

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

View File

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

View File

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

View File

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

View File

@@ -2,8 +2,7 @@ package conf
import (
"encoding/json"
"errors"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/loader"
"v2ray.com/core/common/protocol"
"v2ray.com/core/proxy/socks"
@@ -80,11 +79,11 @@ func (v *SocksClientConfig) Build() (*loader.TypedSettings, error) {
for _, rawUser := range serverConfig.Users {
user := new(protocol.User)
if err := json.Unmarshal(rawUser, user); err != nil {
return nil, errors.New("Socks|Client: Failed to parse user: " + err.Error())
return nil, errors.Base(err).Message("Socks|Client: Failed to parse user.")
}
account := new(SocksAccount)
if err := json.Unmarshal(rawUser, account); err != nil {
return nil, errors.New("Socks|Client: Failed to parse socks account: " + err.Error())
return nil, errors.Base(err).Message("Socks|Client: Failed to parse socks account.")
}
user.Account = loader.NewTypedSettings(account.Build())
server.User = append(server.User, user)

View File

@@ -1,8 +1,7 @@
package conf
import (
"errors"
"v2ray.com/core/common/errors"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/transport"
"v2ray.com/core/transport/internet"
@@ -20,7 +19,7 @@ func (v *TransportConfig) Build() (*transport.Config, error) {
if v.TCPConfig != nil {
ts, err := v.TCPConfig.Build()
if err != nil {
return nil, errors.New("Failed to build TCP config: " + err.Error())
return nil, errors.Base(err).Message("Failed to build TCP config.")
}
config.NetworkSettings = append(config.NetworkSettings, &internet.NetworkSettings{
Network: v2net.Network_TCP,
@@ -31,7 +30,7 @@ func (v *TransportConfig) Build() (*transport.Config, error) {
if v.KCPConfig != nil {
ts, err := v.KCPConfig.Build()
if err != nil {
return nil, errors.New("Failed to build KCP config: " + err.Error())
return nil, errors.Base(err).Message("Failed to build mKCP config.")
}
config.NetworkSettings = append(config.NetworkSettings, &internet.NetworkSettings{
Network: v2net.Network_KCP,
@@ -42,7 +41,7 @@ func (v *TransportConfig) Build() (*transport.Config, error) {
if v.WSConfig != nil {
ts, err := v.WSConfig.Build()
if err != nil {
return nil, errors.New("Failed to build WebSocket config: " + err.Error())
return nil, errors.Base(err).Message("Failed to build WebSocket config.")
}
config.NetworkSettings = append(config.NetworkSettings, &internet.NetworkSettings{
Network: v2net.Network_WebSocket,

View File

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

View File

@@ -2,11 +2,10 @@ package conf
import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"strings"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/loader"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/transport/internet"
@@ -85,11 +84,11 @@ func (v *KCPConfig) Build() (*loader.TypedSettings, error) {
if len(v.HeaderConfig) > 0 {
headerConfig, _, err := kcpHeaderLoader.Load(v.HeaderConfig)
if err != nil {
return nil, errors.New("KCP|Config: Failed to parse header config: " + err.Error())
return nil, errors.Base(err).Message("Invalid mKCP header config.")
}
ts, err := headerConfig.(Buildable).Build()
if err != nil {
return nil, errors.New("Failed to get KCP authenticator config: " + err.Error())
return nil, errors.Base(err).Message("Invalid mKCP header config.")
}
config.HeaderConfig = ts
}
@@ -112,11 +111,11 @@ func (v *TCPConfig) Build() (*loader.TypedSettings, error) {
if len(v.HeaderConfig) > 0 {
headerConfig, _, err := tcpHeaderLoader.Load(v.HeaderConfig)
if err != nil {
return nil, errors.New("TCP|Config: Failed to parse header config: " + err.Error())
return nil, errors.Base(err).Message("Invalid TCP header config.")
}
ts, err := headerConfig.(Buildable).Build()
if err != nil {
return nil, errors.New("Failed to get TCP authenticator config: " + err.Error())
return nil, errors.Base(err).Message("Invalid TCP header config.")
}
config.HeaderSettings = ts
}
@@ -156,11 +155,11 @@ func (v *TLSConfig) Build() (*loader.TypedSettings, error) {
for idx, certConf := range v.Certs {
cert, err := ioutil.ReadFile(certConf.CertFile)
if err != nil {
return nil, errors.New("TLS: Failed to load certificate file: " + err.Error())
return nil, errors.Base(err).Message("Failed to load TLS certificate file: ", certConf.CertFile)
}
key, err := ioutil.ReadFile(certConf.KeyFile)
if err != nil {
return nil, errors.New("TLS: Failed to load key file: " + err.Error())
return nil, errors.Base(err).Message("Failed to load TLS key file: ", certConf.KeyFile)
}
config.Certificate[idx] = &tls.Certificate{
Key: key,
@@ -194,14 +193,14 @@ func (v *StreamConfig) Build() (*internet.StreamConfig, error) {
}
ts, err := tlsSettings.Build()
if err != nil {
return nil, errors.New("Failed to build TLS config: " + err.Error())
return nil, errors.Base(err).Message("Failed to build TLS config.")
}
config.SecuritySettings = append(config.SecuritySettings, ts)
}
if v.TCPSettings != nil {
ts, err := v.TCPSettings.Build()
if err != nil {
return nil, errors.New("Failed to build TCP config: " + err.Error())
return nil, errors.Base(err).Message("Failed to build TCP config.")
}
config.NetworkSettings = append(config.NetworkSettings, &internet.NetworkSettings{
Network: v2net.Network_TCP,
@@ -211,7 +210,7 @@ func (v *StreamConfig) Build() (*internet.StreamConfig, error) {
if v.KCPSettings != nil {
ts, err := v.KCPSettings.Build()
if err != nil {
return nil, errors.New("Failed to build KCP config: " + err.Error())
return nil, errors.Base(err).Message("Failed to build mKCP config.")
}
config.NetworkSettings = append(config.NetworkSettings, &internet.NetworkSettings{
Network: v2net.Network_KCP,
@@ -221,7 +220,7 @@ func (v *StreamConfig) Build() (*internet.StreamConfig, error) {
if v.WSSettings != nil {
ts, err := v.WSSettings.Build()
if err != nil {
return nil, errors.New("Failed to build WebSocket config: " + err.Error())
return nil, errors.Base(err).Message("Failed to build WebSocket config.")
}
config.NetworkSettings = append(config.NetworkSettings, &internet.NetworkSettings{
Network: v2net.Network_WebSocket,

View File

@@ -2,11 +2,10 @@ package conf
import (
"encoding/json"
"errors"
"strings"
"io"
"strings"
"v2ray.com/core"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/loader"
v2net "v2ray.com/core/common/net"
)
@@ -61,7 +60,7 @@ func (v *InboundConnectionConfig) Build() (*core.InboundConnectionConfig, error)
jsonConfig, err := inboundConfigLoader.LoadWithID(v.Settings, v.Protocol)
if err != nil {
return nil, errors.New("Failed to load inbound config: " + err.Error())
return nil, errors.Base(err).Message("Failed to load inbound config.")
}
ts, err := jsonConfig.(Buildable).Build()
if err != nil {
@@ -87,7 +86,7 @@ func (v *OutboundConnectionConfig) Build() (*core.OutboundConnectionConfig, erro
config := new(core.OutboundConnectionConfig)
rawConfig, err := outboundConfigLoader.LoadWithID(v.Settings, v.Protocol)
if err != nil {
return nil, errors.New("Failed to parse outbound config: " + err.Error())
return nil, errors.Base(err).Message("Failed to parse outbound config.")
}
ts, err := rawConfig.(Buildable).Build()
if err != nil {
@@ -98,7 +97,7 @@ func (v *OutboundConnectionConfig) Build() (*core.OutboundConnectionConfig, erro
if v.SendThrough != nil {
address := v.SendThrough
if address.Family().IsDomain() {
return nil, errors.New("Point: Unable to send through: " + address.String())
return nil, errors.New("Invalid sendThrough address: " + address.String())
}
config.SendThrough = address.Build()
}
@@ -112,7 +111,7 @@ func (v *OutboundConnectionConfig) Build() (*core.OutboundConnectionConfig, erro
if v.ProxySettings != nil {
ps, err := v.ProxySettings.Build()
if err != nil {
return nil, errors.New("Outbound: invalid proxy settings: " + err.Error())
return nil, errors.Base(err).Message("Invalid outbound proxy settings.")
}
config.ProxySettings = ps
}
@@ -138,7 +137,7 @@ func (v *InboundDetourAllocationConfig) Build() (*core.AllocationStrategy, error
case "external":
config.Type = core.AllocationStrategy_External
default:
return nil, errors.New("Unknown allocation strategy: " + v.Strategy)
return nil, errors.New("Unknown allocation strategy: ", v.Strategy)
}
if v.Concurrency != nil {
config.Concurrency = &core.AllocationStrategyConcurrency{
@@ -169,13 +168,13 @@ type InboundDetourConfig struct {
func (v *InboundDetourConfig) Build() (*core.InboundConnectionConfig, error) {
config := new(core.InboundConnectionConfig)
if v.PortRange == nil {
return nil, errors.New("Point: Port range not specified in InboundDetour.")
return nil, errors.New("Port range not specified in InboundDetour.")
}
config.PortRange = v.PortRange.Build()
if v.ListenOn != nil {
if v.ListenOn.Family().IsDomain() {
return nil, errors.New("Point: Unable to listen on domain address: " + v.ListenOn.Domain())
return nil, errors.New("Unable to listen on domain address: ", v.ListenOn.Domain())
}
config.ListenOn = v.ListenOn.Build()
}
@@ -198,7 +197,7 @@ func (v *InboundDetourConfig) Build() (*core.InboundConnectionConfig, error) {
rawConfig, err := inboundConfigLoader.LoadWithID(v.Settings, v.Protocol)
if err != nil {
return nil, errors.New("Failed to load inbound detour config: " + err.Error())
return nil, errors.Base(err).Message("Failed to load inbound detour config.")
}
ts, err := rawConfig.(Buildable).Build()
if err != nil {
@@ -239,7 +238,7 @@ func (v *OutboundDetourConfig) Build() (*core.OutboundConnectionConfig, error) {
rawConfig, err := outboundConfigLoader.LoadWithID(v.Settings, v.Protocol)
if err != nil {
return nil, errors.New("Failed to parse to outbound detour config: " + err.Error())
return nil, errors.Base(err).Message("Failed to parse to outbound detour config.")
}
ts, err := rawConfig.(Buildable).Build()
if err != nil {
@@ -249,7 +248,7 @@ func (v *OutboundDetourConfig) Build() (*core.OutboundConnectionConfig, error) {
if v.ProxySettings != nil {
ps, err := v.ProxySettings.Build()
if err != nil {
return nil, errors.New("OutboundDetour: invalid proxy settings: " + err.Error())
return nil, errors.Base(err).Message("Invalid outbound detour proxy settings.")
}
config.ProxySettings = ps
}
@@ -341,7 +340,7 @@ func init() {
decoder := json.NewDecoder(input)
err := decoder.Decode(jsonConfig)
if err != nil {
return nil, errors.New("Point: Failed to load server config: " + err.Error())
return nil, errors.Base(err).Message("Invalid V2Ray config.")
}
return jsonConfig.Build()

View File

@@ -2,8 +2,7 @@ package conf
import (
"encoding/json"
"errors"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/loader"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/common/protocol"
@@ -78,11 +77,11 @@ func (v *VMessInboundConfig) Build() (*loader.TypedSettings, error) {
for idx, rawData := range v.Users {
user := new(protocol.User)
if err := json.Unmarshal(rawData, user); err != nil {
return nil, errors.New("VMess|Inbound: Invalid user: " + err.Error())
return nil, errors.Base(err).Message("Invalid VMess user.")
}
account := new(VMessAccount)
if err := json.Unmarshal(rawData, account); err != nil {
return nil, errors.New("VMess|Inbound: Invalid user: " + err.Error())
return nil, errors.Base(err).Message("Invalid VMess user.")
}
user.Account = loader.NewTypedSettings(account.Build())
config.User[idx] = user
@@ -124,11 +123,11 @@ func (v *VMessOutboundConfig) Build() (*loader.TypedSettings, error) {
for _, rawUser := range rec.Users {
user := new(protocol.User)
if err := json.Unmarshal(rawUser, user); err != nil {
return nil, errors.New("VMess|Outbound: Invalid user: " + err.Error())
return nil, errors.Base(err).Message("Invalid VMess user.")
}
account := new(VMessAccount)
if err := json.Unmarshal(rawUser, account); err != nil {
return nil, errors.New("VMess|Outbound: Invalid user: " + err.Error())
return nil, errors.Base(err).Message("Invalid VMess user.")
}
user.Account = loader.NewTypedSettings(account.Build())
spec.User = append(spec.User, user)

View File

@@ -13,4 +13,20 @@ $GOPATH/bin/build --os=linux --arch=mips64 --zip
$GOPATH/bin/build --os=freebsd --arch=x86 --zip
$GOPATH/bin/build --os=freebsd --arch=amd64 --zip
$GOPATH/bin/build --os=openbsd --arch=x86 --zip
$GOPATH/bin/build --os=openbsd --arch=amd64 --zip
$GOPATH/bin/build --os=openbsd --arch=amd64 --zip
INSTALL_DIR=_install
git clone "https://github.com/v2ray/install.git" ${INSTALL_DIR}
cp $GOPATH/bin/v2ray-${TRAVIS_TAG}-linux-64/v2ray ${INSTALL_DIR}/docker/official/
pushd ${INSTALL_DIR}
git config user.name "V2Ray Auto Build"
git config user.email "admin@v2ray.com"
git add -A
git commit -m "Update for ${TRAVIS_TAG}"
git push "https://${GIT_KEY_INSTALL}@github.com/v2ray/install.git" master
popd
DOCKER_HUB_API=https://registry.hub.docker.com/u/v2ray/official/trigger/${DOCKER_HUB_KEY}/
curl -H "Content-Type: application/json" --data '{"build": true}' -X POST "${DOCKER_HUB_API}"

View File

@@ -11,7 +11,7 @@ import (
func TestReaderWriter(t *testing.T) {
assert := assert.On(t)
cache := alloc.NewBuffer()
cache := alloc.NewBuffer().Clear()
writer := NewHeaderWriter(alloc.NewLocalBuffer(256).Clear().AppendString("abcd" + ENDING))
writer.Write(cache)
cache.Write([]byte{'e', 'f', 'g'})

View File

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

View File

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

View File

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

View File

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

View File

@@ -62,14 +62,15 @@ type AckList struct {
nextFlush []uint32
flushCandidates []uint32
dirty bool
}
func NewAckList(writer SegmentWriter) *AckList {
return &AckList{
writer: writer,
timestamps: make([]uint32, 0, 32),
numbers: make([]uint32, 0, 32),
nextFlush: make([]uint32, 0, 32),
timestamps: make([]uint32, 0, 128),
numbers: make([]uint32, 0, 128),
nextFlush: make([]uint32, 0, 128),
flushCandidates: make([]uint32, 0, 128),
}
}
@@ -78,6 +79,7 @@ func (v *AckList) Add(number uint32, timestamp uint32) {
v.timestamps = append(v.timestamps, timestamp)
v.numbers = append(v.numbers, number)
v.nextFlush = append(v.nextFlush, 0)
v.dirty = true
}
func (v *AckList) Clear(una uint32) {
@@ -97,6 +99,7 @@ func (v *AckList) Clear(una uint32) {
v.numbers = v.numbers[:count]
v.timestamps = v.timestamps[:count]
v.nextFlush = v.nextFlush[:count]
v.dirty = true
}
}
@@ -123,9 +126,10 @@ func (v *AckList) Flush(current uint32, rto uint32) {
v.writer.Write(seg)
seg.Release()
seg = NewAckSegment()
v.dirty = false
}
}
if seg.Count > 0 {
if v.dirty || seg.Count > 0 {
for _, number := range v.flushCandidates {
if seg.IsFull() {
break
@@ -134,6 +138,7 @@ func (v *AckList) Flush(current uint32, rto uint32) {
}
v.writer.Write(seg)
seg.Release()
v.dirty = false
}
}

View File

@@ -255,6 +255,10 @@ func (v *SendingWorker) ProcessSegment(current uint32, seg *AckSegment, rto uint
}
v.ProcessReceivingNextWithoutLock(seg.ReceivingNext)
if seg.Count == 0 {
return
}
var maxack uint32
var maxackRemoved bool
for i := 0; i < int(seg.Count); i++ {

View File

@@ -7,7 +7,7 @@ TEXT ·xorfwd(SB),NOSPLIT,$0
MOVQ x+0(FP), DI
ADDQ $4, DI // x[i+4]
SUBQ $4, CX
loop:
xorfwdloop:
MOVL (SI), AX
XORL AX, (DI)
ADDQ $4, SI
@@ -15,10 +15,10 @@ loop:
SUBQ $4, CX
CMPL CX, $0
JE done
JE xorfwddone
JMP loop
done:
JMP xorfwdloop
xorfwddone:
RET
// func xorbkd(x []byte)
@@ -31,7 +31,7 @@ TEXT ·xorbkd(SB),NOSPLIT,$0
ADDQ CX, DI // x[-4]
SUBQ $4, DI
SUBQ $4, CX
loop:
xorbkdloop:
MOVL (SI), AX
XORL AX, (DI)
SUBQ $4, SI
@@ -39,9 +39,9 @@ loop:
SUBQ $4, CX
CMPL CX, $0
JE done
JE xorbkddone
JMP loop
JMP xorbkdloop
done:
xorbkddone:
RET

View File

@@ -1,10 +1,9 @@
package tcp
import (
"errors"
"net"
"crypto/tls"
"net"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/transport/internet"
@@ -56,11 +55,11 @@ func Dial(src v2net.Address, dest v2net.Destination, options internet.DialerOpti
if tcpSettings.HeaderSettings != nil {
headerConfig, err := tcpSettings.HeaderSettings.GetInstance()
if err != nil {
return nil, errors.New("TCP: Failed to get header settings: " + err.Error())
return nil, errors.Base(err).Message("Interent|TCP: Failed to get header settings.")
}
auth, err := internet.CreateConnectionAuthenticator(tcpSettings.HeaderSettings.Type, headerConfig)
if err != nil {
return nil, errors.New("TCP: Failed to create header authenticator: " + err.Error())
return nil, errors.Base(err).Message("Internet|TCP: Failed to create header authenticator.")
}
conn = auth.Client(conn)
}

View File

@@ -2,11 +2,10 @@ package tcp
import (
"crypto/tls"
"errors"
"net"
"sync"
"time"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/transport/internet"
@@ -67,11 +66,11 @@ func ListenTCP(address v2net.Address, port v2net.Port, options internet.ListenOp
if tcpSettings.HeaderSettings != nil {
headerConfig, err := tcpSettings.HeaderSettings.GetInstance()
if err != nil {
return nil, errors.New("TCP: Failed to get header settings: " + err.Error())
return nil, errors.Base(err).Message("Internet|TCP: Invalid header settings.")
}
auth, err := internet.CreateConnectionAuthenticator(tcpSettings.HeaderSettings.Type, headerConfig)
if err != nil {
return nil, errors.New("TCP: Failed to create header authenticator: " + err.Error())
return nil, errors.Base(err).Message("Internet|TCP: Invalid header settings.")
}
l.authConfig = auth
}

View File

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

View File

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

View File

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

View File

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

View File

@@ -8,6 +8,7 @@ import (
"time"
"github.com/gorilla/websocket"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log"
)
@@ -41,7 +42,7 @@ func (ws *wsconn) read(b []byte) (n int, err error) {
func (ws *wsconn) getNewReadBuffer() error {
_, r, err := ws.wsc.NextReader()
if err != nil {
log.Warning("WS transport: ws connection NewFrameReader return " + err.Error())
log.Warning("WS transport: ws connection NewFrameReader return ", err)
ws.connClosing = true
ws.Close()
return err
@@ -64,7 +65,7 @@ func (ws *wsconn) readNext(b []byte) (n int, err error) {
return n, err
}
if err == io.EOF {
if errors.Cause(err) == io.EOF {
ws.readBuffer = nil
if n == 0 {
return ws.readNext(b)
@@ -89,7 +90,7 @@ func (ws *wsconn) Write(b []byte) (n int, err error) {
func (ws *wsconn) write(b []byte) (n int, err error) {
wr, err := ws.wsc.NextWriter(websocket.BinaryMessage)
if err != nil {
log.Warning("WS transport: ws connection NewFrameReader return " + err.Error())
log.Warning("WS transport: ws connection NewFrameReader return ", err)
ws.connClosing = true
ws.Close()
return 0, err

View File

@@ -9,7 +9,7 @@ import (
)
const (
bufferSize = 128
bufferSize = 512
)
// NewRay creates a new Ray for direct traffic transport.