From 83bab5dd907af9d0d281a97f36d240bfb0df8c2c Mon Sep 17 00:00:00 2001 From: zonescape <44441590+zonescape@users.noreply.github.com> Date: Sat, 9 Nov 2024 14:16:11 +0300 Subject: [PATCH] Chore: Run gofmt (#3990) --- app/dispatcher/fakednssniffer.go | 2 +- app/proxyman/outbound/handler.go | 2 +- app/router/strategy_leastload_test.go | 110 ++++++++++++------------ app/router/strategy_random.go | 2 +- common/buf/buffer.go | 2 +- common/ctx/context.go | 2 +- common/protocol/user.go | 4 +- common/reflect/marshal.go | 12 +-- common/session/session.go | 2 +- common/singbridge/dialer.go | 4 +- core/xray_test.go | 4 +- features/routing/session/context.go | 2 +- infra/conf/dns_proxy.go | 2 +- infra/conf/dokodemo.go | 10 +-- infra/conf/observatory.go | 2 +- infra/conf/router.go | 6 +- infra/conf/router_strategy.go | 10 +-- infra/conf/xray.go | 2 +- main/commands/all/api/inbound_user.go | 2 +- main/commands/all/api/shared.go | 2 +- proxy/blackhole/blackhole.go | 4 +- proxy/dns/dns.go | 2 +- proxy/proxy.go | 2 +- proxy/shadowsocks/config.go | 12 +-- proxy/shadowsocks/protocol.go | 2 +- proxy/shadowsocks_2022/config.go | 4 +- proxy/shadowsocks_2022/inbound_multi.go | 2 +- proxy/socks/client.go | 2 +- proxy/trojan/server.go | 10 +-- proxy/trojan/validator.go | 1 - proxy/vless/account.go | 4 +- proxy/vmess/account.go | 4 +- proxy/wireguard/client.go | 2 +- testing/scenarios/command_test.go | 12 +-- testing/scenarios/dokodemo_test.go | 8 +- testing/scenarios/feature_test.go | 28 +++--- testing/scenarios/policy_test.go | 8 +- testing/scenarios/reverse_test.go | 16 ++-- testing/scenarios/socks_test.go | 24 +++--- testing/scenarios/tls_test.go | 54 ++++++------ testing/scenarios/transport_test.go | 8 +- testing/scenarios/vless_test.go | 42 ++++----- testing/scenarios/vmess_test.go | 68 +++++++-------- transport/internet/grpc/dial.go | 4 +- transport/internet/grpc/hub.go | 2 +- transport/internet/http/http_test.go | 4 +- transport/internet/http/hub.go | 14 +-- transport/internet/tls/config.go | 6 +- transport/pipe/impl.go | 10 +-- transport/pipe/writer.go | 2 +- 50 files changed, 272 insertions(+), 273 deletions(-) diff --git a/app/dispatcher/fakednssniffer.go b/app/dispatcher/fakednssniffer.go index f7486d1d..bed90877 100644 --- a/app/dispatcher/fakednssniffer.go +++ b/app/dispatcher/fakednssniffer.go @@ -28,7 +28,7 @@ func newFakeDNSSniffer(ctx context.Context) (protocolSnifferWithMetadata, error) } return protocolSnifferWithMetadata{protocolSniffer: func(ctx context.Context, bytes []byte) (SniffResult, error) { outbounds := session.OutboundsFromContext(ctx) - ob := outbounds[len(outbounds) - 1] + ob := outbounds[len(outbounds)-1] if ob.Target.Network == net.Network_TCP || ob.Target.Network == net.Network_UDP { domainFromFakeDNS := fakeDNSEngine.GetDomainFromFakeDNS(ob.Target.Address) if domainFromFakeDNS != "" { diff --git a/app/proxyman/outbound/handler.go b/app/proxyman/outbound/handler.go index 404ac30e..df7d52a4 100644 --- a/app/proxyman/outbound/handler.go +++ b/app/proxyman/outbound/handler.go @@ -11,8 +11,8 @@ import ( "github.com/xtls/xray-core/app/proxyman" "github.com/xtls/xray-core/common" - "github.com/xtls/xray-core/common/errors" "github.com/xtls/xray-core/common/buf" + "github.com/xtls/xray-core/common/errors" "github.com/xtls/xray-core/common/mux" "github.com/xtls/xray-core/common/net" "github.com/xtls/xray-core/common/net/cnc" diff --git a/app/router/strategy_leastload_test.go b/app/router/strategy_leastload_test.go index be95140d..832e0a87 100644 --- a/app/router/strategy_leastload_test.go +++ b/app/router/strategy_leastload_test.go @@ -7,64 +7,64 @@ import ( /* Split into multiple package, need to be tested separately -func TestSelectLeastLoad(t *testing.T) { - settings := &StrategyLeastLoadConfig{ - HealthCheck: &HealthPingConfig{ - SamplingCount: 10, - }, - Expected: 1, - MaxRTT: int64(time.Millisecond * time.Duration(800)), + func TestSelectLeastLoad(t *testing.T) { + settings := &StrategyLeastLoadConfig{ + HealthCheck: &HealthPingConfig{ + SamplingCount: 10, + }, + Expected: 1, + 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) { - settings := &StrategyLeastLoadConfig{ - HealthCheck: &HealthPingConfig{ - SamplingCount: 10, - }, - Costs: []*StrategyWeight{ - {Match: "a", Value: 9}, - }, - Expected: 1, + func TestSelectLeastLoadWithCost(t *testing.T) { + settings := &StrategyLeastLoadConfig{ + HealthCheck: &HealthPingConfig{ + SamplingCount: 10, + }, + Costs: []*StrategyWeight{ + {Match: "a", Value: 9}, + }, + 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) { strategy := &LeastLoadStrategy{ diff --git a/app/router/strategy_random.go b/app/router/strategy_random.go index 2609e347..ed82ff9d 100644 --- a/app/router/strategy_random.go +++ b/app/router/strategy_random.go @@ -11,7 +11,7 @@ import ( ) // RandomStrategy represents a random balancing strategy -type RandomStrategy struct{ +type RandomStrategy struct { FallbackTag string ctx context.Context diff --git a/common/buf/buffer.go b/common/buf/buffer.go index 15d4d4a5..63779586 100644 --- a/common/buf/buffer.go +++ b/common/buf/buffer.go @@ -218,7 +218,7 @@ func (b *Buffer) Cap() int32 { // NewWithSize creates a Buffer with 0 length and capacity with at least the given size. func NewWithSize(size int32) *Buffer { return &Buffer{ - v: bytespool.Alloc(size), + v: bytespool.Alloc(size), } } diff --git a/common/ctx/context.go b/common/ctx/context.go index 94a57902..25144f5f 100644 --- a/common/ctx/context.go +++ b/common/ctx/context.go @@ -7,7 +7,7 @@ type SessionKey int // ID of a session. type ID uint32 -const( +const ( idSessionKey SessionKey = 0 ) diff --git a/common/protocol/user.go b/common/protocol/user.go index 230c4b6d..75e8e654 100644 --- a/common/protocol/user.go +++ b/common/protocol/user.go @@ -41,8 +41,8 @@ func ToProtoUser(mu *MemoryUser) *User { } return &User{ Account: serial.ToTypedMessage(mu.Account.ToProto()), - Email: mu.Email, - Level: mu.Level, + Email: mu.Email, + Level: mu.Level, } } diff --git a/common/reflect/marshal.go b/common/reflect/marshal.go index 6d9798cc..42f47385 100644 --- a/common/reflect/marshal.go +++ b/common/reflect/marshal.go @@ -22,12 +22,12 @@ func MarshalToJson(v interface{}, insertTypeInfo bool) (string, bool) { } func JSONMarshalWithoutEscape(t interface{}) ([]byte, error) { - buffer := &bytes.Buffer{} - encoder := json.NewEncoder(buffer) - encoder.SetIndent("", " ") - encoder.SetEscapeHTML(false) - err := encoder.Encode(t) - return buffer.Bytes(), err + buffer := &bytes.Buffer{} + encoder := json.NewEncoder(buffer) + encoder.SetIndent("", " ") + encoder.SetEscapeHTML(false) + err := encoder.Encode(t) + return buffer.Bytes(), err } func marshalTypedMessage(v *cserial.TypedMessage, ignoreNullValue bool, insertTypeInfo bool) interface{} { diff --git a/common/session/session.go b/common/session/session.go index 4573b216..cad15400 100644 --- a/common/session/session.go +++ b/common/session/session.go @@ -148,4 +148,4 @@ func (c *Content) AttributeLen() int { c.mu.Unlock() }() return len(c.Attributes) -} \ No newline at end of file +} diff --git a/common/singbridge/dialer.go b/common/singbridge/dialer.go index 6be83036..a6b32199 100644 --- a/common/singbridge/dialer.go +++ b/common/singbridge/dialer.go @@ -48,9 +48,9 @@ func (d *XrayOutboundDialer) DialContext(ctx context.Context, network string, de outbounds = []*session.Outbound{{}} ctx = session.ContextWithOutbounds(ctx, outbounds) } - ob := outbounds[len(outbounds) - 1] + ob := outbounds[len(outbounds)-1] ob.Target = ToDestination(destination, ToNetwork(network)) - + opts := []pipe.Option{pipe.WithSizeLimit(64 * 1024)} uplinkReader, uplinkWriter := pipe.New(opts...) downlinkReader, downlinkWriter := pipe.New(opts...) diff --git a/core/xray_test.go b/core/xray_test.go index eea0a408..43d021ef 100644 --- a/core/xray_test.go +++ b/core/xray_test.go @@ -54,8 +54,8 @@ func TestXrayClose(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(net.LocalHostIP), - Port: uint32(0), + Address: net.NewIPOrDomain(net.LocalHostIP), + Port: uint32(0), Networks: []net.Network{net.Network_TCP}, }), }, diff --git a/features/routing/session/context.go b/features/routing/session/context.go index 3c9764b3..f87066a0 100644 --- a/features/routing/session/context.go +++ b/features/routing/session/context.go @@ -125,7 +125,7 @@ func (ctx *Context) GetSkipDNSResolve() bool { // AsRoutingContext creates a context from context.context with session info. func AsRoutingContext(ctx context.Context) routing.Context { outbounds := session.OutboundsFromContext(ctx) - ob := outbounds[len(outbounds) - 1] + ob := outbounds[len(outbounds)-1] return &Context{ Inbound: session.InboundFromContext(ctx), Outbound: ob, diff --git a/infra/conf/dns_proxy.go b/infra/conf/dns_proxy.go index cb135584..3425f22e 100644 --- a/infra/conf/dns_proxy.go +++ b/infra/conf/dns_proxy.go @@ -13,7 +13,7 @@ type DNSOutboundConfig struct { Port uint16 `json:"port"` UserLevel uint32 `json:"userLevel"` NonIPQuery string `json:"nonIPQuery"` - BlockTypes []int32 `json:"blockTypes"` + BlockTypes []int32 `json:"blockTypes"` } func (c *DNSOutboundConfig) Build() (proto.Message, error) { diff --git a/infra/conf/dokodemo.go b/infra/conf/dokodemo.go index e0f76733..2086cb5a 100644 --- a/infra/conf/dokodemo.go +++ b/infra/conf/dokodemo.go @@ -6,11 +6,11 @@ import ( ) type DokodemoConfig struct { - Host *Address `json:"address"` - PortValue uint16 `json:"port"` - NetworkList *NetworkList `json:"network"` - Redirect bool `json:"followRedirect"` - UserLevel uint32 `json:"userLevel"` + Host *Address `json:"address"` + PortValue uint16 `json:"port"` + NetworkList *NetworkList `json:"network"` + Redirect bool `json:"followRedirect"` + UserLevel uint32 `json:"userLevel"` } func (v *DokodemoConfig) Build() (proto.Message, error) { diff --git a/infra/conf/observatory.go b/infra/conf/observatory.go index 24c37a69..1ae403db 100644 --- a/infra/conf/observatory.go +++ b/infra/conf/observatory.go @@ -2,7 +2,7 @@ package conf import ( "google.golang.org/protobuf/proto" - + "github.com/xtls/xray-core/app/observatory" "github.com/xtls/xray-core/app/observatory/burst" "github.com/xtls/xray-core/infra/conf/cfgcommon/duration" diff --git a/infra/conf/router.go b/infra/conf/router.go index 69198d6a..2065f96b 100644 --- a/infra/conf/router.go +++ b/infra/conf/router.go @@ -71,9 +71,9 @@ func (r *BalancingRule) Build() (*router.BalancingRule, error) { } type RouterConfig struct { - RuleList []json.RawMessage `json:"rules"` - DomainStrategy *string `json:"domainStrategy"` - Balancers []*BalancingRule `json:"balancers"` + RuleList []json.RawMessage `json:"rules"` + DomainStrategy *string `json:"domainStrategy"` + Balancers []*BalancingRule `json:"balancers"` DomainMatcher string `json:"domainMatcher"` } diff --git a/infra/conf/router_strategy.go b/infra/conf/router_strategy.go index 4d0f647a..98bcc8d1 100644 --- a/infra/conf/router_strategy.go +++ b/infra/conf/router_strategy.go @@ -2,9 +2,9 @@ package conf import ( "google.golang.org/protobuf/proto" - - "github.com/xtls/xray-core/app/router" + "github.com/xtls/xray-core/app/observatory/burst" + "github.com/xtls/xray-core/app/router" "github.com/xtls/xray-core/infra/conf/cfgcommon/duration" ) @@ -46,10 +46,10 @@ type strategyLeastLoadConfig struct { // healthCheckSettings holds settings for health Checker type healthCheckSettings struct { - Destination string `json:"destination"` - Connectivity string `json:"connectivity"` + Destination string `json:"destination"` + Connectivity string `json:"connectivity"` Interval duration.Duration `json:"interval"` - SamplingCount int `json:"sampling"` + SamplingCount int `json:"sampling"` Timeout duration.Duration `json:"timeout"` } diff --git a/infra/conf/xray.go b/infra/conf/xray.go index 0b5c60e6..ee9e6dfd 100644 --- a/infra/conf/xray.go +++ b/infra/conf/xray.go @@ -363,7 +363,7 @@ func (c *StatsConfig) Build() (*stats.Config, error) { type Config struct { // Deprecated: Global transport config is no longer used // left for returning error - Transport map[string]json.RawMessage `json:"transport"` + Transport map[string]json.RawMessage `json:"transport"` LogConfig *LogConfig `json:"log"` RouterConfig *RouterConfig `json:"routing"` diff --git a/main/commands/all/api/inbound_user.go b/main/commands/all/api/inbound_user.go index 6ffa4ebb..7a443183 100644 --- a/main/commands/all/api/inbound_user.go +++ b/main/commands/all/api/inbound_user.go @@ -39,7 +39,7 @@ func executeInboundUser(cmd *base.Command, args []string) { client := handlerService.NewHandlerServiceClient(conn) r := &handlerService.GetInboundUserRequest{ - Tag: tag, + Tag: tag, Email: email, } resp, err := client.GetInboundUsers(ctx, r) diff --git a/main/commands/all/api/shared.go b/main/commands/all/api/shared.go index 870ef5fc..f9d18265 100644 --- a/main/commands/all/api/shared.go +++ b/main/commands/all/api/shared.go @@ -15,8 +15,8 @@ import ( "google.golang.org/grpc/credentials/insecure" "github.com/xtls/xray-core/common/buf" - "github.com/xtls/xray-core/main/commands/base" creflect "github.com/xtls/xray-core/common/reflect" + "github.com/xtls/xray-core/main/commands/base" "google.golang.org/grpc" "google.golang.org/protobuf/proto" ) diff --git a/proxy/blackhole/blackhole.go b/proxy/blackhole/blackhole.go index ea3049ad..998666cb 100644 --- a/proxy/blackhole/blackhole.go +++ b/proxy/blackhole/blackhole.go @@ -30,9 +30,9 @@ func New(ctx context.Context, config *Config) (*Handler, error) { // Process implements OutboundHandler.Dispatch(). func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer internet.Dialer) error { outbounds := session.OutboundsFromContext(ctx) - ob := outbounds[len(outbounds) - 1] + ob := outbounds[len(outbounds)-1] ob.Name = "blackhole" - + nBytes := h.response.WriteTo(link.Writer) if nBytes > 0 { // Sleep a little here to make sure the response is sent to client. diff --git a/proxy/dns/dns.go b/proxy/dns/dns.go index eeaa4c4c..ed063197 100644 --- a/proxy/dns/dns.go +++ b/proxy/dns/dns.go @@ -49,7 +49,7 @@ type Handler struct { server net.Destination timeout time.Duration nonIPQuery string - blockTypes []int32 + blockTypes []int32 } func (h *Handler) Init(config *Config, dnsClient dns.Client, policyManager policy.Manager) error { diff --git a/proxy/proxy.go b/proxy/proxy.go index 868c8dfc..1e4c69f5 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -78,7 +78,7 @@ type UserManager interface { // RemoveUser removes a user by email. RemoveUser(context.Context, string) error - + // Get user by email. GetUser(context.Context, string) *protocol.MemoryUser diff --git a/proxy/shadowsocks/config.go b/proxy/shadowsocks/config.go index e2d812ab..a6d2ef87 100644 --- a/proxy/shadowsocks/config.go +++ b/proxy/shadowsocks/config.go @@ -22,7 +22,7 @@ import ( // MemoryAccount is an account type converted from Account. type MemoryAccount struct { Cipher Cipher - CipherType CipherType + CipherType CipherType Key []byte Password string @@ -42,8 +42,8 @@ func (a *MemoryAccount) Equals(another protocol.Account) bool { func (a *MemoryAccount) ToProto() proto.Message { return &Account{ CipherType: a.CipherType, - Password: a.Password, - IvCheck: a.replayFilter != nil, + Password: a.Password, + IvCheck: a.replayFilter != nil, } } @@ -117,10 +117,10 @@ func (a *Account) AsAccount() (protocol.Account, error) { return nil, errors.New("failed to get cipher").Base(err) } return &MemoryAccount{ - Cipher: Cipher, + Cipher: Cipher, CipherType: a.CipherType, - Key: passwordToCipherKey([]byte(a.Password), Cipher.KeySize()), - Password: a.Password, + Key: passwordToCipherKey([]byte(a.Password), Cipher.KeySize()), + Password: a.Password, replayFilter: func() antireplay.GeneralizedReplayFilter { if a.IvCheck { return antireplay.NewBloomRing() diff --git a/proxy/shadowsocks/protocol.go b/proxy/shadowsocks/protocol.go index 00855c73..c992f619 100644 --- a/proxy/shadowsocks/protocol.go +++ b/proxy/shadowsocks/protocol.go @@ -10,9 +10,9 @@ import ( "github.com/xtls/xray-core/common" "github.com/xtls/xray-core/common/buf" - "github.com/xtls/xray-core/common/errors" "github.com/xtls/xray-core/common/crypto" "github.com/xtls/xray-core/common/drain" + "github.com/xtls/xray-core/common/errors" "github.com/xtls/xray-core/common/net" "github.com/xtls/xray-core/common/protocol" ) diff --git a/proxy/shadowsocks_2022/config.go b/proxy/shadowsocks_2022/config.go index 3678cd58..9ddd2cf8 100644 --- a/proxy/shadowsocks_2022/config.go +++ b/proxy/shadowsocks_2022/config.go @@ -8,13 +8,13 @@ import ( // MemoryAccount is an account type converted from Account. type MemoryAccount struct { - Key string + Key string } // AsAccount implements protocol.AsAccount. func (u *Account) AsAccount() (protocol.Account, error) { return &MemoryAccount{ - Key: u.GetKey(), + Key: u.GetKey(), }, nil } diff --git a/proxy/shadowsocks_2022/inbound_multi.go b/proxy/shadowsocks_2022/inbound_multi.go index 20b85139..4bfa086a 100644 --- a/proxy/shadowsocks_2022/inbound_multi.go +++ b/proxy/shadowsocks_2022/inbound_multi.go @@ -155,7 +155,7 @@ func (i *MultiUserInbound) GetUser(ctx context.Context, email string) *protocol. if email == "" { return nil } - + i.Lock() defer i.Unlock() diff --git a/proxy/socks/client.go b/proxy/socks/client.go index e5af3161..2ed5740a 100644 --- a/proxy/socks/client.go +++ b/proxy/socks/client.go @@ -45,7 +45,7 @@ func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) { serverPicker: protocol.NewRoundRobinServerPicker(serverList), policyManager: v.GetFeature(policy.ManagerType()).(policy.Manager), } - + return c, nil } diff --git a/proxy/trojan/server.go b/proxy/trojan/server.go index 20ac1fd1..44662ac3 100644 --- a/proxy/trojan/server.go +++ b/proxy/trojan/server.go @@ -361,14 +361,14 @@ func (s *Server) fallback(ctx context.Context, err error, sessionPolicy policy.S cs := tlsConn.ConnectionState() name = cs.ServerName alpn = cs.NegotiatedProtocol - errors.LogInfo(ctx, "realName = " + name) - errors.LogInfo(ctx, "realAlpn = " + alpn) + errors.LogInfo(ctx, "realName = "+name) + errors.LogInfo(ctx, "realAlpn = "+alpn) } else if realityConn, ok := iConn.(*reality.Conn); ok { cs := realityConn.ConnectionState() name = cs.ServerName alpn = cs.NegotiatedProtocol - errors.LogInfo(ctx, "realName = " + name) - errors.LogInfo(ctx, "realAlpn = " + alpn) + errors.LogInfo(ctx, "realName = "+name) + errors.LogInfo(ctx, "realAlpn = "+alpn) } name = strings.ToLower(name) alpn = strings.ToLower(alpn) @@ -418,7 +418,7 @@ func (s *Server) fallback(ctx context.Context, err error, sessionPolicy policy.S } if k == '?' || k == ' ' { path = string(firstBytes[i:j]) - errors.LogInfo(ctx, "realPath = " + path) + errors.LogInfo(ctx, "realPath = "+path) if pfb[path] == nil { path = "" } diff --git a/proxy/trojan/validator.go b/proxy/trojan/validator.go index fb3499fa..bfe53812 100644 --- a/proxy/trojan/validator.go +++ b/proxy/trojan/validator.go @@ -51,7 +51,6 @@ func (v *Validator) Get(hash string) *protocol.MemoryUser { return nil } - // Get a trojan user with hashed key, nil if user doesn't exist. func (v *Validator) GetByEmail(email string) *protocol.MemoryUser { u, _ := v.email.Load(email) diff --git a/proxy/vless/account.go b/proxy/vless/account.go index 798b93f4..c22cfe16 100644 --- a/proxy/vless/account.go +++ b/proxy/vless/account.go @@ -42,8 +42,8 @@ func (a *MemoryAccount) Equals(account protocol.Account) bool { func (a *MemoryAccount) ToProto() proto.Message { return &Account{ - Id: a.ID.String(), - Flow: a.Flow, + Id: a.ID.String(), + Flow: a.Flow, Encryption: a.Encryption, } } diff --git a/proxy/vmess/account.go b/proxy/vmess/account.go index d063f9f5..df8ba52b 100644 --- a/proxy/vmess/account.go +++ b/proxy/vmess/account.go @@ -38,8 +38,8 @@ func (a *MemoryAccount) ToProto() proto.Message { test = test + "NoTerminationSignal" } return &Account{ - Id: a.ID.String(), - TestsEnabled: test, + Id: a.ID.String(), + TestsEnabled: test, SecuritySettings: &protocol.SecurityConfig{Type: a.Security}, } } diff --git a/proxy/wireguard/client.go b/proxy/wireguard/client.go index 1bb594b7..c26cbf4d 100644 --- a/proxy/wireguard/client.go +++ b/proxy/wireguard/client.go @@ -29,8 +29,8 @@ import ( "github.com/xtls/xray-core/common" "github.com/xtls/xray-core/common/buf" - "github.com/xtls/xray-core/common/errors" "github.com/xtls/xray-core/common/dice" + "github.com/xtls/xray-core/common/errors" "github.com/xtls/xray-core/common/log" "github.com/xtls/xray-core/common/net" "github.com/xtls/xray-core/common/protocol" diff --git a/testing/scenarios/command_test.go b/testing/scenarios/command_test.go index b20d6f10..037255a9 100644 --- a/testing/scenarios/command_test.go +++ b/testing/scenarios/command_test.go @@ -303,8 +303,8 @@ func TestCommanderAddRemoveUser(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -458,8 +458,8 @@ func TestCommanderStats(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -480,8 +480,8 @@ func TestCommanderStats(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, diff --git a/testing/scenarios/dokodemo_test.go b/testing/scenarios/dokodemo_test.go index d6b69823..f74fb4bd 100644 --- a/testing/scenarios/dokodemo_test.go +++ b/testing/scenarios/dokodemo_test.go @@ -85,8 +85,8 @@ func TestDokodemoTCP(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -181,8 +181,8 @@ func TestDokodemoUDP(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_UDP}, }), }, diff --git a/testing/scenarios/feature_test.go b/testing/scenarios/feature_test.go index 5dd08ec4..6fe0d850 100644 --- a/testing/scenarios/feature_test.go +++ b/testing/scenarios/feature_test.go @@ -53,8 +53,8 @@ func TestPassiveConnection(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -161,8 +161,8 @@ func TestProxy(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -299,8 +299,8 @@ func TestProxyOverKCP(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -386,8 +386,8 @@ func TestBlackhole(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -397,8 +397,8 @@ func TestBlackhole(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest2.Address), - Port: uint32(dest2.Port), + Address: net.NewIPOrDomain(dest2.Address), + Port: uint32(dest2.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -512,8 +512,8 @@ func TestUDPConnection(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_UDP}, }), }, @@ -556,8 +556,8 @@ func TestDomainSniffing(t *testing.T) { }, }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(net.LocalHostIP), - Port: 443, + Address: net.NewIPOrDomain(net.LocalHostIP), + Port: 443, Networks: []net.Network{net.Network_TCP}, }), }, diff --git a/testing/scenarios/policy_test.go b/testing/scenarios/policy_test.go index 773e6bcf..1e8aafea 100644 --- a/testing/scenarios/policy_test.go +++ b/testing/scenarios/policy_test.go @@ -110,8 +110,8 @@ func TestVMessClosing(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -214,8 +214,8 @@ func TestZeroBuffer(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, diff --git a/testing/scenarios/reverse_test.go b/testing/scenarios/reverse_test.go index 197f6d1f..faaa402e 100644 --- a/testing/scenarios/reverse_test.go +++ b/testing/scenarios/reverse_test.go @@ -76,8 +76,8 @@ func TestReverseProxy(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -141,8 +141,8 @@ func TestReverseProxy(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -255,8 +255,8 @@ func TestReverseProxyLongRunning(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -334,8 +334,8 @@ func TestReverseProxyLongRunning(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, diff --git a/testing/scenarios/socks_test.go b/testing/scenarios/socks_test.go index 13e6f869..83ebebc3 100644 --- a/testing/scenarios/socks_test.go +++ b/testing/scenarios/socks_test.go @@ -64,8 +64,8 @@ func TestSocksBridgeTCP(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -143,8 +143,8 @@ func TestSocksWithHttpRequest(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -213,8 +213,8 @@ func TestSocksBridageUDP(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_UDP}, }), }, @@ -247,8 +247,8 @@ func TestSocksBridageUDP(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_UDP}, }), }, @@ -328,8 +328,8 @@ func TestSocksBridageUDPWithRouting(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_UDP}, }), }, @@ -366,8 +366,8 @@ func TestSocksBridageUDPWithRouting(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_UDP}, }), }, diff --git a/testing/scenarios/tls_test.go b/testing/scenarios/tls_test.go index f1955877..ffe43300 100644 --- a/testing/scenarios/tls_test.go +++ b/testing/scenarios/tls_test.go @@ -81,8 +81,8 @@ func TestSimpleTLSConnection(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -196,8 +196,8 @@ func TestAutoIssuingCertificate(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -301,8 +301,8 @@ func TestTLSOverKCP(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -401,8 +401,8 @@ func TestTLSOverWebSocket(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -426,7 +426,7 @@ func TestTLSOverWebSocket(t *testing.T) { }), SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{ StreamSettings: &internet.StreamConfig{ - ProtocolName: "websocket", + ProtocolName: "websocket", TransportSettings: []*internet.TransportConfig{ { ProtocolName: "websocket", @@ -475,11 +475,11 @@ func TestHTTP2(t *testing.T) { PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(serverPort)}}, Listen: net.NewIPOrDomain(net.LocalHostIP), StreamSettings: &internet.StreamConfig{ - ProtocolName: "http", + ProtocolName: "http", TransportSettings: []*internet.TransportConfig{ { ProtocolName: "http", - Settings: serial.ToTypedMessage(&http.Config{ + Settings: serial.ToTypedMessage(&http.Config{ Host: []string{"example.com"}, Path: "/testpath", }), @@ -520,8 +520,8 @@ func TestHTTP2(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -545,11 +545,11 @@ func TestHTTP2(t *testing.T) { }), SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{ StreamSettings: &internet.StreamConfig{ - ProtocolName: "http", + ProtocolName: "http", TransportSettings: []*internet.TransportConfig{ { ProtocolName: "http", - Settings: serial.ToTypedMessage(&http.Config{ + Settings: serial.ToTypedMessage(&http.Config{ Host: []string{"example.com"}, Path: "/testpath", }), @@ -639,8 +639,8 @@ func TestGRPC(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -755,8 +755,8 @@ func TestGRPCMultiMode(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -866,8 +866,8 @@ func TestSimpleTLSConnectionPinned(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -968,8 +968,8 @@ func TestSimpleTLSConnectionPinnedWrongCert(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -1069,8 +1069,8 @@ func TestUTLSConnectionPinned(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -1172,8 +1172,8 @@ func TestUTLSConnectionPinnedWrongCert(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, diff --git a/testing/scenarios/transport_test.go b/testing/scenarios/transport_test.go index e6ece892..bb16deee 100644 --- a/testing/scenarios/transport_test.go +++ b/testing/scenarios/transport_test.go @@ -42,7 +42,7 @@ func TestHTTPConnectionHeader(t *testing.T) { TransportSettings: []*internet.TransportConfig{ { ProtocolName: "tcp", - Settings: serial.ToTypedMessage(&tcptransport.Config{ + Settings: serial.ToTypedMessage(&tcptransport.Config{ HeaderSettings: serial.ToTypedMessage(&http.Config{}), }), }, @@ -76,8 +76,8 @@ func TestHTTPConnectionHeader(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -104,7 +104,7 @@ func TestHTTPConnectionHeader(t *testing.T) { TransportSettings: []*internet.TransportConfig{ { ProtocolName: "tcp", - Settings: serial.ToTypedMessage(&tcptransport.Config{ + Settings: serial.ToTypedMessage(&tcptransport.Config{ HeaderSettings: serial.ToTypedMessage(&http.Config{}), }), }, diff --git a/testing/scenarios/vless_test.go b/testing/scenarios/vless_test.go index 87952794..dcac17ea 100644 --- a/testing/scenarios/vless_test.go +++ b/testing/scenarios/vless_test.go @@ -85,8 +85,8 @@ func TestVless(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -190,8 +190,8 @@ func TestVlessTls(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -215,7 +215,7 @@ func TestVlessTls(t *testing.T) { }), SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{ StreamSettings: &internet.StreamConfig{ - ProtocolName: "tcp", + ProtocolName: "tcp", TransportSettings: []*internet.TransportConfig{ { ProtocolName: "tcp", @@ -313,8 +313,8 @@ func TestVlessXtlsVision(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -339,7 +339,7 @@ func TestVlessXtlsVision(t *testing.T) { }), SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{ StreamSettings: &internet.StreamConfig{ - ProtocolName: "tcp", + ProtocolName: "tcp", TransportSettings: []*internet.TransportConfig{ { ProtocolName: "tcp", @@ -403,12 +403,12 @@ func TestVlessXtlsVisionReality(t *testing.T) { SecurityType: serial.GetMessageType(&reality.Config{}), SecuritySettings: []*serial.TypedMessage{ serial.ToTypedMessage(&reality.Config{ - Show: true, - Dest: "www.google.com:443", // use google for now, may fail in some region + Show: true, + Dest: "www.google.com:443", // use google for now, may fail in some region ServerNames: []string{"www.google.com"}, - PrivateKey: privateKey, - ShortIds: shortIds, - Type: "tcp", + PrivateKey: privateKey, + ShortIds: shortIds, + Type: "tcp", }), }, }, @@ -447,8 +447,8 @@ func TestVlessXtlsVisionReality(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -473,7 +473,7 @@ func TestVlessXtlsVisionReality(t *testing.T) { }), SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{ StreamSettings: &internet.StreamConfig{ - ProtocolName: "tcp", + ProtocolName: "tcp", TransportSettings: []*internet.TransportConfig{ { ProtocolName: "tcp", @@ -483,12 +483,12 @@ func TestVlessXtlsVisionReality(t *testing.T) { SecurityType: serial.GetMessageType(&reality.Config{}), SecuritySettings: []*serial.TypedMessage{ serial.ToTypedMessage(&reality.Config{ - Show: true, + Show: true, Fingerprint: "chrome", - ServerName: "www.google.com", - PublicKey: publicKey, - ShortId: shortIds[0], - SpiderX: "/", + ServerName: "www.google.com", + PublicKey: publicKey, + ShortId: shortIds[0], + SpiderX: "/", }), }, }, diff --git a/testing/scenarios/vmess_test.go b/testing/scenarios/vmess_test.go index 092d25a3..dbffe0d6 100644 --- a/testing/scenarios/vmess_test.go +++ b/testing/scenarios/vmess_test.go @@ -71,8 +71,8 @@ func TestVMessDynamicPort(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -131,8 +131,8 @@ func TestVMessDynamicPort(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -223,8 +223,8 @@ func TestVMessGCM(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -325,8 +325,8 @@ func TestVMessGCMReadv(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -430,8 +430,8 @@ func TestVMessGCMUDP(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_UDP}, }), }, @@ -529,8 +529,8 @@ func TestVMessChacha20(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -629,8 +629,8 @@ func TestVMessNone(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -731,8 +731,8 @@ func TestVMessKCP(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -802,11 +802,11 @@ func TestVMessKCPLarge(t *testing.T) { PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(serverPort)}}, Listen: net.NewIPOrDomain(net.LocalHostIP), StreamSettings: &internet.StreamConfig{ - ProtocolName: "mkcp", + ProtocolName: "mkcp", TransportSettings: []*internet.TransportConfig{ { ProtocolName: "mkcp", - Settings: serial.ToTypedMessage(&kcp.Config{ + Settings: serial.ToTypedMessage(&kcp.Config{ ReadBuffer: &kcp.ReadBuffer{ Size: 512 * 1024, }, @@ -857,8 +857,8 @@ func TestVMessKCPLarge(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -885,11 +885,11 @@ func TestVMessKCPLarge(t *testing.T) { }), SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{ StreamSettings: &internet.StreamConfig{ - ProtocolName: "mkcp", + ProtocolName: "mkcp", TransportSettings: []*internet.TransportConfig{ { ProtocolName: "mkcp", - Settings: serial.ToTypedMessage(&kcp.Config{ + Settings: serial.ToTypedMessage(&kcp.Config{ ReadBuffer: &kcp.ReadBuffer{ Size: 512 * 1024, }, @@ -984,8 +984,8 @@ func TestVMessGCMMux(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -1100,8 +1100,8 @@ func TestVMessGCMMuxUDP(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -1111,8 +1111,8 @@ func TestVMessGCMMuxUDP(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(udpDest.Address), - Port: uint32(udpDest.Port), + Address: net.NewIPOrDomain(udpDest.Address), + Port: uint32(udpDest.Port), Networks: []net.Network{net.Network_UDP}, }), }, @@ -1224,8 +1224,8 @@ func TestVMessZero(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -1323,8 +1323,8 @@ func TestVMessGCMLengthAuth(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, @@ -1427,8 +1427,8 @@ func TestVMessGCMLengthAuthPlusNoTerminationSignal(t *testing.T) { Listen: net.NewIPOrDomain(net.LocalHostIP), }), ProxySettings: serial.ToTypedMessage(&dokodemo.Config{ - Address: net.NewIPOrDomain(dest.Address), - Port: uint32(dest.Port), + Address: net.NewIPOrDomain(dest.Address), + Port: uint32(dest.Port), Networks: []net.Network{net.Network_TCP}, }), }, diff --git a/transport/internet/grpc/dial.go b/transport/internet/grpc/dial.go index 24ae8ad0..b8740dae 100644 --- a/transport/internet/grpc/dial.go +++ b/transport/internet/grpc/dial.go @@ -56,7 +56,7 @@ func dialgRPC(ctx context.Context, dest net.Destination, streamSettings *interne } client := encoding.NewGRPCServiceClient(conn) if grpcSettings.MultiMode { - errors.LogDebug(ctx, "using gRPC multi mode service name: `" + grpcSettings.getServiceName() + "` stream name: `" + grpcSettings.getTunMultiStreamName() + "`") + errors.LogDebug(ctx, "using gRPC multi mode service name: `"+grpcSettings.getServiceName()+"` stream name: `"+grpcSettings.getTunMultiStreamName()+"`") grpcService, err := client.(encoding.GRPCServiceClientX).TunMultiCustomName(ctx, grpcSettings.getServiceName(), grpcSettings.getTunMultiStreamName()) if err != nil { return nil, errors.New("Cannot dial gRPC").Base(err) @@ -64,7 +64,7 @@ func dialgRPC(ctx context.Context, dest net.Destination, streamSettings *interne return encoding.NewMultiHunkConn(grpcService, nil), nil } - errors.LogDebug(ctx, "using gRPC tun mode service name: `" + grpcSettings.getServiceName() + "` stream name: `" + grpcSettings.getTunStreamName() + "`") + errors.LogDebug(ctx, "using gRPC tun mode service name: `"+grpcSettings.getServiceName()+"` stream name: `"+grpcSettings.getTunStreamName()+"`") grpcService, err := client.(encoding.GRPCServiceClientX).TunCustomName(ctx, grpcSettings.getServiceName(), grpcSettings.getTunStreamName()) if err != nil { return nil, errors.New("Cannot dial gRPC").Base(err) diff --git a/transport/internet/grpc/hub.go b/transport/internet/grpc/hub.go index b07c3b75..ae8788fa 100644 --- a/transport/internet/grpc/hub.go +++ b/transport/internet/grpc/hub.go @@ -120,7 +120,7 @@ func Listen(ctx context.Context, address net.Address, port net.Port, settings *i } } - errors.LogDebug(ctx, "gRPC listen for service name `" + grpcSettings.getServiceName() + "` tun `" + grpcSettings.getTunStreamName() + "` multi tun `" + grpcSettings.getTunMultiStreamName() + "`") + errors.LogDebug(ctx, "gRPC listen for service name `"+grpcSettings.getServiceName()+"` tun `"+grpcSettings.getTunStreamName()+"` multi tun `"+grpcSettings.getTunMultiStreamName()+"`") encoding.RegisterGRPCServiceServerX(s, listener, grpcSettings.getServiceName(), grpcSettings.getTunStreamName(), grpcSettings.getTunMultiStreamName()) if config := reality.ConfigFromStreamSettings(settings); config != nil { diff --git a/transport/internet/http/http_test.go b/transport/internet/http/http_test.go index dd6c852d..1b3afa80 100644 --- a/transport/internet/http/http_test.go +++ b/transport/internet/http/http_test.go @@ -103,7 +103,7 @@ func TestH3Connection(t *testing.T) { SecurityType: "tls", SecuritySettings: &tls.Config{ NextProtocol: []string{"h3"}, - Certificate: []*tls.Certificate{tls.ParseCertificate(cert.MustGenerate(nil, cert.CommonName("www.example.com")))}, + Certificate: []*tls.Certificate{tls.ParseCertificate(cert.MustGenerate(nil, cert.CommonName("www.example.com")))}, }, }, func(conn stat.Connection) { go func() { @@ -133,7 +133,7 @@ func TestH3Connection(t *testing.T) { ProtocolSettings: &Config{}, SecurityType: "tls", SecuritySettings: &tls.Config{ - NextProtocol: []string{"h3"}, + NextProtocol: []string{"h3"}, ServerName: "www.example.com", AllowInsecure: true, }, diff --git a/transport/internet/http/hub.go b/transport/internet/http/hub.go index 96fe8f62..1fac2b73 100644 --- a/transport/internet/http/hub.go +++ b/transport/internet/http/hub.go @@ -141,8 +141,8 @@ func Listen(ctx context.Context, address net.Address, port net.Port, streamSetti isH3 := len(tlsConfig.NextProtos) == 1 && tlsConfig.NextProtos[0] == "h3" listener := &Listener{ handler: handler, - config: httpSettings, - isH3: isH3, + config: httpSettings, + isH3: isH3, } if port == net.Port(0) { // unix listener.local = &net.UnixAddr{ @@ -168,7 +168,7 @@ func Listen(ctx context.Context, address net.Address, port net.Port, streamSetti if isH3 { Conn, err := internet.ListenSystemPacket(context.Background(), listener.local, streamSettings.SocketSettings) if err != nil { - return nil, errors.New("failed to listen UDP(for SH3) on ", address, ":", port).Base(err) + return nil, errors.New("failed to listen UDP(for SH3) on ", address, ":", port).Base(err) } h3listener, err := quic.ListenEarly(Conn, tlsConfig, nil) if err != nil { @@ -188,7 +188,7 @@ func Listen(ctx context.Context, address net.Address, port net.Port, streamSetti var server *http.Server if config == nil { h2s := &http2.Server{} - + server = &http.Server{ Addr: serial.Concat(address, ":", port), Handler: h2c.NewHandler(listener, h2s), @@ -202,7 +202,7 @@ func Listen(ctx context.Context, address net.Address, port net.Port, streamSetti ReadHeaderTimeout: time.Second * 4, } } - + listener.server = server go func() { var streamListener net.Listener @@ -226,7 +226,7 @@ func Listen(ctx context.Context, address net.Address, port net.Port, streamSetti return } } - + if config == nil { if config := reality.ConfigFromStreamSettings(streamSettings); config != nil { streamListener = goreality.NewListener(streamListener, config.GetREALITYConfig()) @@ -241,7 +241,7 @@ func Listen(ctx context.Context, address net.Address, port net.Port, streamSetti errors.LogInfoInner(ctx, err, "stopping serving TLS H2") } } - }() + }() } return listener, nil diff --git a/transport/internet/tls/config.go b/transport/internet/tls/config.go index b6c55c00..75648c4b 100644 --- a/transport/internet/tls/config.go +++ b/transport/internet/tls/config.go @@ -1,6 +1,7 @@ package tls import ( + "bytes" "context" "crypto/hmac" "crypto/tls" @@ -10,7 +11,6 @@ import ( "strings" "sync" "time" - "bytes" "github.com/xtls/xray-core/common/errors" "github.com/xtls/xray-core/common/net" @@ -70,7 +70,7 @@ func (c *Config) BuildCertificates() []*tls.Certificate { continue } index := len(certs) - 1 - setupOcspTicker(entry, func(isReloaded, isOcspstapling bool){ + setupOcspTicker(entry, func(isReloaded, isOcspstapling bool) { cert := certs[index] if isReloaded { if newKeyPair := getX509KeyPair(); newKeyPair != nil { @@ -162,7 +162,7 @@ func (c *Config) getCustomCA() []*Certificate { for _, certificate := range c.Certificate { if certificate.Usage == Certificate_AUTHORITY_ISSUE { certs = append(certs, certificate) - setupOcspTicker(certificate, func(isReloaded, isOcspstapling bool){ }) + setupOcspTicker(certificate, func(isReloaded, isOcspstapling bool) {}) } } return certs diff --git a/transport/pipe/impl.go b/transport/pipe/impl.go index 8bf58a34..4a30dbbb 100644 --- a/transport/pipe/impl.go +++ b/transport/pipe/impl.go @@ -47,11 +47,11 @@ var ( ) func (p *pipe) Len() int32 { - data := p.data - if data == nil { - return 0 - } - return data.Len() + data := p.data + if data == nil { + return 0 + } + return data.Len() } func (p *pipe) getState(forRead bool) error { diff --git a/transport/pipe/writer.go b/transport/pipe/writer.go index 0a192ca0..4ba26ccc 100644 --- a/transport/pipe/writer.go +++ b/transport/pipe/writer.go @@ -20,7 +20,7 @@ func (w *Writer) Close() error { } func (w *Writer) Len() int32 { - return w.pipe.Len() + return w.pipe.Len() } // Interrupt implements common.Interruptible.