1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-02 17:27:50 -04:00
v2fly/proxy/vmess/outbound/receiver.go
2015-12-16 23:53:38 +01:00

42 lines
809 B
Go

package outbound
import (
"math/rand"
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/proxy/vmess"
)
type Receiver struct {
Destination v2net.Destination
Accounts []vmess.User
}
type ReceiverManager struct {
receivers []*Receiver
}
func NewReceiverManager(receivers []*Receiver) *ReceiverManager {
return &ReceiverManager{
receivers: receivers,
}
}
func (this *ReceiverManager) PickReceiver() (v2net.Destination, vmess.User) {
receiverLen := len(this.receivers)
receiverIdx := 0
if receiverLen > 1 {
receiverIdx = rand.Intn(receiverLen)
}
receiver := this.receivers[receiverIdx]
userLen := len(receiver.Accounts)
userIdx := 0
if userLen > 1 {
userIdx = rand.Intn(userLen)
}
user := receiver.Accounts[userIdx]
return receiver.Destination, user
}