1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-07-03 04:25:23 +00:00
v2fly/proxy/vmess/outbound/receiver.go

42 lines
811 B
Go
Raw Normal View History

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