More table
Some checks failed
Build and Release for Windows 7 / check-assets (push) Has been cancelled
Build and Release / check-assets (push) Has been cancelled
Tests and Checkings / check-assets (push) Has been cancelled
Tests and Checkings / check-proto (push) Has been cancelled
Tests and Checkings / check-format (push) Has been cancelled
Build and Release for Windows 7 / build (win7-32, 386, windows) (push) Has been cancelled
Build and Release for Windows 7 / build (win7-64, amd64, windows) (push) Has been cancelled
Build and Release / build (386, freebsd, ) (push) Has been cancelled
Build and Release / build (386, linux, ) (push) Has been cancelled
Build and Release / build (386, openbsd, ) (push) Has been cancelled
Build and Release / build (386, windows, ) (push) Has been cancelled
Build and Release / build (amd64, android, android-amd64) (push) Has been cancelled
Build and Release / build (amd64, darwin, ) (push) Has been cancelled
Build and Release / build (amd64, freebsd, ) (push) Has been cancelled
Build and Release / build (amd64, linux, ) (push) Has been cancelled
Build and Release / build (amd64, openbsd, ) (push) Has been cancelled
Build and Release / build (amd64, windows, ) (push) Has been cancelled
Build and Release / build (arm, 5, linux) (push) Has been cancelled
Build and Release / build (arm, 6, linux) (push) Has been cancelled
Build and Release / build (arm, 7, freebsd) (push) Has been cancelled
Build and Release / build (arm, 7, linux) (push) Has been cancelled
Build and Release / build (arm, 7, openbsd) (push) Has been cancelled
Build and Release / build (arm64, android) (push) Has been cancelled
Build and Release / build (arm64, darwin) (push) Has been cancelled
Build and Release / build (arm64, freebsd) (push) Has been cancelled
Build and Release / build (arm64, linux) (push) Has been cancelled
Build and Release / build (arm64, openbsd) (push) Has been cancelled
Build and Release / build (arm64, windows) (push) Has been cancelled
Build and Release / build (loong64, linux) (push) Has been cancelled
Build and Release / build (mips, linux) (push) Has been cancelled
Build and Release / build (mips64, linux) (push) Has been cancelled
Build and Release / build (mips64le, linux) (push) Has been cancelled
Build and Release / build (mipsle, linux) (push) Has been cancelled
Build and Release / build (ppc64, linux) (push) Has been cancelled
Build and Release / build (ppc64le, linux) (push) Has been cancelled
Build and Release / build (riscv64, linux) (push) Has been cancelled
Build and Release / build (s390x, linux) (push) Has been cancelled
Tests and Checkings / test (macos-latest) (push) Has been cancelled
Tests and Checkings / test (ubuntu-latest) (push) Has been cancelled
Tests and Checkings / test (windows-latest) (push) Has been cancelled

This commit is contained in:
Fangliding 2026-06-06 06:11:54 +08:00
parent 0e6ab63b8a
commit 87c08d0d7a
No known key found for this signature in database
GPG key ID: A1E6A14761C93303
2 changed files with 33 additions and 12 deletions

View file

@ -6,6 +6,7 @@ import (
"encoding/hex"
"encoding/json"
"math"
"math/big"
"net/netip"
"net/url"
"os"
@ -381,6 +382,14 @@ func (c *SplitHTTPConfig) Build() (proto.Message, error) {
}
if c.SessionIDTable != "" {
if predefined, ok := splithttp.PredefinedTable[c.SessionIDTable]; ok {
c.SessionIDTable = predefined
}
room := roomSize(len(c.SessionIDTable), c.SessionIDLength.From, c.SessionIDLength.To)
// 2.1B possiblities should be enough
if room.Cmp(big.NewInt(2<<30)) < 0 {
return nil, errors.New("sessionIDTable or sessionIDLength is too small")
}
if c.SessionIDLength.From <= 0 {
return nil, errors.New("sessionIDLength.from must be greater than 0")
}
@ -454,6 +463,17 @@ func (c *SplitHTTPConfig) Build() (proto.Message, error) {
return config, nil
}
func roomSize(tableSize int, min, max int32) *big.Int {
base := big.NewInt(int64(tableSize))
sum := new(big.Int)
term := new(big.Int)
for k := min; k <= max; k++ {
term.Exp(base, big.NewInt(int64(k)), nil)
sum.Add(sum, term)
}
return sum
}
const (
Byte = 1
Kilobyte = 1024 * Byte

View file

@ -488,22 +488,23 @@ func (c *RangeConfig) rand() int32 {
}
// predefined
var (
base62Table = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
hexTable = "0123456789abcdef"
hexTableUpper = "0123456789ABCDEF"
)
var PredefinedTable = map[string]string{
"number": "0123456789",
"base62": "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
"base36": "0123456789abcdefghijklmnopqrstuvwxyz",
"BASE36": "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"hex": "0123456789abcdef",
"HEX": "0123456789ABCDEF",
"Alphabet": "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
"ALPHABET": "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"alphabet": "abcdefghijklmnopqrstuvwxyz",
}
func (c *Config) GenerateSessionID() string {
length := c.SessionIDLength.rand()
table := c.SessionIDTable
switch table {
case "base62":
table = base62Table
case "hex":
table = hexTable
case "HEX":
table = hexTableUpper
if predefined, ok := PredefinedTable[table]; ok {
table = predefined
}
if table != "" && length > 0 {
id := make([]byte, length)