1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-10-02 16:56:02 -04:00
v2fly/proxy/vmess/outbound/receiver.go

42 lines
791 B
Go
Raw Normal View History

2015-12-04 19:16:21 -05:00
package outbound
import (
"math/rand"
v2net "github.com/v2ray/v2ray-core/common/net"
2015-12-07 14:32:38 -05:00
"github.com/v2ray/v2ray-core/proxy/vmess"
2015-12-04 19:16:21 -05:00
)
2015-12-07 14:32:38 -05:00
type Receiver struct {
Address v2net.Address
Accounts []vmess.User
}
2015-12-04 19:16:21 -05:00
type ReceiverManager struct {
2015-12-07 14:32:38 -05:00
receivers []*Receiver
2015-12-04 19:16:21 -05:00
}
2015-12-07 14:32:38 -05:00
func NewReceiverManager(receivers []*Receiver) *ReceiverManager {
2015-12-04 19:16:21 -05:00
return &ReceiverManager{
receivers: receivers,
}
}
2015-12-07 14:32:38 -05:00
func (this *ReceiverManager) PickReceiver() (v2net.Address, vmess.User) {
2015-12-04 19:16:21 -05:00
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
}