1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-17 13:05:24 +00: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 return f.domainName
} }
func newFakeDNSThenOthers(ctx context.Context, fakeDNSSniffer protocolSnifferWithMetadata, others []protocolSnifferWithMetadata) ( func newFakeDNSThenOthers(ctx context.Context, fakeDNSSniffer protocolSnifferWithMetadata, others []protocolSnifferWithMetadata) (protocolSnifferWithMetadata, error) { // nolint: unparam
protocolSnifferWithMetadata, error) { // nolint: unparam
// ctx may be used in the future // ctx may be used in the future
_ = ctx _ = ctx
return protocolSnifferWithMetadata{ return protocolSnifferWithMetadata{

View File

@ -316,7 +316,6 @@ func init() {
})) }))
common.Must(common.RegisterConfig((*SimplifiedConfig)(nil), func(ctx context.Context, config interface{}) (interface{}, error) { common.Must(common.RegisterConfig((*SimplifiedConfig)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
ctx = cfgcommon.NewConfigureLoadingContext(context.Background()) ctx = cfgcommon.NewConfigureLoadingContext(context.Background())
geoloadername := platform.NewEnvFlag("v2ray.conf.geoloader").GetValue(func() string { 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. // New creates a new log.Instance based on the given config.
func New(ctx context.Context, config *Config) (*Instance, error) { func New(ctx context.Context, config *Config) (*Instance, error) {
if config.Error == nil { if config.Error == nil {
config.Error = &LogSpecification{Type: LogType_Console, Level: log.Severity_Warning} 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) { o.hp.StartScheduler(func() ([]string, error) {
hs, ok := o.ohm.(outbound.HandlerSelector) hs, ok := o.ohm.(outbound.HandlerSelector)
if !ok { if !ok {
return nil, newError("outbound.Manager is not a HandlerSelector") 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") return nil, newError("empty worker list")
} }
var minIdx = -1 minIdx := -1
var minConn uint32 = 9999 var minConn uint32 = 9999
for i, w := range p.workers { for i, w := range p.workers {
if w.draining { if w.draining {

View File

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

View File

@ -3,7 +3,7 @@ package internal
import "encoding/binary" import "encoding/binary"
func ChaCha20Block(s *[16]uint32, out []byte, rounds int) { 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 { for i := 0; i < rounds; i += 2 {
var x uint32 var x uint32

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -7,14 +7,13 @@ import (
"encoding/binary" "encoding/binary"
"io" "io"
"github.com/v2fly/v2ray-core/v4/common/errors"
"github.com/lucas-clemente/quic-go/quicvarint" "github.com/lucas-clemente/quic-go/quicvarint"
"github.com/marten-seemann/qtls-go1-17" "github.com/marten-seemann/qtls-go1-17"
"golang.org/x/crypto/hkdf" "golang.org/x/crypto/hkdf"
"github.com/v2fly/v2ray-core/v4/common" "github.com/v2fly/v2ray-core/v4/common"
"github.com/v2fly/v2ray-core/v4/common/buf" "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" 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 return implementationConfigInstance.(proto.Message), nil
} }
func newImplementationRegistry() *implementationRegistry { func newImplementationRegistry() *implementationRegistry {
@ -107,7 +106,7 @@ func RegisterImplementation(proto interface{}, loader CustomLoader) error {
func registerImplementation(proto interface{}, loader CustomLoader) error { func registerImplementation(proto interface{}, loader CustomLoader) error {
protoReflect := reflect.New(reflect.TypeOf(proto).Elem()) protoReflect := reflect.New(reflect.TypeOf(proto).Elem())
var proto2 = protoReflect.Interface().(protov2.Message) proto2 := protoReflect.Interface().(protov2.Message)
msgDesc := proto2.ProtoReflect().Descriptor() msgDesc := proto2.ProtoReflect().Descriptor()
fullName := string(msgDesc.FullName()) fullName := string(msgDesc.FullName())
msgOpts, err := protoext.GetMessageOptions(msgDesc) msgOpts, err := protoext.GetMessageOptions(msgDesc)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -4,8 +4,10 @@
package merge package merge
const priorityKey string = "_priority" const (
const tagKey string = "_tag" priorityKey string = "_priority"
tagKey string = "_tag"
)
// ApplyRules applies merge rules according to _tag, _priority fields, and remove them // ApplyRules applies merge rules according to _tag, _priority fields, and remove them
func ApplyRules(m map[string]interface{}) error { 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 // Build implements Buildable
func (c *DNSConfig) Build() (*dns.Config, error) { func (c *DNSConfig) Build() (*dns.Config, error) {
if c.cfgctx == nil { if c.cfgctx == nil {
c.cfgctx = cfgcommon.NewConfigureLoadingContext(context.Background()) c.cfgctx = cfgcommon.NewConfigureLoadingContext(context.Background())

View File

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

View File

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

View File

@ -60,7 +60,6 @@ func executeBalancerInfo(cmd *base.Command, args []string) {
} }
showBalancerInfo(resp.Balancer) showBalancerInfo(resp.Balancer)
} }
func showBalancerInfo(b *routerService.BalancerMsg) { 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)) base.Fatalf("%s", newError(fmt.Sprintf("failed to load config: %s", configFiles)).Base(err))
return return
} }
} }
bytew, err := proto.Marshal(config) bytew, err := proto.Marshal(config)
if err != nil { if err != nil {
@ -54,6 +53,5 @@ var cmdConvertPb = &base.Command{
return return
} }
io.Copy(os.Stdout, bytes.NewReader(bytew)) io.Copy(os.Stdout, bytes.NewReader(bytew))
}, },
} }

View File

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

View File

@ -41,4 +41,5 @@ var cmdReversePb = &base.Command{
io.Copy(os.Stdout, bytes.NewReader(value)) 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.StringVar(&outputFormat, "o", "json", "")
cmd.Flag.BoolVar(&confDirRecursively, "r", false, "") cmd.Flag.BoolVar(&confDirRecursively, "r", false, "")
} }
func executeConvert(cmd *base.Command, args []string) { func executeConvert(cmd *base.Command, args []string) {
setConfArgs(cmd) setConfArgs(cmd)
cmd.Flag.Parse(args) cmd.Flag.Parse(args)

View File

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

View File

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

View File

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

View File

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

View File

@ -25,7 +25,6 @@ type bindingInstance struct {
var binding bindingInstance var binding bindingInstance
func (b *bindingInstance) startAPIInstance() { func (b *bindingInstance) startAPIInstance() {
bindConfig := &core.Config{ bindConfig := &core.Config{
App: []*anypb.Any{ App: []*anypb.Any{
serial.ToTypedMessage(&instman.Config{}), 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") 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 h.config.DomainStrategy == Config_USE_IP4 || (localAddr != nil && localAddr.Family().IsIPv4()) {
if lookupIPv4, ok := h.dns.(dns.IPv4Lookup); ok { if lookupIPv4, ok := h.dns.(dns.IPv4Lookup); ok {
lookupFunc = lookupIPv4.LookupIPv4 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)) behaviorSeed := crc32.ChecksumIEEE(hashkdf.Sum(nil))
drainer, err := drain.NewBehaviorSeedLimitedDrainer(int64(behaviorSeed), 16+38, 3266, 64) drainer, err := drain.NewBehaviorSeedLimitedDrainer(int64(behaviorSeed), 16+38, 3266, 64)
if err != nil { if err != nil {
return nil, nil, newError("failed to initialize drainer").Base(err) 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)) behaviorSeed := crc32.ChecksumIEEE(hashkdf.Sum(nil))
drainer, err := drain.NewBehaviorSeedLimitedDrainer(int64(behaviorSeed), 16+38, 3266, 64) drainer, err := drain.NewBehaviorSeedLimitedDrainer(int64(behaviorSeed), 16+38, 3266, 64)
if err != nil { if err != nil {
return nil, newError("failed to initialize drainer").Base(err) return nil, newError("failed to initialize drainer").Base(err)
} }

View File

@ -28,17 +28,18 @@ func init() {
common.Must(common.RegisterConfig((*ClientConfig)(nil), func(ctx context.Context, config interface{}) (interface{}, error) { common.Must(common.RegisterConfig((*ClientConfig)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
simplifiedClient := config.(*ClientConfig) simplifiedClient := config.(*ClientConfig)
fullClient := &trojan.ClientConfig{Server: []*protocol.ServerEndpoint{ fullClient := &trojan.ClientConfig{
{ Server: []*protocol.ServerEndpoint{
Address: simplifiedClient.Address, {
Port: simplifiedClient.Port, Address: simplifiedClient.Address,
User: []*protocol.User{ Port: simplifiedClient.Port,
{ User: []*protocol.User{
Account: serial.ToTypedMessage(&trojan.Account{Password: simplifiedClient.Password}), {
Account: serial.ToTypedMessage(&trojan.Account{Password: simplifiedClient.Password}),
},
}, },
}, },
}, },
},
} }
return common.CreateObject(ctx, fullClient) return common.CreateObject(ctx, fullClient)
})) }))

View File

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