1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 09:36:34 -05:00

Chore: format code to fix lint (#1426)

This commit is contained in:
Loyalsoldier 2021-11-27 14:32:07 +08:00 committed by GitHub
parent cbb6d7a509
commit 43447aa2e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
47 changed files with 55 additions and 78 deletions

View File

@ -86,8 +86,7 @@ func (f DNSThenOthersSniffResult) Domain() string {
return f.domainName
}
func newFakeDNSThenOthers(ctx context.Context, fakeDNSSniffer protocolSnifferWithMetadata, others []protocolSnifferWithMetadata) (
protocolSnifferWithMetadata, error) { // nolint: unparam
func newFakeDNSThenOthers(ctx context.Context, fakeDNSSniffer protocolSnifferWithMetadata, others []protocolSnifferWithMetadata) (protocolSnifferWithMetadata, error) { // nolint: unparam
// ctx may be used in the future
_ = ctx
return protocolSnifferWithMetadata{

View File

@ -316,7 +316,6 @@ func init() {
}))
common.Must(common.RegisterConfig((*SimplifiedConfig)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
ctx = cfgcommon.NewConfigureLoadingContext(context.Background())
geoloadername := platform.NewEnvFlag("v2ray.conf.geoloader").GetValue(func() string {

View File

@ -23,7 +23,6 @@ type Instance struct {
// New creates a new log.Instance based on the given config.
func New(ctx context.Context, config *Config) (*Instance, error) {
if config.Error == nil {
config.Error = &LogSpecification{Type: LogType_Console, Level: log.Severity_Warning}
}

View File

@ -66,7 +66,6 @@ func (o *Observer) Start() error {
o.hp.StartScheduler(func() ([]string, error) {
hs, ok := o.ohm.(outbound.HandlerSelector)
if !ok {
return nil, newError("outbound.Manager is not a HandlerSelector")
}

View File

@ -152,7 +152,7 @@ func (p *StaticMuxPicker) PickAvailable() (*mux.ClientWorker, error) {
return nil, newError("empty worker list")
}
var minIdx = -1
minIdx := -1
var minConn uint32 = 9999
for i, w := range p.workers {
if w.draining {

View File

@ -85,6 +85,7 @@ func TestSelectLeastExpected(t *testing.T) {
t.Errorf("expected: %v, actual: %v", expected, len(ns))
}
}
func TestSelectLeastExpected2(t *testing.T) {
strategy := &LeastLoadStrategy{
settings: &StrategyLeastLoadConfig{
@ -102,6 +103,7 @@ func TestSelectLeastExpected2(t *testing.T) {
t.Errorf("expected: %v, actual: %v", expected, len(ns))
}
}
func TestSelectLeastExpectedAndBaselines(t *testing.T) {
strategy := &LeastLoadStrategy{
settings: &StrategyLeastLoadConfig{
@ -122,6 +124,7 @@ func TestSelectLeastExpectedAndBaselines(t *testing.T) {
t.Errorf("expected: %v, actual: %v", expected, len(ns))
}
}
func TestSelectLeastExpectedAndBaselines2(t *testing.T) {
strategy := &LeastLoadStrategy{
settings: &StrategyLeastLoadConfig{
@ -142,6 +145,7 @@ func TestSelectLeastExpectedAndBaselines2(t *testing.T) {
t.Errorf("expected: %v, actual: %v", expected, len(ns))
}
}
func TestSelectLeastLoadBaselines(t *testing.T) {
strategy := &LeastLoadStrategy{
settings: &StrategyLeastLoadConfig{
@ -160,6 +164,7 @@ func TestSelectLeastLoadBaselines(t *testing.T) {
t.Errorf("expected: %v, actual: %v", expected, len(ns))
}
}
func TestSelectLeastLoadBaselinesNoQualified(t *testing.T) {
strategy := &LeastLoadStrategy{
settings: &StrategyLeastLoadConfig{

View File

@ -3,7 +3,7 @@ package internal
import "encoding/binary"
func ChaCha20Block(s *[16]uint32, out []byte, rounds int) {
var x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15 = s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11], s[12], s[13], s[14], s[15]
x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15 := s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11], s[12], s[13], s[14], s[15]
for i := 0; i < rounds; i += 2 {
var x uint32

View File

@ -9,14 +9,12 @@ type AppEnvironmentCapabilitySet interface {
SystemNetworkCapabilitySet
InstanceNetworkCapabilitySet
FileSystemCapabilitySet
PersistentStorage() storage.ScopedPersistentStorage
TransientStorage() storage.ScopedTransientStorage
}
type AppEnvironment interface {
AppEnvironmentCapabilitySet
NarrowScope(key []byte) (AppEnvironment, error)
doNotImpl()
}

View File

@ -8,7 +8,6 @@ type ConnectionCapabilitySet interface {
type ConnectionEnvironment interface {
ConnectionCapabilitySet
doNotImpl()
}

View File

@ -6,8 +6,7 @@ import (
"github.com/v2fly/v2ray-core/v4/common/platform/filesystem/fsifce"
)
type fileSystemDefaultImpl struct {
}
type fileSystemDefaultImpl struct{}
func (f fileSystemDefaultImpl) OpenFileForReadSeek() fsifce.FileSeekerFunc {
return filesystem.NewFileSeeker

View File

@ -7,15 +7,12 @@ import (
type ProxyEnvironmentCapabilitySet interface {
BaseEnvironmentCapabilitySet
InstanceNetworkCapabilitySet
TransientStorage() storage.ScopedTransientStorage
}
type ProxyEnvironment interface {
ProxyEnvironmentCapabilitySet
NarrowScope(key []byte) (ProxyEnvironment, error)
NarrowScopeToTransport(key []byte) (TransportEnvironment, error)
doNotImpl()
}

View File

@ -8,13 +8,11 @@ type TransportEnvironmentCapacitySet interface {
BaseEnvironmentCapabilitySet
SystemNetworkCapabilitySet
InstanceNetworkCapabilitySet
TransientStorage() storage.ScopedTransientStorage
}
type TransportEnvironment interface {
TransportEnvironmentCapacitySet
NarrowScope(key []byte) (TransportEnvironment, error)
doNotImpl()
}

View File

@ -42,7 +42,6 @@ func Interrupt(obj interface{}) error {
type Runnable interface {
// Start starts the runnable object. Upon the method returning nil, the object begins to function properly.
Start() error
Closable
}

View File

@ -66,7 +66,6 @@ type Address interface {
IP() net.IP // IP of this Address
Domain() string // Domain of this Address
Family() AddressFamily
String() string // String representation of this Address
}

View File

@ -37,7 +37,6 @@ func WithAddressTypeParser(atp AddressTypeParser) AddressOption {
type AddressSerializer interface {
ReadAddressPort(buffer *buf.Buffer, input io.Reader) (net.Address, net.Port, error)
WriteAddressPort(writer io.Writer, addr net.Address, port net.Port) error
}

View File

@ -6,9 +6,8 @@ import (
"math"
"time"
"github.com/v2fly/v2ray-core/v4/common/buf"
"github.com/v2fly/v2ray-core/v4/common"
"github.com/v2fly/v2ray-core/v4/common/buf"
)
type SniffHeader struct{}

View File

@ -7,14 +7,13 @@ import (
"encoding/binary"
"io"
"github.com/v2fly/v2ray-core/v4/common/errors"
"github.com/lucas-clemente/quic-go/quicvarint"
"github.com/marten-seemann/qtls-go1-17"
"golang.org/x/crypto/hkdf"
"github.com/v2fly/v2ray-core/v4/common"
"github.com/v2fly/v2ray-core/v4/common/buf"
"github.com/v2fly/v2ray-core/v4/common/errors"
ptls "github.com/v2fly/v2ray-core/v4/common/protocol/tls"
)

View File

@ -77,7 +77,6 @@ func (i *implementationRegistry) LoadImplementationByAlias(ctx context.Context,
}
return implementationConfigInstance.(proto.Message), nil
}
func newImplementationRegistry() *implementationRegistry {
@ -107,7 +106,7 @@ func RegisterImplementation(proto interface{}, loader CustomLoader) error {
func registerImplementation(proto interface{}, loader CustomLoader) error {
protoReflect := reflect.New(reflect.TypeOf(proto).Elem())
var proto2 = protoReflect.Interface().(protov2.Message)
proto2 := protoReflect.Interface().(protov2.Message)
msgDesc := proto2.ProtoReflect().Descriptor()
fullName := string(msgDesc.FullName())
msgOpts, err := protoext.GetMessageOptions(msgDesc)

View File

@ -8,8 +8,7 @@ type AnyResolver interface {
Resolve(typeURL string) (proto.Message, error)
}
type serialResolver struct {
}
type serialResolver struct{}
func (s serialResolver) Resolve(typeURL string) (proto.Message, error) {
instance, err := GetInstance(typeURL)

View File

@ -52,9 +52,11 @@ func GetInstanceOf(v *anypb.Any) (proto.Message, error) {
func V2Type(v *anypb.Any) string {
return V2TypeFromURL(v.TypeUrl)
}
func V2TypeFromURL(string2 string) string {
return strings.TrimPrefix(string2, V2RayTypeURLHeader)
}
func V2TypeHumanReadable(v *anypb.Any) string {
return v.TypeUrl
}

View File

@ -7,8 +7,10 @@ import (
"unicode"
)
var errInvalidSize = errors.New("invalid size")
var errInvalidUnit = errors.New("invalid or unsupported unit")
var (
errInvalidSize = errors.New("invalid size")
errInvalidUnit = errors.New("invalid or unsupported unit")
)
// ByteSize is the size of bytes
type ByteSize uint64

View File

@ -9,7 +9,6 @@ import (
// InstanceManagement : unstable
type InstanceManagement interface {
features.Feature
ListInstance(ctx context.Context) ([]string, error)
AddInstance(ctx context.Context, name string, config []byte, configType string) error
StartInstance(ctx context.Context, name string) error

View File

@ -10,7 +10,6 @@ import (
type Observatory interface {
features.Feature
GetObservation(ctx context.Context) (proto.Message, error)
}

View File

@ -8,7 +8,6 @@ import (
type PersistentStorageEngine interface {
features.Feature
PersistentStorageEngine()
Put(ctx context.Context, key []byte, value []byte) error
Get(ctx context.Context, key []byte) ([]byte, error)

View File

@ -6,11 +6,9 @@ import (
type ScopedPersistentStorage interface {
ScopedPersistentStorageEngine()
Put(ctx context.Context, key []byte, value []byte) error
Get(ctx context.Context, key []byte) ([]byte, error)
List(ctx context.Context, keyPrefix []byte) ([][]byte, error)
ClearIfCharacteristicMismatch(ctx context.Context, characteristic []byte) error
NarrowScope(ctx context.Context, key []byte) (ScopedPersistentStorage, error)
}

View File

@ -70,6 +70,7 @@ security = 'tls'
json.Unmarshal(bs, &m)
assertResult(t, m, expected)
}
func TestTOMLToJSON_ValueTypes(t *testing.T) {
input := `
boolean = [ true, false, true, false ]

View File

@ -67,6 +67,7 @@ outbounds:
json.Unmarshal(bs, &m)
assertResult(t, m, expected)
}
func TestYMLToJSON_ValueTypes(t *testing.T) {
input := `
boolean:

View File

@ -193,6 +193,7 @@ func TestMergeTagDeep(t *testing.T) {
}
assertResult(t, m, expected)
}
func assertResult(t *testing.T, value []byte, expected string) {
v := make(map[string]interface{})
err := serial.DecodeJSON(bytes.NewReader(value), &v)

View File

@ -4,8 +4,10 @@
package merge
const priorityKey string = "_priority"
const tagKey string = "_tag"
const (
priorityKey string = "_priority"
tagKey string = "_tag"
)
// ApplyRules applies merge rules according to _tag, _priority fields, and remove them
func ApplyRules(m map[string]interface{}) error {

View File

@ -204,7 +204,6 @@ func (c *DNSConfig) BuildV5(ctx context.Context) (*dns.Config, error) {
// Build implements Buildable
func (c *DNSConfig) Build() (*dns.Config, error) {
if c.cfgctx == nil {
c.cfgctx = cfgcommon.NewConfigureLoadingContext(context.Background())

View File

@ -15,16 +15,13 @@ const (
strategyLeastPing string = "leastping"
)
var (
strategyConfigLoader = loader.NewJSONConfigLoader(loader.ConfigCreatorCache{
var strategyConfigLoader = loader.NewJSONConfigLoader(loader.ConfigCreatorCache{
strategyRandom: func() interface{} { return new(strategyEmptyConfig) },
strategyLeastLoad: func() interface{} { return new(strategyLeastLoadConfig) },
strategyLeastPing: func() interface{} { return new(strategyLeastPingConfig) },
}, "type", "settings")
)
}, "type", "settings")
type strategyEmptyConfig struct {
}
type strategyEmptyConfig struct{}
func (v *strategyEmptyConfig) Build() (proto.Message, error) {
return nil, nil

View File

@ -33,7 +33,6 @@ func (v *V2JsonProtobufFollower) Range(f func(protoreflect.FieldDescriptor, prot
name := descriptor.FullName()
fullname := v.Message.Descriptor().FullName()
if fullname == "google.protobuf.Any" {
switch name {
case "google.protobuf.Any.type_url":
fd := V2JsonProtobufAnyTypeFieldDescriptor{descriptor}
@ -58,7 +57,6 @@ func (v *V2JsonProtobufFollower) Range(f func(protoreflect.FieldDescriptor, prot
default:
panic("unexpected any value")
}
}
return followValue(descriptor, value, f)
})
@ -106,7 +104,6 @@ func (v *V2JsonProtobufFollower) Set(descriptor protoreflect.FieldDescriptor, va
default:
v.Message.Set(descriptor, value)
}
}
func (v *V2JsonProtobufFollower) Mutable(descriptor protoreflect.FieldDescriptor) protoreflect.Value {
@ -124,7 +121,6 @@ func (v *V2JsonProtobufFollower) Mutable(descriptor protoreflect.FieldDescriptor
}
func (v *V2JsonProtobufFollower) NewField(descriptor protoreflect.FieldDescriptor) protoreflect.Value {
if _, ok := descriptor.(*V2JsonProtobufAnyValueField); ok {
url := v.Message.Get(v.Message.Descriptor().Fields().ByName("type_url")).String()

View File

@ -54,6 +54,7 @@ type V2JsonProtobufAnyTypeFieldDescriptor struct {
func (v V2JsonProtobufAnyTypeFieldDescriptor) JSONName() string {
return "type"
}
func (v V2JsonProtobufAnyTypeFieldDescriptor) TextName() string {
return "type"
}
@ -70,6 +71,7 @@ func (v *V2JsonProtobufAnyValueField) Kind() protoreflect.Kind {
func (v *V2JsonProtobufAnyValueField) JSONName() string {
return v.name
}
func (v *V2JsonProtobufAnyValueField) TextName() string {
return v.name
}

View File

@ -60,7 +60,6 @@ func executeBalancerInfo(cmd *base.Command, args []string) {
}
showBalancerInfo(resp.Balancer)
}
func showBalancerInfo(b *routerService.BalancerMsg) {

View File

@ -46,7 +46,6 @@ var cmdConvertPb = &base.Command{
base.Fatalf("%s", newError(fmt.Sprintf("failed to load config: %s", configFiles)).Base(err))
return
}
}
bytew, err := proto.Marshal(config)
if err != nil {
@ -54,6 +53,5 @@ var cmdConvertPb = &base.Command{
return
}
io.Copy(os.Stdout, bytes.NewReader(bytew))
},
}

View File

@ -14,5 +14,4 @@ var cmdEngineering = &base.Command{
func init() {
base.RegisterCommand(cmdEngineering)
}

View File

@ -41,4 +41,5 @@ var cmdReversePb = &base.Command{
io.Copy(os.Stdout, bytes.NewReader(value))
}
}
}}
},
}

View File

@ -74,6 +74,7 @@ func setConfArgs(cmd *base.Command) {
cmd.Flag.StringVar(&outputFormat, "o", "json", "")
cmd.Flag.BoolVar(&confDirRecursively, "r", false, "")
}
func executeConvert(cmd *base.Command, args []string) {
setConfArgs(cmd)
cmd.Flag.Parse(args)

View File

@ -29,9 +29,7 @@ func init() {
cmdPing.Run = executePing // break init loop
}
var (
pingIPStr = cmdPing.Flag.String("ip", "", "")
)
var pingIPStr = cmdPing.Flag.String("ip", "", "")
func executePing(cmd *base.Command, args []string) {
if cmdPing.Flag.NArg() < 1 {

View File

@ -25,9 +25,7 @@ func init() {
cmdVerify.Run = executeVerify // break init loop
}
var (
verifySigFile = cmdVerify.Flag.String("sig", "", "Path to the signature file")
)
var verifySigFile = cmdVerify.Flag.String("sig", "", "Path to the signature file")
func executeVerify(cmd *base.Command, args []string) {
target := cmdVerify.Flag.Arg(0)

View File

@ -113,8 +113,10 @@ func ExitIfErrors() {
}
}
var exitStatus = 0
var exitMu sync.Mutex
var (
exitStatus = 0
exitMu sync.Mutex
)
// SetExitStatus set exit status code
func SetExitStatus(n int) {

View File

@ -79,7 +79,7 @@ import (
// commands
_ "github.com/v2fly/v2ray-core/v4/main/commands/all"
//engineering commands
// engineering commands
_ "github.com/v2fly/v2ray-core/v4/main/commands/all/engineering"
// Commands that rely on jsonv4 format This disable selective compile

View File

@ -25,7 +25,6 @@ type bindingInstance struct {
var binding bindingInstance
func (b *bindingInstance) startAPIInstance() {
bindConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&instman.Config{}),

View File

@ -71,7 +71,7 @@ func (h *Handler) resolveIP(ctx context.Context, domain string, localAddr net.Ad
newError("DNS client doesn't implement ClientWithIPOption")
}
var lookupFunc = h.dns.LookupIP
lookupFunc := h.dns.LookupIP
if h.config.DomainStrategy == Config_USE_IP4 || (localAddr != nil && localAddr.Family().IsIPv4()) {
if lookupIPv4, ok := h.dns.(dns.IPv4Lookup); ok {
lookupFunc = lookupIPv4.LookupIPv4

View File

@ -37,7 +37,6 @@ func ReadTCPSession(user *protocol.MemoryUser, reader io.Reader) (*protocol.Requ
behaviorSeed := crc32.ChecksumIEEE(hashkdf.Sum(nil))
drainer, err := drain.NewBehaviorSeedLimitedDrainer(int64(behaviorSeed), 16+38, 3266, 64)
if err != nil {
return nil, nil, newError("failed to initialize drainer").Base(err)
}
@ -138,7 +137,6 @@ func ReadTCPResponse(user *protocol.MemoryUser, reader io.Reader) (buf.Reader, e
behaviorSeed := crc32.ChecksumIEEE(hashkdf.Sum(nil))
drainer, err := drain.NewBehaviorSeedLimitedDrainer(int64(behaviorSeed), 16+38, 3266, 64)
if err != nil {
return nil, newError("failed to initialize drainer").Base(err)
}

View File

@ -28,7 +28,8 @@ func init() {
common.Must(common.RegisterConfig((*ClientConfig)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
simplifiedClient := config.(*ClientConfig)
fullClient := &trojan.ClientConfig{Server: []*protocol.ServerEndpoint{
fullClient := &trojan.ClientConfig{
Server: []*protocol.ServerEndpoint{
{
Address: simplifiedClient.Address,
Port: simplifiedClient.Port,

View File

@ -1,10 +1,10 @@
package core_test
import (
"google.golang.org/protobuf/types/known/anypb"
"testing"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
. "github.com/v2fly/v2ray-core/v4"
"github.com/v2fly/v2ray-core/v4/app/dispatcher"