mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-17 06:46:33 -05:00
Fix lint
This commit is contained in:
parent
ebee459f1f
commit
fc6ae4d4e7
2
.github/linters/.golangci.yml
vendored
2
.github/linters/.golangci.yml
vendored
@ -2,6 +2,8 @@ run:
|
|||||||
timeout: 5m
|
timeout: 5m
|
||||||
skip-files:
|
skip-files:
|
||||||
- generated.*
|
- generated.*
|
||||||
|
- .*_test.go
|
||||||
|
- proxy/vlite/*
|
||||||
|
|
||||||
issues:
|
issues:
|
||||||
new: true
|
new: true
|
||||||
|
@ -4,11 +4,13 @@ package command
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
grpc "google.golang.org/grpc"
|
||||||
|
|
||||||
core "github.com/v2fly/v2ray-core/v5"
|
core "github.com/v2fly/v2ray-core/v5"
|
||||||
"github.com/v2fly/v2ray-core/v5/app/log"
|
"github.com/v2fly/v2ray-core/v5/app/log"
|
||||||
"github.com/v2fly/v2ray-core/v5/common"
|
"github.com/v2fly/v2ray-core/v5/common"
|
||||||
cmlog "github.com/v2fly/v2ray-core/v5/common/log"
|
cmlog "github.com/v2fly/v2ray-core/v5/common/log"
|
||||||
grpc "google.golang.org/grpc"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// LoggerServer is the implemention of LoggerService
|
// LoggerServer is the implemention of LoggerService
|
||||||
|
@ -7,64 +7,64 @@ import (
|
|||||||
/*
|
/*
|
||||||
Split into multiple package, need to be tested separately
|
Split into multiple package, need to be tested separately
|
||||||
|
|
||||||
func TestSelectLeastLoad(t *testing.T) {
|
func TestSelectLeastLoad(t *testing.T) {
|
||||||
settings := &StrategyLeastLoadConfig{
|
settings := &StrategyLeastLoadConfig{
|
||||||
HealthCheck: &HealthPingConfig{
|
HealthCheck: &HealthPingConfig{
|
||||||
SamplingCount: 10,
|
SamplingCount: 10,
|
||||||
},
|
},
|
||||||
Expected: 1,
|
Expected: 1,
|
||||||
MaxRTT: int64(time.Millisecond * time.Duration(800)),
|
MaxRTT: int64(time.Millisecond * time.Duration(800)),
|
||||||
|
}
|
||||||
|
strategy := NewLeastLoadStrategy(settings)
|
||||||
|
// std 40
|
||||||
|
strategy.PutResult("a", time.Millisecond*time.Duration(60))
|
||||||
|
strategy.PutResult("a", time.Millisecond*time.Duration(140))
|
||||||
|
strategy.PutResult("a", time.Millisecond*time.Duration(60))
|
||||||
|
strategy.PutResult("a", time.Millisecond*time.Duration(140))
|
||||||
|
// std 60
|
||||||
|
strategy.PutResult("b", time.Millisecond*time.Duration(40))
|
||||||
|
strategy.PutResult("b", time.Millisecond*time.Duration(160))
|
||||||
|
strategy.PutResult("b", time.Millisecond*time.Duration(40))
|
||||||
|
strategy.PutResult("b", time.Millisecond*time.Duration(160))
|
||||||
|
// std 0, but >MaxRTT
|
||||||
|
strategy.PutResult("c", time.Millisecond*time.Duration(1000))
|
||||||
|
strategy.PutResult("c", time.Millisecond*time.Duration(1000))
|
||||||
|
strategy.PutResult("c", time.Millisecond*time.Duration(1000))
|
||||||
|
strategy.PutResult("c", time.Millisecond*time.Duration(1000))
|
||||||
|
expected := "a"
|
||||||
|
actual := strategy.SelectAndPick([]string{"a", "b", "c", "untested"})
|
||||||
|
if actual != expected {
|
||||||
|
t.Errorf("expected: %v, actual: %v", expected, actual)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
strategy := NewLeastLoadStrategy(settings)
|
|
||||||
// std 40
|
|
||||||
strategy.PutResult("a", time.Millisecond*time.Duration(60))
|
|
||||||
strategy.PutResult("a", time.Millisecond*time.Duration(140))
|
|
||||||
strategy.PutResult("a", time.Millisecond*time.Duration(60))
|
|
||||||
strategy.PutResult("a", time.Millisecond*time.Duration(140))
|
|
||||||
// std 60
|
|
||||||
strategy.PutResult("b", time.Millisecond*time.Duration(40))
|
|
||||||
strategy.PutResult("b", time.Millisecond*time.Duration(160))
|
|
||||||
strategy.PutResult("b", time.Millisecond*time.Duration(40))
|
|
||||||
strategy.PutResult("b", time.Millisecond*time.Duration(160))
|
|
||||||
// std 0, but >MaxRTT
|
|
||||||
strategy.PutResult("c", time.Millisecond*time.Duration(1000))
|
|
||||||
strategy.PutResult("c", time.Millisecond*time.Duration(1000))
|
|
||||||
strategy.PutResult("c", time.Millisecond*time.Duration(1000))
|
|
||||||
strategy.PutResult("c", time.Millisecond*time.Duration(1000))
|
|
||||||
expected := "a"
|
|
||||||
actual := strategy.SelectAndPick([]string{"a", "b", "c", "untested"})
|
|
||||||
if actual != expected {
|
|
||||||
t.Errorf("expected: %v, actual: %v", expected, actual)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSelectLeastLoadWithCost(t *testing.T) {
|
func TestSelectLeastLoadWithCost(t *testing.T) {
|
||||||
settings := &StrategyLeastLoadConfig{
|
settings := &StrategyLeastLoadConfig{
|
||||||
HealthCheck: &HealthPingConfig{
|
HealthCheck: &HealthPingConfig{
|
||||||
SamplingCount: 10,
|
SamplingCount: 10,
|
||||||
},
|
},
|
||||||
Costs: []*StrategyWeight{
|
Costs: []*StrategyWeight{
|
||||||
{Match: "a", Value: 9},
|
{Match: "a", Value: 9},
|
||||||
},
|
},
|
||||||
Expected: 1,
|
Expected: 1,
|
||||||
|
}
|
||||||
|
strategy := NewLeastLoadStrategy(settings, nil)
|
||||||
|
// std 40, std+c 120
|
||||||
|
strategy.PutResult("a", time.Millisecond*time.Duration(60))
|
||||||
|
strategy.PutResult("a", time.Millisecond*time.Duration(140))
|
||||||
|
strategy.PutResult("a", time.Millisecond*time.Duration(60))
|
||||||
|
strategy.PutResult("a", time.Millisecond*time.Duration(140))
|
||||||
|
// std 60
|
||||||
|
strategy.PutResult("b", time.Millisecond*time.Duration(40))
|
||||||
|
strategy.PutResult("b", time.Millisecond*time.Duration(160))
|
||||||
|
strategy.PutResult("b", time.Millisecond*time.Duration(40))
|
||||||
|
strategy.PutResult("b", time.Millisecond*time.Duration(160))
|
||||||
|
expected := "b"
|
||||||
|
actual := strategy.SelectAndPick([]string{"a", "b", "untested"})
|
||||||
|
if actual != expected {
|
||||||
|
t.Errorf("expected: %v, actual: %v", expected, actual)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
strategy := NewLeastLoadStrategy(settings, nil)
|
|
||||||
// std 40, std+c 120
|
|
||||||
strategy.PutResult("a", time.Millisecond*time.Duration(60))
|
|
||||||
strategy.PutResult("a", time.Millisecond*time.Duration(140))
|
|
||||||
strategy.PutResult("a", time.Millisecond*time.Duration(60))
|
|
||||||
strategy.PutResult("a", time.Millisecond*time.Duration(140))
|
|
||||||
// std 60
|
|
||||||
strategy.PutResult("b", time.Millisecond*time.Duration(40))
|
|
||||||
strategy.PutResult("b", time.Millisecond*time.Duration(160))
|
|
||||||
strategy.PutResult("b", time.Millisecond*time.Duration(40))
|
|
||||||
strategy.PutResult("b", time.Millisecond*time.Duration(160))
|
|
||||||
expected := "b"
|
|
||||||
actual := strategy.SelectAndPick([]string{"a", "b", "untested"})
|
|
||||||
if actual != expected {
|
|
||||||
t.Errorf("expected: %v, actual: %v", expected, actual)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
*/
|
||||||
func TestSelectLeastExpected(t *testing.T) {
|
func TestSelectLeastExpected(t *testing.T) {
|
||||||
strategy := &LeastLoadStrategy{
|
strategy := &LeastLoadStrategy{
|
||||||
|
@ -7,7 +7,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func ContextWithEnvironment(ctx context.Context, environment interface{}) context.Context {
|
func ContextWithEnvironment(ctx context.Context, environment interface{}) context.Context {
|
||||||
return context.WithValue(ctx, environmentKey, environment) //nolint: revive
|
return context.WithValue(ctx, environmentKey, environment) //nolint: revive,staticcheck
|
||||||
}
|
}
|
||||||
|
|
||||||
func EnvironmentFromContext(ctx context.Context) interface{} {
|
func EnvironmentFromContext(ctx context.Context) interface{} {
|
||||||
|
@ -216,9 +216,9 @@ func (ac *ACAutomatonMatcherGroup) MatchAny(input string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Letter-Digit-Hyphen (LDH) subset (https://tools.ietf.org/html/rfc952):
|
// Letter-Digit-Hyphen (LDH) subset (https://tools.ietf.org/html/rfc952):
|
||||||
// * Letters A to Z (no distinction is made between uppercase and lowercase)
|
// - Letters A to Z (no distinction is made between uppercase and lowercase)
|
||||||
// * Digits 0 to 9
|
// - Digits 0 to 9
|
||||||
// * Hyphens(-) and Periods(.)
|
// - Hyphens(-) and Periods(.)
|
||||||
//
|
//
|
||||||
// If for future the strmatcher are used for other scenarios than domain,
|
// If for future the strmatcher are used for other scenarios than domain,
|
||||||
// we could add a new Charset interface to represent variable charsets.
|
// we could add a new Charset interface to represent variable charsets.
|
||||||
|
@ -15,7 +15,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Matcher is the interface to determine a string matches a pattern.
|
// Matcher is the interface to determine a string matches a pattern.
|
||||||
// * This is a basic matcher to represent a certain kind of match semantic(full, substr, domain or regex).
|
// - This is a basic matcher to represent a certain kind of match semantic(full, substr, domain or regex).
|
||||||
type Matcher interface {
|
type Matcher interface {
|
||||||
// Type returns the matcher's type.
|
// Type returns the matcher's type.
|
||||||
Type() Type
|
Type() Type
|
||||||
@ -34,8 +34,8 @@ type Matcher interface {
|
|||||||
|
|
||||||
// MatcherGroup is an advanced type of matcher to accept a bunch of basic Matchers (of certain type, not all matcher types).
|
// MatcherGroup is an advanced type of matcher to accept a bunch of basic Matchers (of certain type, not all matcher types).
|
||||||
// For example:
|
// For example:
|
||||||
// * FullMatcherGroup accepts FullMatcher and uses a hash table to facilitate lookup.
|
// - FullMatcherGroup accepts FullMatcher and uses a hash table to facilitate lookup.
|
||||||
// * DomainMatcherGroup accepts DomainMatcher and uses a trie to optimize both memory consumption and lookup speed.
|
// - DomainMatcherGroup accepts DomainMatcher and uses a trie to optimize both memory consumption and lookup speed.
|
||||||
type MatcherGroup interface {
|
type MatcherGroup interface {
|
||||||
// Match returns all matched matchers with their corresponding values.
|
// Match returns all matched matchers with their corresponding values.
|
||||||
Match(input string) []uint32
|
Match(input string) []uint32
|
||||||
@ -46,9 +46,9 @@ type MatcherGroup interface {
|
|||||||
|
|
||||||
// IndexMatcher is a general type of matcher thats accepts all kinds of basic matchers.
|
// IndexMatcher is a general type of matcher thats accepts all kinds of basic matchers.
|
||||||
// It should:
|
// It should:
|
||||||
// * Accept all Matcher types with no exception.
|
// - Accept all Matcher types with no exception.
|
||||||
// * Optimize string matching with a combination of MatcherGroups.
|
// - Optimize string matching with a combination of MatcherGroups.
|
||||||
// * Obey certain priority order specification when returning matched Matchers.
|
// - Obey certain priority order specification when returning matched Matchers.
|
||||||
type IndexMatcher interface {
|
type IndexMatcher interface {
|
||||||
// Size returns number of matchers added to IndexMatcher.
|
// Size returns number of matchers added to IndexMatcher.
|
||||||
Size() uint32
|
Size() uint32
|
||||||
|
@ -26,7 +26,8 @@ func MustFromContext(ctx context.Context) *Instance {
|
|||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
/* toContext returns ctx from the given context, or creates an Instance if the context doesn't find that.
|
/*
|
||||||
|
toContext returns ctx from the given context, or creates an Instance if the context doesn't find that.
|
||||||
|
|
||||||
It is unsupported to use this function to create a context that is suitable to invoke V2Ray's internal component
|
It is unsupported to use this function to create a context that is suitable to invoke V2Ray's internal component
|
||||||
in third party code, you shouldn't use //go:linkname to alias of this function into your own package and
|
in third party code, you shouldn't use //go:linkname to alias of this function into your own package and
|
||||||
@ -34,7 +35,6 @@ use this function in your third party code.
|
|||||||
|
|
||||||
For third party code, usage enabled by creating a context to interact with V2Ray's internal component is unsupported,
|
For third party code, usage enabled by creating a context to interact with V2Ray's internal component is unsupported,
|
||||||
and may break at any time.
|
and may break at any time.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
func toContext(ctx context.Context, v *Instance) context.Context {
|
func toContext(ctx context.Context, v *Instance) context.Context {
|
||||||
if FromContext(ctx) != v {
|
if FromContext(ctx) != v {
|
||||||
@ -43,7 +43,8 @@ func toContext(ctx context.Context, v *Instance) context.Context {
|
|||||||
return ctx
|
return ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
/*ToBackgroundDetachedContext create a detached context from another context
|
/*
|
||||||
|
ToBackgroundDetachedContext create a detached context from another context
|
||||||
Internal API
|
Internal API
|
||||||
*/
|
*/
|
||||||
func ToBackgroundDetachedContext(ctx context.Context) context.Context {
|
func ToBackgroundDetachedContext(ctx context.Context) context.Context {
|
||||||
|
@ -11,7 +11,6 @@ Merge Rules:
|
|||||||
- Simple values (string, number, boolean) are overwritten, others are merged
|
- Simple values (string, number, boolean) are overwritten, others are merged
|
||||||
- Elements with same "tag" (or "_tag") in an array will be merged
|
- Elements with same "tag" (or "_tag") in an array will be merged
|
||||||
- Add "_priority" property to array elements will help sort the
|
- Add "_priority" property to array elements will help sort the
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package merge
|
package merge
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
func loadHeterogeneousConfigFromRawJSON(interfaceType, name string, rawJSON json.RawMessage) (proto.Message, error) {
|
func loadHeterogeneousConfigFromRawJSON(interfaceType, name string, rawJSON json.RawMessage) (proto.Message, error) {
|
||||||
fsdef := envimpl.NewDefaultFileSystemDefaultImpl()
|
fsdef := envimpl.NewDefaultFileSystemDefaultImpl()
|
||||||
ctx := envctx.ContextWithEnvironment(context.TODO(), fsdef)
|
ctx := envctx.ContextWithEnvironment(context.TODO(), fsdef)
|
||||||
if rawJSON == nil || len(rawJSON) == 0 {
|
if len(rawJSON) == 0 {
|
||||||
rawJSON = []byte("{}")
|
rawJSON = []byte("{}")
|
||||||
}
|
}
|
||||||
return registry.LoadImplementationByAlias(ctx, interfaceType, name, []byte(rawJSON))
|
return registry.LoadImplementationByAlias(ctx, interfaceType, name, []byte(rawJSON))
|
||||||
|
@ -6,6 +6,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"crypto/hmac"
|
"crypto/hmac"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
|
"hash/crc64"
|
||||||
|
|
||||||
core "github.com/v2fly/v2ray-core/v5"
|
core "github.com/v2fly/v2ray-core/v5"
|
||||||
"github.com/v2fly/v2ray-core/v5/common"
|
"github.com/v2fly/v2ray-core/v5/common"
|
||||||
"github.com/v2fly/v2ray-core/v5/common/buf"
|
"github.com/v2fly/v2ray-core/v5/common/buf"
|
||||||
@ -23,7 +25,6 @@ import (
|
|||||||
"github.com/v2fly/v2ray-core/v5/proxy/vmess/encoding"
|
"github.com/v2fly/v2ray-core/v5/proxy/vmess/encoding"
|
||||||
"github.com/v2fly/v2ray-core/v5/transport"
|
"github.com/v2fly/v2ray-core/v5/transport"
|
||||||
"github.com/v2fly/v2ray-core/v5/transport/internet"
|
"github.com/v2fly/v2ray-core/v5/transport/internet"
|
||||||
"hash/crc64"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Handler is an outbound connection handler for VMess protocol.
|
// Handler is an outbound connection handler for VMess protocol.
|
||||||
|
@ -252,7 +252,9 @@ func (v *TimedUserValidator) BurnTaintFuse(userHash []byte) error {
|
|||||||
return ErrNotFound
|
return ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ShouldShowLegacyWarn will return whether a Legacy Warning should be shown
|
/*
|
||||||
|
ShouldShowLegacyWarn will return whether a Legacy Warning should be shown
|
||||||
|
|
||||||
Not guaranteed to only return true once for every inbound, but it is okay.
|
Not guaranteed to only return true once for every inbound, but it is okay.
|
||||||
*/
|
*/
|
||||||
func (v *TimedUserValidator) ShouldShowLegacyWarn() bool {
|
func (v *TimedUserValidator) ShouldShowLegacyWarn() bool {
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
// Package kcp - A Fast and Reliable ARQ Protocol
|
// Package kcp - A Fast and Reliable ARQ Protocol
|
||||||
//
|
//
|
||||||
// Acknowledgement:
|
// Acknowledgement:
|
||||||
// skywind3000@github for inventing the KCP protocol
|
//
|
||||||
// xtaci@github for translating to Golang
|
// skywind3000@github for inventing the KCP protocol
|
||||||
|
// xtaci@github for translating to Golang
|
||||||
package kcp
|
package kcp
|
||||||
|
|
||||||
//go:generate go run github.com/v2fly/v2ray-core/v5/common/errors/errorgen
|
//go:generate go run github.com/v2fly/v2ray-core/v5/common/errors/errorgen
|
||||||
|
@ -10,13 +10,17 @@ import (
|
|||||||
|
|
||||||
const SystemDNS = "8.8.8.8:53"
|
const SystemDNS = "8.8.8.8:53"
|
||||||
|
|
||||||
/* DNSResolverFunc
|
/*
|
||||||
This is a temporary API and is subject to removal at any time.
|
DNSResolverFunc
|
||||||
|
|
||||||
|
This is a temporary API and is subject to removal at any time.
|
||||||
*/
|
*/
|
||||||
type DNSResolverFunc func() *net.Resolver
|
type DNSResolverFunc func() *net.Resolver
|
||||||
|
|
||||||
/* NewDNSResolver
|
/*
|
||||||
This is a temporary API and is subject to removal at any time.
|
NewDNSResolver
|
||||||
|
|
||||||
|
This is a temporary API and is subject to removal at any time.
|
||||||
*/
|
*/
|
||||||
var NewDNSResolver DNSResolverFunc = func() *net.Resolver {
|
var NewDNSResolver DNSResolverFunc = func() *net.Resolver {
|
||||||
return &net.Resolver{
|
return &net.Resolver{
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
/*Package websocket implements Websocket transport
|
/*
|
||||||
|
Package websocket implements Websocket transport
|
||||||
|
|
||||||
Websocket transport implements an HTTP(S) compliable, surveillance proof transport method with plausible deniability.
|
Websocket transport implements an HTTP(S) compliable, surveillance proof transport method with plausible deniability.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user