From b57f3052a8a0588661a226538075d543912b32e9 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Tue, 23 Sep 2025 08:33:11 +0800 Subject: [PATCH] chore: speedup convid generation --- transport/kcptun/client.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/transport/kcptun/client.go b/transport/kcptun/client.go index af84133e..46731ca9 100644 --- a/transport/kcptun/client.go +++ b/transport/kcptun/client.go @@ -2,8 +2,6 @@ package kcptun import ( "context" - "crypto/rand" - "encoding/binary" "net" "sync" "time" @@ -11,6 +9,7 @@ import ( "github.com/metacubex/mihomo/log" "github.com/metacubex/kcp-go" + "github.com/metacubex/randv2" "github.com/metacubex/smux" ) @@ -60,8 +59,7 @@ func (c *Client) createConn(ctx context.Context, dial DialFn) (*smux.Session, er } config := c.config - var convid uint32 - binary.Read(rand.Reader, binary.LittleEndian, &convid) + convid := randv2.Uint32() kcpconn, err := kcp.NewConn4(convid, addr, c.block, config.DataShard, config.ParityShard, true, conn) if err != nil { return nil, err