diff --git a/app/point/config/config.go b/app/point/config/config.go index 00daf8133..2daada223 100644 --- a/app/point/config/config.go +++ b/app/point/config/config.go @@ -16,6 +16,11 @@ type LogConfig interface { AccessLog() string } +type InboundDetour interface { + Protocol() string + Port() +} + type PointConfig interface { Port() uint16 LogConfig() LogConfig diff --git a/common/net/timed_io.go b/common/net/timed_io.go index b2690ea15..ff2450834 100644 --- a/common/net/timed_io.go +++ b/common/net/timed_io.go @@ -1,7 +1,7 @@ package net import ( - "io" + "io" "net" "time" ) @@ -11,17 +11,17 @@ var ( ) type TimeOutReader struct { - timeout int + timeout int connection net.Conn - worker io.Reader + worker io.Reader } func NewTimeOutReader(timeout int, connection net.Conn) *TimeOutReader { reader := &TimeOutReader{ connection: connection, } - reader.SetTimeOut(timeout) - return reader + reader.SetTimeOut(timeout) + return reader } func (reader *TimeOutReader) Read(p []byte) (int, error) { @@ -33,36 +33,36 @@ func (reader *TimeOutReader) GetTimeOut() int { } func (reader *TimeOutReader) SetTimeOut(value int) { - reader.timeout = value - if value > 0 { - reader.worker = &timedReaderWorker{ - timeout: value, - connection: reader.connection, - } - } else { - reader.worker = &noOpReaderWorker{ - connection: reader.connection, - } - } + reader.timeout = value + if value > 0 { + reader.worker = &timedReaderWorker{ + timeout: value, + connection: reader.connection, + } + } else { + reader.worker = &noOpReaderWorker{ + connection: reader.connection, + } + } } type timedReaderWorker struct { - timeout int - connection net.Conn + timeout int + connection net.Conn } func (this *timedReaderWorker) Read(p []byte) (int, error) { - deadline := time.Duration(this.timeout) * time.Second + deadline := time.Duration(this.timeout) * time.Second this.connection.SetReadDeadline(time.Now().Add(deadline)) - nBytes, err := this.connection.Read(p) - this.connection.SetReadDeadline(emptyTime) - return nBytes, err + nBytes, err := this.connection.Read(p) + this.connection.SetReadDeadline(emptyTime) + return nBytes, err } type noOpReaderWorker struct { - connection net.Conn + connection net.Conn } func (this *noOpReaderWorker) Read(p []byte) (int, error) { - return this.connection.Read(p) + return this.connection.Read(p) } diff --git a/proxy/vmess/config/json/user.go b/proxy/vmess/config/json/user.go index 6c0e4cdd2..d48454521 100644 --- a/proxy/vmess/config/json/user.go +++ b/proxy/vmess/config/json/user.go @@ -8,16 +8,16 @@ import ( // ConfigUser is an user account in VMess configuration. type ConfigUser struct { - Id *config.ID - Email string - LevelValue config.UserLevel + Id *config.ID + Email string + LevelValue config.UserLevel } func (u *ConfigUser) UnmarshalJSON(data []byte) error { type rawUser struct { IdString string `json:"id"` EmailString string `json:"email"` - LevelInt int `json:"level"` + LevelInt int `json:"level"` } var rawUserValue rawUser if err := json.Unmarshal(data, &rawUserValue); err != nil { @@ -29,7 +29,7 @@ func (u *ConfigUser) UnmarshalJSON(data []byte) error { } u.Id = id u.Email = rawUserValue.EmailString - u.LevelValue = config.UserLevel(rawUserValue.LevelInt) + u.LevelValue = config.UserLevel(rawUserValue.LevelInt) return nil } @@ -38,5 +38,5 @@ func (u *ConfigUser) ID() *config.ID { } func (this *ConfigUser) Level() config.UserLevel { - return this.LevelValue -} \ No newline at end of file + return this.LevelValue +} diff --git a/proxy/vmess/config/user.go b/proxy/vmess/config/user.go index 26e55e6f9..0d407c1ba 100644 --- a/proxy/vmess/config/user.go +++ b/proxy/vmess/config/user.go @@ -3,25 +3,25 @@ package config type UserLevel int const ( - UserLevelAdmin = UserLevel(999) - UserLevelUntrusted = UserLevel(0) + UserLevelAdmin = UserLevel(999) + UserLevelUntrusted = UserLevel(0) ) type User interface { ID() *ID - Level() UserLevel + Level() UserLevel } type UserSettings struct { - PayloadReadTimeout int + PayloadReadTimeout int } func GetUserSettings(level UserLevel) UserSettings { - settings := UserSettings { - PayloadReadTimeout: 120, - } - if level > 0 { - settings.PayloadReadTimeout = 0 - } - return settings + settings := UserSettings{ + PayloadReadTimeout: 120, + } + if level > 0 { + settings.PayloadReadTimeout = 0 + } + return settings } diff --git a/proxy/vmess/protocol/user/userset.go b/proxy/vmess/protocol/user/userset.go index 707982fdb..2577f6f10 100644 --- a/proxy/vmess/protocol/user/userset.go +++ b/proxy/vmess/protocol/user/userset.go @@ -19,7 +19,7 @@ type UserSet interface { } type TimedUserSet struct { - validUsers []config.User + validUsers []config.User userHash map[string]indexTimePair userHashDeleteQueue *collect.TimedQueue access sync.RWMutex @@ -32,7 +32,7 @@ type indexTimePair struct { func NewTimedUserSet() UserSet { tus := &TimedUserSet{ - validUsers: make([]config.User, 0, 16), + validUsers: make([]config.User, 0, 16), userHash: make(map[string]indexTimePair, 512), userHashDeleteQueue: collect.NewTimedQueue(updateIntervalSec), access: sync.RWMutex{}, diff --git a/proxy/vmess/protocol/vmess.go b/proxy/vmess/protocol/vmess.go index 550a6a841..5ed7bdce7 100644 --- a/proxy/vmess/protocol/vmess.go +++ b/proxy/vmess/protocol/vmess.go @@ -37,7 +37,7 @@ const ( // streaming. type VMessRequest struct { Version byte - User config.User + User config.User RequestIV []byte RequestKey []byte ResponseHeader []byte @@ -98,7 +98,7 @@ func (r *VMessRequestReader) Read(reader io.Reader) (*VMessRequest, error) { bufferLen := nBytes request := &VMessRequest{ - User: userObj, + User: userObj, Version: buffer.Value[0], } diff --git a/proxy/vmess/protocol/vmess_test.go b/proxy/vmess/protocol/vmess_test.go index 43377510c..0fe691fcb 100644 --- a/proxy/vmess/protocol/vmess_test.go +++ b/proxy/vmess/protocol/vmess_test.go @@ -13,8 +13,8 @@ import ( ) type TestUser struct { - id *config.ID - level config.UserLevel + id *config.ID + level config.UserLevel } func (u *TestUser) ID() *config.ID { @@ -22,7 +22,7 @@ func (u *TestUser) ID() *config.ID { } func (this *TestUser) Level() config.UserLevel { - return this.level + return this.level } func TestVMessSerialization(t *testing.T) { @@ -32,10 +32,10 @@ func TestVMessSerialization(t *testing.T) { if err != nil { t.Fatal(err) } - - testUser := &TestUser { - id: userId, - } + + testUser := &TestUser{ + id: userId, + } userSet := mocks.MockUserSet{[]config.User{}, make(map[string]int), make(map[string]int64)} userSet.AddUser(testUser) @@ -82,10 +82,10 @@ func TestVMessSerialization(t *testing.T) { func BenchmarkVMessRequestWriting(b *testing.B) { userId, _ := config.NewID("2b2966ac-16aa-4fbf-8d81-c5f172a3da51") userSet := mocks.MockUserSet{[]config.User{}, make(map[string]int), make(map[string]int64)} - - testUser := &TestUser{ - id: userId, - } + + testUser := &TestUser{ + id: userId, + } userSet.AddUser(testUser) request := new(VMessRequest) diff --git a/proxy/vmess/vmessin.go b/proxy/vmess/vmessin.go index 6e049c5d8..eab449bc3 100644 --- a/proxy/vmess/vmessin.go +++ b/proxy/vmess/vmessin.go @@ -91,7 +91,7 @@ func (handler *VMessInboundHandler) HandleConnection(connection *net.TCPConn) er readFinish.Lock() writeFinish.Lock() - userSettings := config.GetUserSettings(request.User.Level()) + userSettings := config.GetUserSettings(request.User.Level()) connReader.SetTimeOut(userSettings.PayloadReadTimeout) go handleInput(request, connReader, input, &readFinish) diff --git a/proxy/vmess/vmessout.go b/proxy/vmess/vmessout.go index bf67e6927..76574afb0 100644 --- a/proxy/vmess/vmessout.go +++ b/proxy/vmess/vmessout.go @@ -67,7 +67,7 @@ func (handler *VMessOutboundHandler) Dispatch(firstPacket v2net.Packet, ray ray. } request := &protocol.VMessRequest{ Version: protocol.Version, - User: vNextUser, + User: vNextUser, Command: command, Address: firstPacket.Destination().Address(), } diff --git a/testing/mocks/mockuserset.go b/testing/mocks/mockuserset.go index f61cbbdea..d36e6d303 100644 --- a/testing/mocks/mockuserset.go +++ b/testing/mocks/mockuserset.go @@ -5,7 +5,7 @@ import ( ) type MockUserSet struct { - Users []config.User + Users []config.User UserHashes map[string]int Timestamps map[string]int64 }