mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-11-02 17:27:50 -04:00
42 lines
791 B
Go
42 lines
791 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 {
|
|
Address v2net.Address
|
|
Accounts []vmess.User
|
|
}
|
|
|
|
type ReceiverManager struct {
|
|
receivers []*Receiver
|
|
}
|
|
|
|
func NewReceiverManager(receivers []*Receiver) *ReceiverManager {
|
|
return &ReceiverManager{
|
|
receivers: receivers,
|
|
}
|
|
}
|
|
|
|
func (this *ReceiverManager) PickReceiver() (v2net.Address, 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.Address, user
|
|
}
|