You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
v2ray-core/proxy/vmess/outbound/receiver.go

42 lines
809 B

9 years ago
package outbound
import (
"math/rand"
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/proxy/vmess"
9 years ago
)
type Receiver struct {
Destination v2net.Destination
Accounts []vmess.User
}
9 years ago
type ReceiverManager struct {
receivers []*Receiver
9 years ago
}
func NewReceiverManager(receivers []*Receiver) *ReceiverManager {
9 years ago
return &ReceiverManager{
receivers: receivers,
}
}
func (this *ReceiverManager) PickReceiver() (v2net.Destination, vmess.User) {
9 years ago
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
9 years ago
}