Finalmask: Refactor header conns to avoid multiple-copy; Add randRange to "header-custom" (TCP & UDP) (#5812)

https://github.com/XTLS/Xray-core/pull/5657#issuecomment-4016760602
https://github.com/XTLS/Xray-core/pull/5657#issuecomment-4052921628
This commit is contained in:
LjhAUMEM
2026-03-21 17:04:22 +08:00
committed by GitHub
parent 35800e953e
commit 06dc4cf8bd
28 changed files with 388 additions and 558 deletions

View File

@@ -4,8 +4,11 @@ package crypto // import "github.com/xtls/xray-core/common/crypto"
import (
"crypto/rand"
"math/big"
"github.com/xtls/xray-core/common"
)
// [,)
func RandBetween(from int64, to int64) int64 {
if from == to {
return from
@@ -16,3 +19,20 @@ func RandBetween(from int64, to int64) int64 {
bigInt, _ := rand.Int(rand.Reader, big.NewInt(to-from))
return from + bigInt.Int64()
}
// [,]
func RandBytesBetween(b []byte, from, to byte) {
common.Must2(rand.Read(b))
if from > to {
from, to = to, from
}
if to-from == 255 {
return
}
for i := range b {
b[i] = from + b[i]%(to-from+1)
}
}