From 2ac380788b6ff4e1d589025958fec6ad24eb45bc Mon Sep 17 00:00:00 2001 From: Chinsyo Date: Fri, 20 Nov 2020 01:02:52 +0800 Subject: [PATCH] Some minor fixes (#433) --- app/proxyman/proxyman.go | 21 -------------------- app/router/condition_geoip_test.go | 2 +- app/router/condition_test.go | 2 +- proxy/vmess/validator.go | 8 ++++++-- transport/internet/headers/http/http_test.go | 15 ++------------ v2ray_test.go | 2 +- 6 files changed, 11 insertions(+), 39 deletions(-) delete mode 100644 app/proxyman/proxyman.go diff --git a/app/proxyman/proxyman.go b/app/proxyman/proxyman.go deleted file mode 100644 index f83afcea8..000000000 --- a/app/proxyman/proxyman.go +++ /dev/null @@ -1,21 +0,0 @@ -// Package proxyman defines applications for managing inbound and outbound proxies. -package proxyman - -import ( - "context" - - "v2ray.com/core/common/session" -) - -// ContextWithSniffingConfig is a wrapper of session.ContextWithContent. -// Deprecated. Use session.ContextWithContent directly. -func ContextWithSniffingConfig(ctx context.Context, c *SniffingConfig) context.Context { - content := session.ContentFromContext(ctx) - if content == nil { - content = new(session.Content) - ctx = session.ContextWithContent(ctx, content) - } - content.SniffingRequest.Enabled = c.Enabled - content.SniffingRequest.OverrideDestinationForProtocol = c.DestinationOverride - return ctx -} diff --git a/app/router/condition_geoip_test.go b/app/router/condition_geoip_test.go index c92d990b3..9c73393ea 100644 --- a/app/router/condition_geoip_test.go +++ b/app/router/condition_geoip_test.go @@ -5,7 +5,7 @@ import ( "path/filepath" "testing" - proto "github.com/golang/protobuf/proto" + "github.com/golang/protobuf/proto" "v2ray.com/core/app/router" "v2ray.com/core/common" "v2ray.com/core/common/net" diff --git a/app/router/condition_test.go b/app/router/condition_test.go index af055bb4e..05d734669 100644 --- a/app/router/condition_test.go +++ b/app/router/condition_test.go @@ -6,7 +6,7 @@ import ( "strconv" "testing" - proto "github.com/golang/protobuf/proto" + "github.com/golang/protobuf/proto" . "v2ray.com/core/app/router" "v2ray.com/core/common" diff --git a/proxy/vmess/validator.go b/proxy/vmess/validator.go index 512337448..9f21f5974 100644 --- a/proxy/vmess/validator.go +++ b/proxy/vmess/validator.go @@ -113,6 +113,7 @@ func (v *TimedUserValidator) removeExpiredHashes(expire uint32) { func (v *TimedUserValidator) updateUserHash() { now := time.Now() nowSec := protocol.Timestamp(now.Unix()) + v.Lock() defer v.Unlock() @@ -154,8 +155,8 @@ func (v *TimedUserValidator) Add(u *protocol.MemoryUser) error { } func (v *TimedUserValidator) Get(userHash []byte) (*protocol.MemoryUser, protocol.Timestamp, bool, error) { - defer v.RUnlock() v.RLock() + defer v.RUnlock() v.behaviorFused = true @@ -173,8 +174,9 @@ func (v *TimedUserValidator) Get(userHash []byte) (*protocol.MemoryUser, protoco } func (v *TimedUserValidator) GetAEAD(userHash []byte) (*protocol.MemoryUser, bool, error) { - defer v.RUnlock() v.RLock() + defer v.RUnlock() + var userHashFL [16]byte copy(userHashFL[:], userHash) @@ -220,6 +222,7 @@ func (v *TimedUserValidator) Close() error { func (v *TimedUserValidator) GetBehaviorSeed() uint64 { v.Lock() defer v.Unlock() + v.behaviorFused = true if v.behaviorSeed == 0 { v.behaviorSeed = dice.RollUint64() @@ -230,6 +233,7 @@ func (v *TimedUserValidator) GetBehaviorSeed() uint64 { func (v *TimedUserValidator) BurnTaintFuse(userHash []byte) error { v.RLock() defer v.RUnlock() + var userHashFL [16]byte copy(userHashFL[:], userHash) diff --git a/transport/internet/headers/http/http_test.go b/transport/internet/headers/http/http_test.go index 95b180bfb..13db12386 100644 --- a/transport/internet/headers/http/http_test.go +++ b/transport/internet/headers/http/http_test.go @@ -29,15 +29,10 @@ func TestReaderWriter(t *testing.T) { common.Must(err) reader := &HeaderReader{} - buffer, err := reader.Read(cache) + _, err = reader.Read(cache) if err != nil && !strings.HasPrefix(err.Error(), "malformed HTTP request") { t.Error("unknown error ", err) } - _ = buffer - /* - if buffer.String() != "efg" { - t.Error("buffer: ", buffer.String()) - }*/ } func TestRequestHeader(t *testing.T) { @@ -70,17 +65,11 @@ func TestLongRequestHeader(t *testing.T) { payload = append(payload, []byte("abcd")...) reader := HeaderReader{} - b, err := reader.Read(bytes.NewReader(payload)) + _, err := reader.Read(bytes.NewReader(payload)) if err != nil && !(strings.HasPrefix(err.Error(), "invalid") || strings.HasPrefix(err.Error(), "malformed")) { t.Error("unknown error ", err) } - _ = b - /* - common.Must(err) - if b.String() != "abcd" { - t.Error("expect content abcd, but actually ", b.String()) - }*/ } func TestConnection(t *testing.T) { diff --git a/v2ray_test.go b/v2ray_test.go index 982f44ed5..7bb1a7cc9 100644 --- a/v2ray_test.go +++ b/v2ray_test.go @@ -3,7 +3,7 @@ package core_test import ( "testing" - proto "github.com/golang/protobuf/proto" + "github.com/golang/protobuf/proto" . "v2ray.com/core" "v2ray.com/core/app/dispatcher" "v2ray.com/core/app/proxyman"