forked from v2fly/v2ray-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
receiver.go
41 lines (33 loc) · 791 Bytes
/
receiver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
}