@@ -4,13 +4,15 @@ import (
44 "encoding/base64"
55 "fmt"
66 "io"
7+ "math/rand/v2"
78 "net/http"
89 "strings"
910
1011 "github.com/xtls/xray-core/common"
1112 "github.com/xtls/xray-core/common/buf"
1213 "github.com/xtls/xray-core/common/crypto"
1314 "github.com/xtls/xray-core/common/utils"
15+ "github.com/xtls/xray-core/common/uuid"
1416 "github.com/xtls/xray-core/transport/internet"
1517)
1618
@@ -131,26 +133,26 @@ func (c *Config) GetNormalizedUplinkHTTPMethod() string {
131133 return c .UplinkHTTPMethod
132134}
133135
134- func (c * Config ) GetNormalizedScMaxEachPostBytes () RangeConfig {
136+ func (c * Config ) GetNormalizedScMaxEachPostBytes () * RangeConfig {
135137 if c .ScMaxEachPostBytes == nil || c .ScMaxEachPostBytes .To == 0 {
136- return RangeConfig {
138+ return & RangeConfig {
137139 From : 1000000 ,
138140 To : 1000000 ,
139141 }
140142 }
141143
142- return * c .ScMaxEachPostBytes
144+ return c .ScMaxEachPostBytes
143145}
144146
145- func (c * Config ) GetNormalizedScMinPostsIntervalMs () RangeConfig {
147+ func (c * Config ) GetNormalizedScMinPostsIntervalMs () * RangeConfig {
146148 if c .ScMinPostsIntervalMs == nil || c .ScMinPostsIntervalMs .To == 0 {
147- return RangeConfig {
149+ return & RangeConfig {
148150 From : 30 ,
149151 To : 30 ,
150152 }
151153 }
152154
153- return * c .ScMinPostsIntervalMs
155+ return c .ScMinPostsIntervalMs
154156}
155157
156158func (c * Config ) GetNormalizedScMaxBufferedPosts () int {
@@ -161,41 +163,41 @@ func (c *Config) GetNormalizedScMaxBufferedPosts() int {
161163 return int (c .ScMaxBufferedPosts )
162164}
163165
164- func (c * Config ) GetNormalizedScStreamUpServerSecs () RangeConfig {
166+ func (c * Config ) GetNormalizedScStreamUpServerSecs () * RangeConfig {
165167 if c .ScStreamUpServerSecs == nil || c .ScStreamUpServerSecs .To == 0 {
166- return RangeConfig {
168+ return & RangeConfig {
167169 From : 20 ,
168170 To : 80 ,
169171 }
170172 }
171173
172- return * c .ScStreamUpServerSecs
174+ return c .ScStreamUpServerSecs
173175}
174176
175- func (c * Config ) GetNormalizedUplinkChunkSize () RangeConfig {
177+ func (c * Config ) GetNormalizedUplinkChunkSize () * RangeConfig {
176178 if c .UplinkChunkSize == nil || c .UplinkChunkSize .To == 0 {
177179 switch c .UplinkDataPlacement {
178180 case PlacementCookie :
179- return RangeConfig {
181+ return & RangeConfig {
180182 From : 2 * 1024 , // 2 KiB
181183 To : 3 * 1024 , // 3 KiB
182184 }
183185 case PlacementHeader :
184- return RangeConfig {
186+ return & RangeConfig {
185187 From : 3 * 1000 , // 3 KB
186188 To : 4 * 1000 , // 4 KB
187189 }
188190 default :
189191 return c .GetNormalizedScMaxEachPostBytes ()
190192 }
191193 } else if c .UplinkChunkSize .From < 64 {
192- return RangeConfig {
194+ return & RangeConfig {
193195 From : 64 ,
194196 To : max (64 , c .UplinkChunkSize .To ),
195197 }
196198 }
197199
198- return * c .UplinkChunkSize
200+ return c .UplinkChunkSize
199201}
200202
201203func (c * Config ) GetNormalizedServerMaxHeaderBytes () int {
@@ -417,59 +419,59 @@ func (c *Config) ExtractMetaFromRequest(req *http.Request, path string) (session
417419 return sessionId , seqStr
418420}
419421
420- func (m * XmuxConfig ) GetNormalizedMaxConcurrency () RangeConfig {
422+ func (m * XmuxConfig ) GetNormalizedMaxConcurrency () * RangeConfig {
421423 if m .MaxConcurrency == nil {
422- return RangeConfig {
424+ return & RangeConfig {
423425 From : 0 ,
424426 To : 0 ,
425427 }
426428 }
427429
428- return * m .MaxConcurrency
430+ return m .MaxConcurrency
429431}
430432
431- func (m * XmuxConfig ) GetNormalizedMaxConnections () RangeConfig {
433+ func (m * XmuxConfig ) GetNormalizedMaxConnections () * RangeConfig {
432434 if m .MaxConnections == nil {
433- return RangeConfig {
435+ return & RangeConfig {
434436 From : 0 ,
435437 To : 0 ,
436438 }
437439 }
438440
439- return * m .MaxConnections
441+ return m .MaxConnections
440442}
441443
442- func (m * XmuxConfig ) GetNormalizedCMaxReuseTimes () RangeConfig {
444+ func (m * XmuxConfig ) GetNormalizedCMaxReuseTimes () * RangeConfig {
443445 if m .CMaxReuseTimes == nil {
444- return RangeConfig {
446+ return & RangeConfig {
445447 From : 0 ,
446448 To : 0 ,
447449 }
448450 }
449451
450- return * m .CMaxReuseTimes
452+ return m .CMaxReuseTimes
451453}
452454
453- func (m * XmuxConfig ) GetNormalizedHMaxRequestTimes () RangeConfig {
455+ func (m * XmuxConfig ) GetNormalizedHMaxRequestTimes () * RangeConfig {
454456 if m .HMaxRequestTimes == nil {
455- return RangeConfig {
457+ return & RangeConfig {
456458 From : 0 ,
457459 To : 0 ,
458460 }
459461 }
460462
461- return * m .HMaxRequestTimes
463+ return m .HMaxRequestTimes
462464}
463465
464- func (m * XmuxConfig ) GetNormalizedHMaxReusableSecs () RangeConfig {
466+ func (m * XmuxConfig ) GetNormalizedHMaxReusableSecs () * RangeConfig {
465467 if m .HMaxReusableSecs == nil {
466- return RangeConfig {
468+ return & RangeConfig {
467469 From : 0 ,
468470 To : 0 ,
469471 }
470472 }
471473
472- return * m .HMaxReusableSecs
474+ return m .HMaxReusableSecs
473475}
474476
475477func init () {
@@ -478,10 +480,40 @@ func init() {
478480 }))
479481}
480482
481- func (c RangeConfig ) rand () int32 {
483+ func (c * RangeConfig ) rand () int32 {
482484 return int32 (crypto .RandBetween (int64 (c .From ), int64 (c .To )))
483485}
484486
487+ // predefined
488+ var (
489+ base62Table = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
490+ hexTable = "0123456789abcdef"
491+ hexTableUpper = "0123456789ABCDEF"
492+ )
493+
494+ func (c * Config ) GenerateSessionID () string {
495+ length := c .SessionIDLength .rand ()
496+ table := c .SessionIDTable
497+ switch table {
498+ case "base62" :
499+ table = base62Table
500+ case "hex" :
501+ table = hexTable
502+ case "HEX" :
503+ table = hexTableUpper
504+ }
505+ if table != "" && length > 0 {
506+ id := make ([]byte , length )
507+ for i := range id {
508+ id [i ] = table [rand .N (len (table ))]
509+ }
510+ return string (id )
511+ } else {
512+ uuid := uuid .New ()
513+ return uuid .String ()
514+ }
515+ }
516+
485517func appendToPath (path , value string ) string {
486518 if strings .HasSuffix (path , "/" ) {
487519 return path + value
0 commit comments