1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-17 18:06:15 -05:00
v2fly/proxy/vmess/outbound/receiver.go

42 lines
809 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 {
2015-12-16 17:53:38 -05:00
Destination v2net.Destination
Accounts []vmess.User
2015-12-07 14:32:38 -05:00
}
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-16 17:53:38 -05:00
func (this *ReceiverManager) PickReceiver() (v2net.Destination, 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]
2015-12-16 17:53:38 -05:00
return receiver.Destination, user
2015-12-04 19:16:21 -05:00
}