本文整理汇总了Golang中github.com/v2ray/v2ray-core/common/dice.Roll函数的典型用法代码示例。如果您正苦于以下问题:Golang Roll函数的具体用法?Golang Roll怎么用?Golang Roll使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Roll函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Dial
func Dial(dest v2net.Destination) (net.Conn, error) {
var ip net.IP
if dest.Address().IsIPv4() || dest.Address().IsIPv6() {
ip = dest.Address().IP()
} else {
ips, err := net.LookupIP(dest.Address().Domain())
if err != nil {
return nil, err
}
if len(ips) == 0 {
return nil, ErrInvalidHost
}
ip = ips[dice.Roll(len(ips))]
}
if dest.IsTCP() {
return net.DialTCP("tcp", nil, &net.TCPAddr{
IP: ip,
Port: int(dest.Port()),
})
} else {
return net.DialUDP("udp", nil, &net.UDPAddr{
IP: ip,
Port: int(dest.Port()),
})
}
}
开发者ID:airmao,项目名称:v2ray-core,代码行数:26,代码来源:dialer.go
示例2: GetConnectionHandler
func (this *InboundDetourHandlerDynamic) GetConnectionHandler() (proxy.InboundHandler, int) {
this.RLock()
defer this.RUnlock()
ich := this.ichInUse[dice.Roll(len(this.ichInUse))]
until := this.config.Allocation.Refresh - int((time.Now().Unix()-this.lastRefresh.Unix())/60/1000)
if until < 0 {
until = 0
}
return ich, int(until)
}
开发者ID:wangyou,项目名称:v2ray-core,代码行数:10,代码来源:inbound_detour_dynamic.go
示例3: pickUnusedPort
func (this *InboundDetourHandlerDynamic) pickUnusedPort() v2net.Port {
delta := int(this.config.PortRange.To) - int(this.config.PortRange.From) + 1
for {
r := dice.Roll(delta)
port := this.config.PortRange.From + v2net.Port(r)
_, used := this.portsInUse[port]
if !used {
return port
}
}
}
开发者ID:wangyou,项目名称:v2ray-core,代码行数:11,代码来源:inbound_detour_dynamic.go
示例4: ResolveIP
// @Private
func (this *FreedomConnection) ResolveIP(destination v2net.Destination) v2net.Destination {
if !destination.Address().IsDomain() {
return destination
}
ips := this.dns.Get(destination.Address().Domain())
if len(ips) == 0 {
log.Info("Freedom: DNS returns nil answer. Keep domain as is.")
return destination
}
ip := ips[dice.Roll(len(ips))]
var newDest v2net.Destination
if destination.IsTCP() {
newDest = v2net.TCPDestination(v2net.IPAddress(ip), destination.Port())
} else {
newDest = v2net.UDPDestination(v2net.IPAddress(ip), destination.Port())
}
log.Info("Freedom: Changing destination from ", destination, " to ", newDest)
return newDest
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:22,代码来源:freedom.go
示例5: pickDetour
func (this *ReceiverManager) pickDetour() *Receiver {
if len(this.detours) == 0 {
return nil
}
this.detourAccess.RLock()
idx := dice.Roll(len(this.detours))
rec := this.detours[idx]
this.detourAccess.RUnlock()
if rec.Expired() {
this.detourAccess.Lock()
detourLen := len(this.detours)
if detourLen > idx && this.detours[idx].Expired() {
this.detours[idx] = this.detours[detourLen-1]
this.detours = this.detours[:detourLen-1]
}
this.detourAccess.Unlock()
return nil
}
return rec.Receiver
}
开发者ID:orvice,项目名称:v2ray-core,代码行数:22,代码来源:receiver.go
示例6: AssignUnusedID
// @Private
func (this *UDPNameServer) AssignUnusedID(response chan<- *ARecord) uint16 {
var id uint16
this.Lock()
if len(this.requests) > CleanupThreshold && this.nextCleanup.Before(time.Now()) {
this.nextCleanup = time.Now().Add(CleanupInterval)
go this.Cleanup()
}
for {
id = uint16(dice.Roll(65536))
if _, found := this.requests[id]; found {
continue
}
log.Debug("DNS: Add pending request id ", id)
this.requests[id] = &PendingRequest{
expire: time.Now().Add(time.Second * 8),
response: response,
}
break
}
this.Unlock()
return id
}
开发者ID:yueyingjuesha,项目名称:v2ray-core,代码行数:24,代码来源:nameserver.go
示例7: AnyValidID
func (this *User) AnyValidID() *ID {
if len(this.AlterIDs) == 0 {
return this.ID
}
return this.AlterIDs[dice.Roll(len(this.AlterIDs))]
}
开发者ID:jim1568cas,项目名称:v2ray-core,代码行数:6,代码来源:user.go
示例8: PickPort
func PickPort() v2net.Port {
return v2net.Port(30000 + dice.Roll(20000))
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:3,代码来源:port.go
示例9: GetConnectionHandler
func (this *InboundDetourHandlerAlways) GetConnectionHandler() (proxy.InboundHandler, int) {
ich := this.ich[dice.Roll(len(this.ich))]
return ich.handler, this.config.Allocation.Refresh
}
开发者ID:airmao,项目名称:v2ray-core,代码行数:4,代码来源:inbound_detour_always.go
示例10: DialKCP
package kcp
import (
"net"
"sync/atomic"
"github.com/v2ray/v2ray-core/common/dice"
"github.com/v2ray/v2ray-core/common/log"
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/transport/internet"
)
var (
globalConv = uint32(dice.Roll(65536))
)
func DialKCP(src v2net.Address, dest v2net.Destination) (internet.Connection, error) {
udpDest := v2net.UDPDestination(dest.Address(), dest.Port())
log.Info("Dialling KCP to ", udpDest)
conn, err := internet.DialToDest(src, udpDest)
if err != nil {
return nil, err
}
cpip := NewSimpleAuthenticator()
conv := uint16(atomic.AddUint32(&globalConv, 1))
session := NewConnection(conv, conn, conn.LocalAddr().(*net.UDPAddr), conn.RemoteAddr().(*net.UDPAddr), cpip)
session.FetchInputFrom(conn)
return session, nil
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:31,代码来源:dialer.go
示例11: AnyValidID
func (this *VMessAccount) AnyValidID() *ID {
if len(this.AlterIDs) == 0 {
return this.ID
}
return this.AlterIDs[dice.Roll(len(this.AlterIDs))]
}
开发者ID:xiaomotou,项目名称:v2ray-core,代码行数:6,代码来源:account.go
示例12: PickUser
func (this *Receiver) PickUser() *proto.User {
return this.Accounts[dice.Roll(len(this.Accounts))]
}
开发者ID:orvice,项目名称:v2ray-core,代码行数:3,代码来源:receiver.go
示例13: pickStdReceiver
func (this *ReceiverManager) pickStdReceiver() *Receiver {
return this.receivers[dice.Roll(len(this.receivers))]
}
开发者ID:orvice,项目名称:v2ray-core,代码行数:3,代码来源:receiver.go
示例14: AnyValidID
func (this *Account) AnyValidID() *protocol.ID {
if len(this.AlterIDs) == 0 {
return this.ID
}
return this.AlterIDs[dice.Roll(len(this.AlterIDs))]
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:6,代码来源:vmess.go
示例15: PickUser
func (this *ServerSpec) PickUser() *User {
userCount := len(this.users)
return this.users[dice.Roll(userCount)]
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:4,代码来源:server_spec.go
示例16: NewTimestampGenerator
func NewTimestampGenerator(base Timestamp, delta int) TimestampGenerator {
return func() Timestamp {
rangeInDelta := dice.Roll(delta*2) - delta
return base + Timestamp(rangeInDelta)
}
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:6,代码来源:time.go
注:本文中的github.com/v2ray/v2ray-core/common/dice.Roll函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论