當前位置: 首頁>>代碼示例>>Golang>>正文


Golang dice.Roll函數代碼示例

本文整理匯總了Golang中github.com/v2ray/v2ray-core/common/dice.Roll函數的典型用法代碼示例。如果您正苦於以下問題:Golang Roll函數的具體用法?Golang Roll怎麽用?Golang Roll使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Roll函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的github.com/v2ray/v2ray-core/common/dice.Roll函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。