当前位置: 首页>>代码示例>>Golang>>正文


Golang dice.Roll函数代码示例

本文整理汇总了Golang中v2ray/com/core/common/dice.Roll函数的典型用法代码示例。如果您正苦于以下问题:Golang Roll函数的具体用法?Golang Roll怎么用?Golang Roll使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Roll函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestNormalGetRequest

func TestNormalGetRequest(t *testing.T) {
	assert := assert.On(t)

	testPacketDispatcher := testdispatcher.NewTestPacketDispatcher(nil)

	port := v2net.Port(dice.Roll(20000) + 10000)
	httpProxy := NewServer(
		&Config{},
		testPacketDispatcher,
		&proxy.InboundHandlerMeta{
			Address: v2net.LocalHostIP,
			Port:    port,
			StreamSettings: &internet.StreamSettings{
				Type: internet.StreamConnectionTypeRawTCP,
			}})
	defer httpProxy.Close()

	err := httpProxy.Start()
	assert.Error(err).IsNil()
	assert.Port(port).Equals(httpProxy.Port())

	httpClient := &http.Client{}
	resp, err := httpClient.Get("http://127.0.0.1:" + port.String() + "/")
	assert.Error(err).IsNil()
	assert.Int(resp.StatusCode).Equals(400)
}
开发者ID:DZLZHCODE,项目名称:v2ray-core,代码行数:26,代码来源:server_test.go

示例2: EncodeRequestHeader

func (v *ClientSession) EncodeRequestHeader(header *protocol.RequestHeader, writer io.Writer) {
	timestamp := protocol.NewTimestampGenerator(protocol.NowTime(), 30)()
	account, err := header.User.GetTypedAccount()
	if err != nil {
		log.Error("VMess: Failed to get user account: ", err)
		return
	}
	idHash := v.idHash(account.(*vmess.InternalAccount).AnyValidID().Bytes())
	idHash.Write(timestamp.Bytes(nil))
	writer.Write(idHash.Sum(nil))

	buffer := make([]byte, 0, 512)
	buffer = append(buffer, Version)
	buffer = append(buffer, v.requestBodyIV...)
	buffer = append(buffer, v.requestBodyKey...)
	buffer = append(buffer, v.responseHeader, byte(header.Option))
	padingLen := dice.Roll(16)
	if header.Security.Is(protocol.SecurityType_LEGACY) {
		// Disable padding in legacy mode for a smooth transition.
		padingLen = 0
	}
	security := byte(padingLen<<4) | byte(header.Security)
	buffer = append(buffer, security, byte(0), byte(header.Command))
	buffer = header.Port.Bytes(buffer)

	switch header.Address.Family() {
	case v2net.AddressFamilyIPv4:
		buffer = append(buffer, AddrTypeIPv4)
		buffer = append(buffer, header.Address.IP()...)
	case v2net.AddressFamilyIPv6:
		buffer = append(buffer, AddrTypeIPv6)
		buffer = append(buffer, header.Address.IP()...)
	case v2net.AddressFamilyDomain:
		buffer = append(buffer, AddrTypeDomain, byte(len(header.Address.Domain())))
		buffer = append(buffer, header.Address.Domain()...)
	}

	if padingLen > 0 {
		pading := make([]byte, padingLen)
		rand.Read(pading)
		buffer = append(buffer, pading...)
	}

	fnv1a := fnv.New32a()
	fnv1a.Write(buffer)

	buffer = fnv1a.Sum(buffer)

	timestampHash := md5.New()
	timestampHash.Write(hashTimestamp(timestamp))
	iv := timestampHash.Sum(nil)
	aesStream := crypto.NewAesEncryptionStream(account.(*vmess.InternalAccount).ID.CmdKey(), iv)
	aesStream.XORKeyStream(buffer, buffer)
	writer.Write(buffer)

	return
}
开发者ID:v2ray,项目名称:v2ray-core,代码行数:57,代码来源:client.go

示例3: GetConnectionHandler

func (this *InboundDetourHandlerDynamic) GetConnectionHandler() (proxy.InboundHandler, int) {
	this.RLock()
	defer this.RUnlock()
	ich := this.ichs[dice.Roll(len(this.ichs))]
	until := int(this.config.GetAllocationStrategyValue().Refresh.GetValue()) - int((time.Now().Unix()-this.lastRefresh.Unix())/60/1000)
	if until < 0 {
		until = 0
	}
	return ich, int(until)
}
开发者ID:xyz12810,项目名称:v2ray-core,代码行数:10,代码来源:inbound_detour_dynamic.go

示例4: 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.FromPort() + v2net.Port(r)
		_, used := this.portsInUse[port]
		if !used {
			return port
		}
	}
}
开发者ID:xyz12810,项目名称:v2ray-core,代码行数:11,代码来源:inbound_detour_dynamic.go

示例5: PickUser

func (v *ServerSpec) PickUser() *User {
	userCount := len(v.users)
	switch userCount {
	case 0:
		return nil
	case 1:
		return v.users[0]
	default:
		return v.users[dice.Roll(userCount)]
	}
}
开发者ID:ylywyn,项目名称:v2ray-core,代码行数:11,代码来源:server_spec.go

示例6: pickString

func pickString(arr []string) string {
	n := len(arr)
	switch n {
	case 0:
		return ""
	case 1:
		return arr[0]
	default:
		return arr[dice.Roll(n)]
	}
}
开发者ID:ylywyn,项目名称:v2ray-core,代码行数:11,代码来源:config.go

示例7: Enqueue

func (v *UDPPayloadQueue) Enqueue(payload UDPPayload) {
	size := len(v.queue)
	idx := 0
	if size > 1 {
		idx = dice.Roll(size)
	}
	for i := 0; i < size; i++ {
		select {
		case v.queue[idx%size] <- payload:
			return
		default:
			idx++
		}
	}
}
开发者ID:v2ray,项目名称:v2ray-core,代码行数:15,代码来源:hub.go

示例8: allocatePort

func (h *DynamicInboundHandler) allocatePort() v2net.Port {
	from := int(h.receiverConfig.PortRange.From)
	delta := int(h.receiverConfig.PortRange.To) - from + 1
	h.Lock()
	defer h.Unlock()

	for {
		r := dice.Roll(delta)
		port := v2net.Port(from + r)
		_, used := h.portsInUse[port]
		if !used {
			h.portsInUse[port] = true
			return port
		}
	}
}
开发者ID:ylywyn,项目名称:v2ray-core,代码行数:16,代码来源:dynamic.go

示例9: ResolveIP

// Private: Visible for testing.
func (this *FreedomConnection) ResolveIP(destination v2net.Destination) v2net.Destination {
	if !destination.Address.Family().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.Network == v2net.Network_TCP {
		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:xyz12810,项目名称:v2ray-core,代码行数:22,代码来源:freedom.go

示例10: AssignUnusedID

// Private: Visible for testing.
func (v *UDPNameServer) AssignUnusedID(response chan<- *ARecord) uint16 {
	var id uint16
	v.Lock()
	if len(v.requests) > CleanupThreshold && v.nextCleanup.Before(time.Now()) {
		v.nextCleanup = time.Now().Add(CleanupInterval)
		go v.Cleanup()
	}

	for {
		id = uint16(dice.Roll(65536))
		if _, found := v.requests[id]; found {
			continue
		}
		log.Debug("DNS: Add pending request id ", id)
		v.requests[id] = &PendingRequest{
			expire:   time.Now().Add(time.Second * 8),
			response: response,
		}
		break
	}
	v.Unlock()
	return id
}
开发者ID:ylywyn,项目名称:v2ray-core,代码行数:24,代码来源:nameserver.go

示例11: GetConnectionHandler

func (this *InboundDetourHandlerAlways) GetConnectionHandler() (proxy.InboundHandler, int) {
	ich := this.ich[dice.Roll(len(this.ich))]
	return ich, this.config.Allocation.Refresh
}
开发者ID:DZLZHCODE,项目名称:v2ray-core,代码行数:4,代码来源:inbound_detour_always.go

示例12: AnyValidID

func (v *InternalAccount) AnyValidID() *protocol.ID {
	if len(v.AlterIDs) == 0 {
		return v.ID
	}
	return v.AlterIDs[dice.Roll(len(v.AlterIDs))]
}
开发者ID:v2ray,项目名称:v2ray-core,代码行数:6,代码来源:account.go

示例13: GetRandomInboundProxy

func (h *AlwaysOnInboundHandler) GetRandomInboundProxy() (proxy.Inbound, net.Port, int) {
	w := h.workers[dice.Roll(len(h.workers))]
	return w.Proxy(), w.Port(), 9999
}
开发者ID:ylywyn,项目名称:v2ray-core,代码行数:4,代码来源:always.go

示例14: PickUser

func (this *ServerSpec) PickUser() *User {
	userCount := len(this.users)
	return this.users[dice.Roll(userCount)]
}
开发者ID:DZLZHCODE,项目名称:v2ray-core,代码行数:4,代码来源:server_spec.go

示例15: NewVideoChat

func NewVideoChat(ctx context.Context, config interface{}) (interface{}, error) {
	return &VideoChat{
		sn: dice.Roll(65535),
	}, nil
}
开发者ID:ylywyn,项目名称:v2ray-core,代码行数:5,代码来源:wechat.go


注:本文中的v2ray/com/core/common/dice.Roll函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。