mirror of
https://github.com/v2ray/v2ray-core.git
synced 2026-11-13 22:45:13 +00:00
dice.Roll()
This commit is contained in:
1 parent
d623b1809d
commit
37a9d8ef50
6 files changed
+23
-36
No files matched your search
@@ -2,9 +2,9 @@ package dialer
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math/rand"
|
||||
"net"
|
||||
|
||||
"github.com/v2ray/v2ray-core/common/dice"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
)
|
||||
|
||||
@@ -24,11 +24,7 @@ func Dial(dest v2net.Destination) (net.Conn, error) {
|
||||
if len(ips) == 0 {
|
||||
return nil, ErrInvalidHost
|
||||
}
|
||||
if len(ips) == 1 {
|
||||
ip = ips[0]
|
||||
} else {
|
||||
ip = ips[rand.Intn(len(ips))]
|
||||
}
|
||||
ip = ips[dice.Roll(len(ips))]
|
||||
}
|
||||
if dest.IsTCP() {
|
||||
return net.DialTCP("tcp", nil, &net.TCPAddr{
|
||||
|
||||
@@ -19,6 +19,7 @@ func TestDialDomain(t *testing.T) {
|
||||
}
|
||||
dest, err := server.Start()
|
||||
assert.Error(err).IsNil()
|
||||
defer server.Close()
|
||||
|
||||
conn, err := Dial(v2net.TCPDestination(v2net.DomainAddress("local.v2ray.com"), dest.Port()))
|
||||
assert.Error(err).IsNil()
|
||||
|
||||
Reference in new issue
Block a user