Skip to content

Commit

Permalink
Chore: Run gofmt (XTLS#3990)
Browse files Browse the repository at this point in the history
  • Loading branch information
zonescape authored Nov 9, 2024
1 parent bc4bf3d commit 83bab5d
Show file tree
Hide file tree
Showing 50 changed files with 272 additions and 273 deletions.
2 changes: 1 addition & 1 deletion app/dispatcher/fakednssniffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
2 changes: 1 addition & 1 deletion app/proxyman/outbound/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
110 changes: 55 additions & 55 deletions app/router/strategy_leastload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
}
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 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)
}
}
}
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)
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)
}
}
}
*/
func TestSelectLeastExpected(t *testing.T) {
strategy := &LeastLoadStrategy{
Expand Down
2 changes: 1 addition & 1 deletion app/router/strategy_random.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

// RandomStrategy represents a random balancing strategy
type RandomStrategy struct{
type RandomStrategy struct {
FallbackTag string

ctx context.Context
Expand Down
2 changes: 1 addition & 1 deletion common/buf/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand Down
2 changes: 1 addition & 1 deletion common/ctx/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type SessionKey int
// ID of a session.
type ID uint32

const(
const (
idSessionKey SessionKey = 0
)

Expand Down
4 changes: 2 additions & 2 deletions common/protocol/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
12 changes: 6 additions & 6 deletions common/reflect/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{} {
Expand Down
2 changes: 1 addition & 1 deletion common/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,4 @@ func (c *Content) AttributeLen() int {
c.mu.Unlock()
}()
return len(c.Attributes)
}
}
4 changes: 2 additions & 2 deletions common/singbridge/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
4 changes: 2 additions & 2 deletions core/xray_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}),
},
Expand Down
2 changes: 1 addition & 1 deletion features/routing/session/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion infra/conf/dns_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions infra/conf/dokodemo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion infra/conf/observatory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions infra/conf/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down
10 changes: 5 additions & 5 deletions infra/conf/router_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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"`
}

Expand Down
2 changes: 1 addition & 1 deletion infra/conf/xray.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
2 changes: 1 addition & 1 deletion main/commands/all/api/inbound_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion main/commands/all/api/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
4 changes: 2 additions & 2 deletions proxy/blackhole/blackhole.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion proxy/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading

0 comments on commit 83bab5d

Please sign in to comment.