mirror of
https://github.com/nadoo/glider.git
synced 2026-11-19 07:09:42 +08:00
chore: update math/rand to math/rand/v2
This commit is contained in:
1 parent
8e81e09a8f
commit
6aee7b35c0
22 files changed
+75
-80
No files matched your search
@@ -5,13 +5,14 @@ import (
|
||||
"crypto/cipher"
|
||||
"crypto/hmac"
|
||||
"crypto/md5"
|
||||
crand "crypto/rand"
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"hash/fnv"
|
||||
"io"
|
||||
"math/rand"
|
||||
"math/rand/v2"
|
||||
"net"
|
||||
"runtime"
|
||||
"strings"
|
||||
@@ -121,7 +122,7 @@ func NewClient(uuidStr, security string, alterID int, aead bool) (*Client, error
|
||||
|
||||
// NewConn returns a new vmess conn.
|
||||
func (c *Client) NewConn(rc net.Conn, target string, cmd CmdType) (*Conn, error) {
|
||||
r := rand.Intn(c.count)
|
||||
r := rand.IntN(c.count)
|
||||
conn := &Conn{user: c.users[r], opt: c.opt, aead: c.aead, security: c.security, Conn: rc}
|
||||
|
||||
var err error
|
||||
@@ -131,12 +132,12 @@ func (c *Client) NewConn(rc net.Conn, target string, cmd CmdType) (*Conn, error)
|
||||
}
|
||||
|
||||
randBytes := pool.GetBuffer(32)
|
||||
rand.Read(randBytes)
|
||||
crand.Read(randBytes)
|
||||
copy(conn.reqBodyIV[:], randBytes[:16])
|
||||
copy(conn.reqBodyKey[:], randBytes[16:32])
|
||||
pool.PutBuffer(randBytes)
|
||||
|
||||
conn.reqRespV = byte(rand.Intn(1 << 8))
|
||||
conn.reqRespV = byte(rand.IntN(1 << 8))
|
||||
|
||||
if conn.aead {
|
||||
bodyIV := sha256.Sum256(conn.reqBodyIV[:])
|
||||
@@ -192,7 +193,7 @@ func (c *Conn) Request(cmd CmdType) error {
|
||||
buf.WriteByte(c.opt) // Opt
|
||||
|
||||
// pLen and Sec
|
||||
paddingLen := rand.Intn(16)
|
||||
paddingLen := rand.IntN(16)
|
||||
pSec := byte(paddingLen<<4) | c.security // P(4bit) and Sec(4bit)
|
||||
buf.WriteByte(pSec)
|
||||
|
||||
@@ -207,7 +208,7 @@ func (c *Conn) Request(cmd CmdType) error {
|
||||
// padding
|
||||
if paddingLen > 0 {
|
||||
padding := pool.GetBuffer(paddingLen)
|
||||
rand.Read(padding)
|
||||
crand.Read(padding)
|
||||
buf.Write(padding)
|
||||
pool.PutBuffer(padding)
|
||||
}
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ func nextID(oldID [16]byte) (newID [16]byte) {
|
||||
func (u *User) GenAlterIDUsers(alterID int) []*User {
|
||||
users := make([]*User, alterID)
|
||||
preID := u.UUID
|
||||
for i := 0; i < alterID; i++ {
|
||||
for i := range alterID {
|
||||
newID := nextID(preID)
|
||||
// NOTE: alterID user is a user which have a different uuid but a same cmdkey with the primary user.
|
||||
users[i] = &User{UUID: newID, CmdKey: u.CmdKey}
|
||||
|
||||
Reference in new issue
Block a user