mirror of https://github.com/v2ray/v2ray-core
dice.RandomUint16
parent
3c032f0d53
commit
48eb40ff39
|
@ -84,7 +84,7 @@ func (v *UDPNameServer) AssignUnusedID(response chan<- *ARecord) uint16 {
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
id = uint16(dice.Roll(65536))
|
id = dice.RandomUint16()
|
||||||
if _, found := v.requests[id]; found {
|
if _, found := v.requests[id]; found {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,11 @@ func Roll(n int) int {
|
||||||
return rand.Intn(n)
|
return rand.Intn(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RandomUint16 returns a random uint16 value.
|
||||||
|
func RandomUint16() uint16 {
|
||||||
|
return uint16(rand.Intn(65536))
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rand.Seed(time.Now().Unix())
|
rand.Seed(time.Now().Unix())
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,9 @@ package srtp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"math/rand"
|
|
||||||
|
|
||||||
"v2ray.com/core/common"
|
"v2ray.com/core/common"
|
||||||
|
"v2ray.com/core/common/dice"
|
||||||
"v2ray.com/core/common/serial"
|
"v2ray.com/core/common/serial"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ func (v *SRTP) Write(b []byte) (int, error) {
|
||||||
func NewSRTP(ctx context.Context, config interface{}) (interface{}, error) {
|
func NewSRTP(ctx context.Context, config interface{}) (interface{}, error) {
|
||||||
return &SRTP{
|
return &SRTP{
|
||||||
header: 0xB5E8,
|
header: 0xB5E8,
|
||||||
number: uint16(rand.Intn(65536)),
|
number: dice.RandomUint16(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,9 @@ package utp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"math/rand"
|
|
||||||
|
|
||||||
"v2ray.com/core/common"
|
"v2ray.com/core/common"
|
||||||
|
"v2ray.com/core/common/dice"
|
||||||
"v2ray.com/core/common/serial"
|
"v2ray.com/core/common/serial"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ func NewUTP(ctx context.Context, config interface{}) (interface{}, error) {
|
||||||
return &UTP{
|
return &UTP{
|
||||||
header: 1,
|
header: 1,
|
||||||
extension: 0,
|
extension: 0,
|
||||||
connectionId: uint16(rand.Intn(65536)),
|
connectionId: dice.RandomUint16(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ func (vc *VideoChat) Write(b []byte) (int, error) {
|
||||||
|
|
||||||
func NewVideoChat(ctx context.Context, config interface{}) (interface{}, error) {
|
func NewVideoChat(ctx context.Context, config interface{}) (interface{}, error) {
|
||||||
return &VideoChat{
|
return &VideoChat{
|
||||||
sn: dice.Roll(65535),
|
sn: int(dice.RandomUint16()),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
globalConv = uint32(dice.Roll(65536))
|
globalConv = uint32(dice.RandomUint16())
|
||||||
globalPool = internal.NewConnectionPool()
|
globalPool = internal.NewConnectionPool()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ import (
|
||||||
func TestV2RayClose(t *testing.T) {
|
func TestV2RayClose(t *testing.T) {
|
||||||
assert := assert.On(t)
|
assert := assert.On(t)
|
||||||
|
|
||||||
port := v2net.Port(dice.Roll(65535))
|
port := v2net.Port(dice.RandomUint16())
|
||||||
config := &Config{
|
config := &Config{
|
||||||
Inbound: []*proxyman.InboundHandlerConfig{
|
Inbound: []*proxyman.InboundHandlerConfig{
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue