Browse Source

Some minor fixes (#433)

Chinsyo 5 years ago
parent
commit
2ac380788b

+ 0 - 21
app/proxyman/proxyman.go

@@ -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
-}

+ 1 - 1
app/router/condition_geoip_test.go

@@ -5,7 +5,7 @@ import (
 	"path/filepath"
 	"path/filepath"
 	"testing"
 	"testing"
 
 
-	proto "github.com/golang/protobuf/proto"
+	"github.com/golang/protobuf/proto"
 	"v2ray.com/core/app/router"
 	"v2ray.com/core/app/router"
 	"v2ray.com/core/common"
 	"v2ray.com/core/common"
 	"v2ray.com/core/common/net"
 	"v2ray.com/core/common/net"

+ 1 - 1
app/router/condition_test.go

@@ -6,7 +6,7 @@ import (
 	"strconv"
 	"strconv"
 	"testing"
 	"testing"
 
 
-	proto "github.com/golang/protobuf/proto"
+	"github.com/golang/protobuf/proto"
 
 
 	. "v2ray.com/core/app/router"
 	. "v2ray.com/core/app/router"
 	"v2ray.com/core/common"
 	"v2ray.com/core/common"

+ 6 - 2
proxy/vmess/validator.go

@@ -113,6 +113,7 @@ func (v *TimedUserValidator) removeExpiredHashes(expire uint32) {
 func (v *TimedUserValidator) updateUserHash() {
 func (v *TimedUserValidator) updateUserHash() {
 	now := time.Now()
 	now := time.Now()
 	nowSec := protocol.Timestamp(now.Unix())
 	nowSec := protocol.Timestamp(now.Unix())
+
 	v.Lock()
 	v.Lock()
 	defer v.Unlock()
 	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) {
 func (v *TimedUserValidator) Get(userHash []byte) (*protocol.MemoryUser, protocol.Timestamp, bool, error) {
-	defer v.RUnlock()
 	v.RLock()
 	v.RLock()
+	defer v.RUnlock()
 
 
 	v.behaviorFused = true
 	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) {
 func (v *TimedUserValidator) GetAEAD(userHash []byte) (*protocol.MemoryUser, bool, error) {
-	defer v.RUnlock()
 	v.RLock()
 	v.RLock()
+	defer v.RUnlock()
+
 	var userHashFL [16]byte
 	var userHashFL [16]byte
 	copy(userHashFL[:], userHash)
 	copy(userHashFL[:], userHash)
 
 
@@ -220,6 +222,7 @@ func (v *TimedUserValidator) Close() error {
 func (v *TimedUserValidator) GetBehaviorSeed() uint64 {
 func (v *TimedUserValidator) GetBehaviorSeed() uint64 {
 	v.Lock()
 	v.Lock()
 	defer v.Unlock()
 	defer v.Unlock()
+
 	v.behaviorFused = true
 	v.behaviorFused = true
 	if v.behaviorSeed == 0 {
 	if v.behaviorSeed == 0 {
 		v.behaviorSeed = dice.RollUint64()
 		v.behaviorSeed = dice.RollUint64()
@@ -230,6 +233,7 @@ func (v *TimedUserValidator) GetBehaviorSeed() uint64 {
 func (v *TimedUserValidator) BurnTaintFuse(userHash []byte) error {
 func (v *TimedUserValidator) BurnTaintFuse(userHash []byte) error {
 	v.RLock()
 	v.RLock()
 	defer v.RUnlock()
 	defer v.RUnlock()
+
 	var userHashFL [16]byte
 	var userHashFL [16]byte
 	copy(userHashFL[:], userHash)
 	copy(userHashFL[:], userHash)
 
 

+ 2 - 13
transport/internet/headers/http/http_test.go

@@ -29,15 +29,10 @@ func TestReaderWriter(t *testing.T) {
 	common.Must(err)
 	common.Must(err)
 
 
 	reader := &HeaderReader{}
 	reader := &HeaderReader{}
-	buffer, err := reader.Read(cache)
+	_, err = reader.Read(cache)
 	if err != nil && !strings.HasPrefix(err.Error(), "malformed HTTP request") {
 	if err != nil && !strings.HasPrefix(err.Error(), "malformed HTTP request") {
 		t.Error("unknown error ", err)
 		t.Error("unknown error ", err)
 	}
 	}
-	_ = buffer
-	/*
-		if buffer.String() != "efg" {
-			t.Error("buffer: ", buffer.String())
-		}*/
 }
 }
 
 
 func TestRequestHeader(t *testing.T) {
 func TestRequestHeader(t *testing.T) {
@@ -70,17 +65,11 @@ func TestLongRequestHeader(t *testing.T) {
 	payload = append(payload, []byte("abcd")...)
 	payload = append(payload, []byte("abcd")...)
 
 
 	reader := HeaderReader{}
 	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")) {
 	if err != nil && !(strings.HasPrefix(err.Error(), "invalid") || strings.HasPrefix(err.Error(), "malformed")) {
 		t.Error("unknown error ", err)
 		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) {
 func TestConnection(t *testing.T) {

+ 1 - 1
v2ray_test.go

@@ -3,7 +3,7 @@ package core_test
 import (
 import (
 	"testing"
 	"testing"
 
 
-	proto "github.com/golang/protobuf/proto"
+	"github.com/golang/protobuf/proto"
 	. "v2ray.com/core"
 	. "v2ray.com/core"
 	"v2ray.com/core/app/dispatcher"
 	"v2ray.com/core/app/dispatcher"
 	"v2ray.com/core/app/proxyman"
 	"v2ray.com/core/app/proxyman"