This commit is contained in:
pak.wzq
2026-02-02 20:54:12 +08:00
committed by ginuerzh
parent 96f35bd7aa
commit f373f2f4b9
2 changed files with 13 additions and 1 deletions
+2
View File
@@ -1 +1,3 @@
# The extended (may be experimental) features outside the main gost tree.
+10
View File
@@ -8,6 +8,7 @@ import (
"sync/atomic"
"time"
"github.com/go-gost/core/logger"
"github.com/go-gost/core/metadata"
"github.com/go-gost/core/selector"
@@ -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)