From f373f2f4b90416ae7efdb0bfc373259e03e8359e Mon Sep 17 00:00:00 2001 From: "pak.wzq" Date: Mon, 2 Feb 2026 20:54:12 +0800 Subject: [PATCH] fix --- README.md | 4 +++- selector/strategy.go | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8da1f535..6da81857 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -# The extended (may be experimental) features outside the main gost tree. \ No newline at end of file +# The extended (may be experimental) features outside the main gost tree. + + diff --git a/selector/strategy.go b/selector/strategy.go index 47e8c822..8458d797 100644 --- a/selector/strategy.go +++ b/selector/strategy.go @@ -7,6 +7,7 @@ import ( "sync" "sync/atomic" "time" + "github.com/go-gost/core/logger" "github.com/go-gost/core/metadata" @@ -102,6 +103,15 @@ func (s *hashStrategy[T]) Apply(ctx context.Context, vs ...T) (v T) { if len(vs) == 0 { return } + + // 打印 基于用户 id 进行 hash 选择最终出口 + if clientID := xctx.ClientIDFromContext(ctx); clientID != "" { + idStr := string(clientID) + value := uint64(crc32.ChecksumIEEE([]byte(idStr))) + logger.Default().Infof("【命中】从 xctx 拿到 ID: %s, Hash: %d", idStr, value) + return vs[value%uint64(len(vs))] + } + if h := xctx.HashFromContext(ctx); h != nil { value := uint64(crc32.ChecksumIEEE([]byte(h.Source))) logger.Default().Tracef("hash %s %d", h.Source, value)