Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test
name: Tests and Checkings

on:
push:
Expand All @@ -8,6 +8,7 @@ on:
jobs:
check-assets:
runs-on: ubuntu-latest
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
steps:
- name: Restore Geodat Cache
uses: actions/cache/restore@v5
Expand Down Expand Up @@ -36,6 +37,7 @@ jobs:

check-proto:
runs-on: ubuntu-latest
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
steps:
- name: Checkout codebase
uses: actions/checkout@v6
Expand All @@ -50,8 +52,28 @@ jobs:
fi
done

check-format:
runs-on: ubuntu-latest
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
permissions:
contents: read
steps:
- name: Checkout codebase
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
check-latest: true
cache: false
- name: Check Format
run: |
go install -v mvdan.cc/gofumpt@latest
go run ./infra/vformat/main.go -mode check -pwd ./

test:
needs: check-assets
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
permissions:
contents: read
runs-on: ${{ matrix.os }}
Expand Down
11 changes: 5 additions & 6 deletions app/commander/commander.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package commander
import (
"context"
"net"
"strings"
"sync"
"strings"

"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/errors"
"github.com/xtls/xray-core/common/signal/done"
core "github.com/xtls/xray-core/core"
"github.com/xtls/xray-core/features/outbound"
"github.com/xtls/xray-core/transport/internet"
"github.com/xtls/xray-core/transport/internet"
"google.golang.org/grpc"
)

Expand Down Expand Up @@ -69,16 +69,15 @@ func (c *Commander) Start() error {
}
c.Unlock()

var listen = func(listener net.Listener) {
listen := func(listener net.Listener) {
if err := c.server.Serve(listener); err != nil {
errors.LogErrorInner(context.Background(), err, "failed to start grpc server")
}
}


if len(c.listen) > 0 {
var addr net.Addr

if strings.HasPrefix(c.listen, "/") || strings.HasPrefix(c.listen, "@") {
addr = &net.UnixAddr{Name: c.listen, Net: "unix"}
} else {
Expand All @@ -89,7 +88,7 @@ func (c *Commander) Start() error {
}
addr = tcpAddr
}
l, err := internet.ListenSystem(context.Background(), addr, nil)
l, err := internet.ListenSystem(context.Background(), addr, nil)
if err != nil {
errors.LogErrorInner(context.Background(), err, "API server failed to listen on ", c.listen)
return err
Expand Down
7 changes: 4 additions & 3 deletions app/dns/cache_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ func (c *CacheController) writeAndShrink(expiredKeys []string) {

if lenAfter == 0 {
if c.highWatermark >= minSizeForEmptyRebuild {
errors.LogDebug(context.Background(), c.name,
errors.LogDebug(
context.Background(), c.name,
" rebuilding empty cache map to reclaim memory.",
" size_before_cleanup=", lenBefore,
" peak_size_before_rebuild=", c.highWatermark,
Expand All @@ -153,7 +154,8 @@ func (c *CacheController) writeAndShrink(expiredKeys []string) {

if reductionFromPeak := c.highWatermark - lenAfter; reductionFromPeak > shrinkAbsoluteThreshold &&
float64(reductionFromPeak) > float64(c.highWatermark)*shrinkRatioThreshold {
errors.LogDebug(context.Background(), c.name,
errors.LogDebug(
context.Background(), c.name,
" shrinking cache map to reclaim memory.",
" new_size=", lenAfter,
" peak_size_before_shrink=", c.highWatermark,
Expand All @@ -165,7 +167,6 @@ func (c *CacheController) writeAndShrink(expiredKeys []string) {
c.highWatermark = lenAfter
go c.migrate()
}

}

type migrationEntry struct {
Expand Down
4 changes: 2 additions & 2 deletions app/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func New(ctx context.Context, config *Config) (*DNS, error) {
return nil, errors.New("failed to create hosts").Base(err)
}

var defaultTag = config.Tag
defaultTag := config.Tag
if len(config.Tag) == 0 {
defaultTag = generateRandomTag()
}
Expand Down Expand Up @@ -139,7 +139,7 @@ func New(ctx context.Context, config *Config) (*DNS, error) {
serveExpiredTTL = *ns.ServeExpiredTTL
}

var tag = defaultTag
tag := defaultTag
if len(ns.Tag) > 0 {
tag = ns.Tag
}
Expand Down
6 changes: 4 additions & 2 deletions app/dns/dnscommon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ func Test_parseResponse(t *testing.T) {

ans = new(dns.Msg)
ans.Id = 1
ans.Answer = append(ans.Answer,
ans.Answer = append(
ans.Answer,
common.Must2(dns.NewRR("google.com. IN CNAME m.test.google.com")),
common.Must2(dns.NewRR("google.com. IN CNAME fake.google.com")),
common.Must2(dns.NewRR("google.com. IN A 8.8.8.8")),
Expand All @@ -35,7 +36,8 @@ func Test_parseResponse(t *testing.T) {

ans = new(dns.Msg)
ans.Id = 2
ans.Answer = append(ans.Answer,
ans.Answer = append(
ans.Answer,
common.Must2(dns.NewRR("google.com. IN CNAME m.test.google.com")),
common.Must2(dns.NewRR("google.com. IN CNAME fake.google.com")),
common.Must2(dns.NewRR("google.com. IN CNAME m.test.google.com")),
Expand Down
19 changes: 10 additions & 9 deletions app/dns/fakedns/fakedns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,16 @@ func TestFakeDnsHolderCreateMappingAndRollOver(t *testing.T) {
}

func TestFakeDNSMulti(t *testing.T) {
fakeMulti, err := NewFakeDNSHolderMulti(&FakeDnsPoolMulti{
Pools: []*FakeDnsPool{{
IpPool: "240.0.0.0/12",
LruSize: 256,
}, {
IpPool: "fddd:c5b4:ff5f:f4f0::/64",
LruSize: 256,
}},
},
fakeMulti, err := NewFakeDNSHolderMulti(
&FakeDnsPoolMulti{
Pools: []*FakeDnsPool{{
IpPool: "240.0.0.0/12",
LruSize: 256,
}, {
IpPool: "fddd:c5b4:ff5f:f4f0::/64",
LruSize: 256,
}},
},
)
common.Must(err)

Expand Down
2 changes: 1 addition & 1 deletion app/dns/nameserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func NewClient(
}
}

var timeoutMs = 4000 * time.Millisecond
timeoutMs := 4000 * time.Millisecond
if ns.TimeoutMs > 0 {
timeoutMs = time.Duration(ns.TimeoutMs) * time.Millisecond
}
Expand Down
1 change: 0 additions & 1 deletion app/dns/nameserver_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ type LocalNameServer struct {

// QueryIP implements Server.
func (s *LocalNameServer) QueryIP(ctx context.Context, domain string, option dns.IPOption) (ips []net.IP, ttl uint32, err error) {

start := time.Now()
ips, ttl, err = s.client.LookupIP(domain, option)

Expand Down
1 change: 0 additions & 1 deletion app/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ func (p *MetricsHandler) Type() interface{} {
}

func (p *MetricsHandler) Start() error {

// direct listen a port if listen is set
if p.listen != "" {
TCPlistener, err := net.Listen("tcp", p.listen)
Expand Down
2 changes: 0 additions & 2 deletions app/observatory/burst/burstobserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package burst

import (
"context"

"sync"

"github.com/xtls/xray-core/app/observatory"
Expand Down Expand Up @@ -72,7 +71,6 @@ func (o *Observer) Start() error {
o.hp.StartScheduler(func() ([]string, error) {
hs, ok := o.ohm.(outbound.HandlerSelector)
if !ok {

return nil, errors.New("outbound.Manager is not a HandlerSelector")
}

Expand Down
2 changes: 1 addition & 1 deletion app/observatory/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (o *Observer) probe(outbound string) ProbeResult {
return nil
})
if err != nil {
var errorMessage = "the outbound " + outbound + " is dead: GET request failed:" + err.Error() + "with outbound handler report underlying connection failed"
errorMessage := "the outbound " + outbound + " is dead: GET request failed:" + err.Error() + "with outbound handler report underlying connection failed"
errors.LogInfoInner(o.ctx, errorCollectorForRequest.UnderlyingError(), errorMessage)
return ProbeResult{Alive: false, LastErrorReason: errorMessage}
}
Expand Down
2 changes: 1 addition & 1 deletion app/proxyman/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (s *handlerServer) GetInboundUsers(ctx context.Context, request *GetInbound
if len(request.Email) > 0 {
return &GetInboundUserResponse{Users: []*protocol.User{protocol.ToProtoUser(um.GetUser(ctx, request.Email))}}, nil
}
var result = make([]*protocol.User, 0, 100)
result := make([]*protocol.User, 0, 100)
users := um.GetUsers(ctx)
for _, u := range users {
result = append(result, protocol.ToProtoUser(u))
Expand Down
6 changes: 3 additions & 3 deletions app/proxyman/inbound/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (

// Manager manages all inbound handlers.
type Manager struct {
access sync.RWMutex
access sync.RWMutex
untaggedHandlers []inbound.Handler
taggedHandlers map[string]inbound.Handler
running bool
taggedHandlers map[string]inbound.Handler
running bool
}

// New returns a new Manager for inbound handlers.
Expand Down
3 changes: 1 addition & 2 deletions app/proxyman/outbound/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func (h *Handler) SetOutboundGateway(ctx context.Context, ob *session.Outbound)
errors.LogDebug(ctx, "use inbound source ip as sendthrough: ", inbound.Source.Address.String())
}
}
//case addr.Family().IsDomain():
// case addr.Family().IsDomain():
default:
ob.Gateway = addr

Expand Down Expand Up @@ -396,7 +396,6 @@ func (h *Handler) ProxySettings() *serial.TypedMessage {
}

func ParseRandomIP(addr net.Address, prefix string) net.Address {

_, ipnet, _ := net.ParseCIDR(addr.IP().String() + "/" + prefix)

ones, bits := ipnet.Mask.Size()
Expand Down
9 changes: 4 additions & 5 deletions app/proxyman/outbound/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
)

func TestInterfaces(t *testing.T) {
_ = (outbound.Handler)(new(Handler))
_ = (outbound.Manager)(new(Manager))
_ = outbound.Handler(new(Handler))
_ = outbound.Manager(new(Manager))
}

const xrayKey core.XrayKey = 1
Expand All @@ -43,7 +43,7 @@ func TestOutboundWithoutStatCounter(t *testing.T) {
}

v, _ := core.New(config)
v.AddFeature((outbound.Manager)(new(Manager)))
v.AddFeature(outbound.Manager(new(Manager)))
ctx := context.WithValue(context.Background(), xrayKey, v)
ctx = session.ContextWithOutbounds(ctx, []*session.Outbound{{}})
h, _ := NewHandler(ctx, &core.OutboundHandlerConfig{
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestOutboundWithStatCounter(t *testing.T) {
}

v, _ := core.New(config)
v.AddFeature((outbound.Manager)(new(Manager)))
v.AddFeature(outbound.Manager(new(Manager)))
ctx := context.WithValue(context.Background(), xrayKey, v)
ctx = session.ContextWithOutbounds(ctx, []*session.Outbound{{}})
h, _ := NewHandler(ctx, &core.OutboundHandlerConfig{
Expand All @@ -88,7 +88,6 @@ func TestOutboundWithStatCounter(t *testing.T) {
}

func TestTagsCache(t *testing.T) {

test_duration := 10 * time.Second
threads_num := 50
delay := 10 * time.Millisecond
Expand Down
1 change: 0 additions & 1 deletion app/proxyman/outbound/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ func (m *Manager) ListHandlers(ctx context.Context) []outbound.Handler {

// Select implements outbound.HandlerSelector.
func (m *Manager) Select(selectors []string) []string {

key := strings.Join(selectors, ",")
if cache, ok := m.tagsCache.Load(key); ok {
return cache.([]string)
Expand Down
1 change: 0 additions & 1 deletion app/router/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ func (s *routingServer) AddRule(ctx context.Context, request *AddRuleRequest) (*
return &AddRuleResponse{}, bo.AddRule(request.Config, request.ShouldAppend)
}
return nil, errors.New("unsupported router implementation")

}

func (s *routingServer) RemoveRule(ctx context.Context, request *RemoveRuleRequest) (*RemoveRuleResponse, error) {
Expand Down
2 changes: 0 additions & 2 deletions app/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ func (r *Router) PickRoute(ctx routing.Context) (routing.Route, error) {

// AddRule implements routing.Router.
func (r *Router) AddRule(config *serial.TypedMessage, shouldAppend bool) error {

inst, err := config.GetInstance()
if err != nil {
return err
Expand Down Expand Up @@ -227,7 +226,6 @@ func (r *Router) RemoveRule(tag string) error {
return nil
}
return errors.New("empty tag name!")

}

// ListRule implements routing.Router
Expand Down
5 changes: 5 additions & 0 deletions app/router/strategy_leastload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func TestSelectLeastExpected(t *testing.T) {
t.Errorf("expected: %v, actual: %v", expected, len(ns))
}
}

func TestSelectLeastExpected2(t *testing.T) {
strategy := &LeastLoadStrategy{
settings: &StrategyLeastLoadConfig{
Expand All @@ -102,6 +103,7 @@ func TestSelectLeastExpected2(t *testing.T) {
t.Errorf("expected: %v, actual: %v", expected, len(ns))
}
}

func TestSelectLeastExpectedAndBaselines(t *testing.T) {
strategy := &LeastLoadStrategy{
settings: &StrategyLeastLoadConfig{
Expand All @@ -122,6 +124,7 @@ func TestSelectLeastExpectedAndBaselines(t *testing.T) {
t.Errorf("expected: %v, actual: %v", expected, len(ns))
}
}

func TestSelectLeastExpectedAndBaselines2(t *testing.T) {
strategy := &LeastLoadStrategy{
settings: &StrategyLeastLoadConfig{
Expand All @@ -142,6 +145,7 @@ func TestSelectLeastExpectedAndBaselines2(t *testing.T) {
t.Errorf("expected: %v, actual: %v", expected, len(ns))
}
}

func TestSelectLeastLoadBaselines(t *testing.T) {
strategy := &LeastLoadStrategy{
settings: &StrategyLeastLoadConfig{
Expand All @@ -160,6 +164,7 @@ func TestSelectLeastLoadBaselines(t *testing.T) {
t.Errorf("expected: %v, actual: %v", expected, len(ns))
}
}

func TestSelectLeastLoadBaselinesNoQualified(t *testing.T) {
strategy := &LeastLoadStrategy{
settings: &StrategyLeastLoadConfig{
Expand Down
2 changes: 0 additions & 2 deletions app/router/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import (
routing_session "github.com/xtls/xray-core/features/routing/session"
)



func ptr[T any](v T) *T { return &v }

type event struct {
Expand Down
Loading
Loading