@@ -35,30 +35,29 @@ const (
3535 PolicyMinMaxLatency ClientSelectionPolicy = "min-max-latency"
3636)
3737
38- // ClientGroupConfig is the configuration for a client group.
39- type ClientGroupConfig struct {
40- // Name is the name of the client group.
41- Name string `json:"name"`
42-
43- // TCPPolicy is the client selection policy for TCP clients.
38+ // ClientSelectionConfig is the configuration for client selection.
39+ type ClientSelectionConfig [PC TCPConnectivityProbeConfig | UDPConnectivityProbeConfig ] struct {
40+ // Policy is the client selection policy.
4441 // See [ClientSelectionPolicy] for available policies.
45- TCPPolicy ClientSelectionPolicy `json:"tcpPolicy "`
42+ Policy ClientSelectionPolicy `json:"policy "`
4643
47- // UDPPolicy is the client selection policy for UDP clients.
48- // See [ClientSelectionPolicy] for available policies.
49- UDPPolicy ClientSelectionPolicy `json:"udpPolicy"`
44+ // Clients is the list of clients in the group, represented by their names.
45+ Clients []string `json:"clients"`
5046
51- // TCPClients is the list of TCP clients in the group, represented by their names.
52- TCPClients []string `json:"tcpClients"`
47+ // Probe is the configuration for connectivity probes.
48+ Probe PC `json:"probe"`
49+ }
5350
54- // UDPClients is the list of UDP clients in the group, represented by their names.
55- UDPClients []string `json:"udpClients"`
51+ // ClientGroupConfig is the configuration for a client group.
52+ type ClientGroupConfig struct {
53+ // Name is the name of the client group.
54+ Name string `json:"name"`
5655
57- // TCPConnectivityProbe is the configuration for TCP connectivity probes .
58- TCPConnectivityProbe TCPConnectivityProbeConfig `json:"tcpConnectivityProbe "`
56+ // TCP is the client selection configuration for TCP clients .
57+ TCP ClientSelectionConfig [ TCPConnectivityProbeConfig ] `json:"tcp "`
5958
60- // UDPConnectivityProbe is the configuration for UDP connectivity probes .
61- UDPConnectivityProbe UDPConnectivityProbeConfig `json:"udpConnectivityProbe "`
59+ // UDP is the client selection configuration for UDP clients .
60+ UDP ClientSelectionConfig [ UDPConnectivityProbeConfig ] `json:"udp "`
6261}
6362
6463// AddClientGroup creates a client group from the configuration and adds it to the client maps.
@@ -68,13 +67,13 @@ func (c *ClientGroupConfig) AddClientGroup(
6867 udpClientByName map [string ]zerocopy.UDPClient ,
6968 addProbeService func (shadowsocks.Service ),
7069) error {
71- if len (c .TCPClients ) == 0 && len (c .UDPClients ) == 0 {
70+ if len (c .TCP . Clients ) == 0 && len (c .UDP . Clients ) == 0 {
7271 return errors .New ("empty client group" )
7372 }
7473
75- if len (c .TCPClients ) > 0 {
76- clients := make ([]tcpClient , len (c .TCPClients ))
77- for i , name := range c .TCPClients {
74+ if len (c .TCP . Clients ) > 0 {
75+ clients := make ([]tcpClient , len (c .TCP . Clients ))
76+ for i , name := range c .TCP . Clients {
7877 client , ok := tcpClientByName [name ]
7978 if ! ok {
8079 return fmt .Errorf ("TCP client not found: %q" , name )
@@ -86,30 +85,30 @@ func (c *ClientGroupConfig) AddClientGroup(
8685 group zerocopy.TCPClient
8786 service * ProbeService [tcpClient ]
8887 )
89- switch c .TCPPolicy {
88+ switch c .TCP . Policy {
9089 case PolicyRoundRobin :
9190 group = newRoundRobinTCPClientGroup (clients )
9291 case PolicyRandom :
9392 group = newRandomTCPClientGroup (clients )
9493 case PolicyAvailability :
95- group , service = c .TCPConnectivityProbe .newAvailabilityClientGroup (c .Name , logger , clients )
94+ group , service = c .TCP . Probe .newAvailabilityClientGroup (c .Name , logger , clients )
9695 addProbeService (service )
9796 case PolicyLatency :
98- group , service = c .TCPConnectivityProbe .newLatencyClientGroup (c .Name , logger , clients )
97+ group , service = c .TCP . Probe .newLatencyClientGroup (c .Name , logger , clients )
9998 addProbeService (service )
10099 case PolicyMinMaxLatency :
101- group , service = c .TCPConnectivityProbe .newMinMaxLatencyClientGroup (c .Name , logger , clients )
100+ group , service = c .TCP . Probe .newMinMaxLatencyClientGroup (c .Name , logger , clients )
102101 addProbeService (service )
103102 default :
104- return fmt .Errorf ("unknown TCP client selection policy: %q" , c .TCPPolicy )
103+ return fmt .Errorf ("unknown TCP client selection policy: %q" , c .TCP . Policy )
105104 }
106105 tcpClientByName [c .Name ] = group
107106 }
108107
109- if len (c .UDPClients ) > 0 {
110- clients := make ([]zerocopy.UDPClient , len (c .UDPClients ))
108+ if len (c .UDP . Clients ) > 0 {
109+ clients := make ([]zerocopy.UDPClient , len (c .UDP . Clients ))
111110 var info zerocopy.UDPClientInfo
112- for i , name := range c .UDPClients {
111+ for i , name := range c .UDP . Clients {
113112 client , ok := udpClientByName [name ]
114113 if ! ok {
115114 return fmt .Errorf ("UDP client not found: %q" , name )
@@ -122,22 +121,22 @@ func (c *ClientGroupConfig) AddClientGroup(
122121 group zerocopy.UDPClient
123122 service * ProbeService [zerocopy.UDPClient ]
124123 )
125- switch c .UDPPolicy {
124+ switch c .UDP . Policy {
126125 case PolicyRoundRobin :
127126 group = newRoundRobinUDPClientGroup (clients , info )
128127 case PolicyRandom :
129128 group = newRandomUDPClientGroup (clients , info )
130129 case PolicyAvailability :
131- group , service = c .UDPConnectivityProbe .newAvailabilityClientGroup (c .Name , logger , clients , info )
130+ group , service = c .UDP . Probe .newAvailabilityClientGroup (c .Name , logger , clients , info )
132131 addProbeService (service )
133132 case PolicyLatency :
134- group , service = c .UDPConnectivityProbe .newLatencyClientGroup (c .Name , logger , clients , info )
133+ group , service = c .UDP . Probe .newLatencyClientGroup (c .Name , logger , clients , info )
135134 addProbeService (service )
136135 case PolicyMinMaxLatency :
137- group , service = c .UDPConnectivityProbe .newMinMaxLatencyClientGroup (c .Name , logger , clients , info )
136+ group , service = c .UDP . Probe .newMinMaxLatencyClientGroup (c .Name , logger , clients , info )
138137 addProbeService (service )
139138 default :
140- return fmt .Errorf ("unknown UDP client selection policy: %q" , c .UDPPolicy )
139+ return fmt .Errorf ("unknown UDP client selection policy: %q" , c .UDP . Policy )
141140 }
142141 udpClientByName [c .Name ] = group
143142 }
0 commit comments