Documentation
¶
Overview ¶
Package clientgroups provides aggregate clients that join multiple TCP and UDP clients into a single client group. The client group uses one of the client selection policies to choose a client from the group for each connection.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientGroupConfig ¶
type ClientGroupConfig struct {
// Name is the name of the client group.
Name string `json:"name"`
// TCP is the client selection configuration for TCP clients.
TCP ClientSelectionConfig[TCPConnectivityProbeConfig] `json:"tcp,omitzero"`
// UDP is the client selection configuration for UDP clients.
UDP ClientSelectionConfig[UDPConnectivityProbeConfig] `json:"udp,omitzero"`
}
ClientGroupConfig is the configuration for a client group.
func (*ClientGroupConfig) AddClientGroup ¶
func (c *ClientGroupConfig) AddClientGroup( logger *zap.Logger, tcpClientByName map[string]netio.StreamClient, udpClientByName map[string]zerocopy.UDPClient, addProbeService func(shadowsocks.Service), ) error
AddClientGroup creates a client group from the configuration and adds it to the client maps.
type ClientSelectionConfig ¶
type ClientSelectionConfig[PC TCPConnectivityProbeConfig | UDPConnectivityProbeConfig] struct { // Policy is the client selection policy. // See [ClientSelectionPolicy] for available policies. Policy ClientSelectionPolicy `json:"policy"` // Clients is the list of clients in the group, represented by their names. Clients []string `json:"clients"` // Probe is the configuration for connectivity probes. Probe PC `json:"probe,omitzero"` }
ClientSelectionConfig is the configuration for client selection.
type ClientSelectionPolicy ¶
type ClientSelectionPolicy string
ClientSelectionPolicy is a client selection policy.
const ( // PolicyRoundRobin selects clients in a round-robin fashion. PolicyRoundRobin ClientSelectionPolicy = "round-robin" // PolicyRandom selects clients randomly. PolicyRandom ClientSelectionPolicy = "random" // PolicyAvailability selects the client with the highest availability. PolicyAvailability ClientSelectionPolicy = "availability" // PolicyLatency selects the client with the lowest average latency. PolicyLatency ClientSelectionPolicy = "latency" // PolicyMinMaxLatency selects the client with the lowest worst latency. PolicyMinMaxLatency ClientSelectionPolicy = "min-max-latency" )
type ConnectivityProbeConfig ¶
type ConnectivityProbeConfig struct {
// Timeout is the timeout for each connectivity test.
//
// Default is 5 seconds.
Timeout jsoncfg.Duration `json:"timeout,omitzero"`
// Interval is the interval between connectivity tests.
//
// Default is 30 seconds.
Interval jsoncfg.Duration `json:"interval,omitzero"`
// Concurrency is the maximum number of concurrent connectivity tests.
//
// Default is 32.
Concurrency int `json:"concurrency,omitzero"`
}
ConnectivityProbeConfig is the shared part of the configuration for TCP and UDP connectivity probes.
type ProbeService ¶
type ProbeService[C any] struct { // contains filtered or unexported fields }
ProbeService runs the probe loop.
ProbeService implements shadowsocks.Service.
func NewProbeService ¶
func NewProbeService[C any]( zapField zap.Field, logger *zap.Logger, selector *atomicClientSelector[C], pc probeConfig[C], start func(ctx context.Context, logger *zap.Logger, selector *atomicClientSelector[C], pc probeConfig[C]) error, ) *ProbeService[C]
NewProbeService returns a new probe service.
func (*ProbeService[C]) Start ¶
func (s *ProbeService[C]) Start(ctx context.Context) error
Start implements shadowsocks.Service.Start.
func (*ProbeService[C]) Stop ¶
func (*ProbeService[C]) Stop() error
Stop implements shadowsocks.Service.Stop.
func (*ProbeService[C]) ZapField ¶
func (s *ProbeService[C]) ZapField() zap.Field
ZapField implements shadowsocks.Service.ZapField.
type TCPConnectivityProbeConfig ¶
type TCPConnectivityProbeConfig struct {
ConnectivityProbeConfig
// Address is the address of the HTTP test endpoint.
//
// Default is "clients3.google.com:80".
Address conn.Addr `json:"address,omitzero"`
// EscapedPath is the escaped URL path of the HTTP test endpoint.
//
// Default is "/generate_204".
EscapedPath string `json:"escapedPath,omitzero"`
// Host specifies the value of the Host header field in the HTTP request.
//
// Default is "clients3.google.com".
Host string `json:"host,omitzero"`
}
TCPConnectivityProbeConfig controls how TCP clients are probed when the client selection policy requires doing connectivity probes.
type UDPConnectivityProbeConfig ¶
type UDPConnectivityProbeConfig struct {
ConnectivityProbeConfig
// Address is the address of the UDP DNS server.
//
// Default is "[2606:4700:4700::1111]:53".
Address conn.Addr `json:"address,omitzero"`
}
UDPConnectivityProbeConfig controls how UDP clients are probed when the client selection policy requires doing connectivity probes.