mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-12-16 20:27:04 +03:00
Some checks are pending
Build docker image / build-image (push) Waiting to run
Build and Release / prepare (push) Waiting to run
Build and Release / build (386, freebsd, , ) (push) Blocked by required conditions
Build and Release / build (386, linux, , ) (push) Blocked by required conditions
Build and Release / build (386, openbsd, , ) (push) Blocked by required conditions
Build and Release / build (386, windows, , ) (push) Blocked by required conditions
Build and Release / build (386, windows, 1.21.4, win7-32) (push) Blocked by required conditions
Build and Release / build (amd64, darwin, , ) (push) Blocked by required conditions
Build and Release / build (amd64, freebsd, , ) (push) Blocked by required conditions
Build and Release / build (amd64, linux, , ) (push) Blocked by required conditions
Build and Release / build (amd64, openbsd, , ) (push) Blocked by required conditions
Build and Release / build (amd64, windows, , ) (push) Blocked by required conditions
Build and Release / build (amd64, windows, 1.21.4, win7-64) (push) Blocked by required conditions
Build and Release / build (arm, 5, linux) (push) Blocked by required conditions
Build and Release / build (arm, 6, linux) (push) Blocked by required conditions
Build and Release / build (arm, 7, freebsd) (push) Blocked by required conditions
Build and Release / build (arm, 7, linux) (push) Blocked by required conditions
Build and Release / build (arm, 7, openbsd) (push) Blocked by required conditions
Build and Release / build (arm, 7, windows) (push) Blocked by required conditions
Build and Release / build (arm64, android) (push) Blocked by required conditions
Build and Release / build (arm64, darwin) (push) Blocked by required conditions
Build and Release / build (arm64, freebsd) (push) Blocked by required conditions
Build and Release / build (arm64, linux) (push) Blocked by required conditions
Build and Release / build (arm64, openbsd) (push) Blocked by required conditions
Build and Release / build (arm64, windows) (push) Blocked by required conditions
Build and Release / build (loong64, linux) (push) Blocked by required conditions
Build and Release / build (mips, linux) (push) Blocked by required conditions
Build and Release / build (mips64, linux) (push) Blocked by required conditions
Build and Release / build (mips64le, linux) (push) Blocked by required conditions
Build and Release / build (mipsle, linux) (push) Blocked by required conditions
Build and Release / build (ppc64, linux) (push) Blocked by required conditions
Build and Release / build (ppc64le, linux) (push) Blocked by required conditions
Build and Release / build (riscv64, linux) (push) Blocked by required conditions
Build and Release / build (s390x, linux) (push) Blocked by required conditions
Test / test (macos-latest) (push) Waiting to run
Test / test (ubuntu-latest) (push) Waiting to run
Test / test (windows-latest) (push) Waiting to run
94 lines
2.6 KiB
Go
94 lines
2.6 KiB
Go
package conf
|
|
|
|
import (
|
|
"google.golang.org/protobuf/proto"
|
|
|
|
"github.com/xtls/xray-core/app/observatory/burst"
|
|
"github.com/xtls/xray-core/app/router"
|
|
"github.com/xtls/xray-core/infra/conf/cfgcommon/duration"
|
|
)
|
|
|
|
const (
|
|
strategyRandom string = "random"
|
|
strategyLeastPing string = "leastping"
|
|
strategyRoundRobin string = "roundrobin"
|
|
strategyLeastLoad string = "leastload"
|
|
)
|
|
|
|
var (
|
|
strategyConfigLoader = NewJSONConfigLoader(ConfigCreatorCache{
|
|
strategyRandom: func() interface{} { return new(strategyEmptyConfig) },
|
|
strategyLeastPing: func() interface{} { return new(strategyEmptyConfig) },
|
|
strategyRoundRobin: func() interface{} { return new(strategyEmptyConfig) },
|
|
strategyLeastLoad: func() interface{} { return new(strategyLeastLoadConfig) },
|
|
}, "type", "settings")
|
|
)
|
|
|
|
type strategyEmptyConfig struct {
|
|
}
|
|
|
|
func (v *strategyEmptyConfig) Build() (proto.Message, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
type strategyLeastLoadConfig struct {
|
|
// weight settings
|
|
Costs []*router.StrategyWeight `json:"costs,omitempty"`
|
|
// ping rtt baselines
|
|
Baselines []duration.Duration `json:"baselines,omitempty"`
|
|
// expected nodes count to select
|
|
Expected int32 `json:"expected,omitempty"`
|
|
// max acceptable rtt, filter away high delay nodes. default 0
|
|
MaxRTT duration.Duration `json:"maxRTT,omitempty"`
|
|
// acceptable failure rate
|
|
Tolerance float64 `json:"tolerance,omitempty"`
|
|
}
|
|
|
|
// healthCheckSettings holds settings for health Checker
|
|
type healthCheckSettings struct {
|
|
Destination string `json:"destination"`
|
|
Connectivity string `json:"connectivity"`
|
|
Interval duration.Duration `json:"interval"`
|
|
SamplingCount int `json:"sampling"`
|
|
Timeout duration.Duration `json:"timeout"`
|
|
}
|
|
|
|
func (h healthCheckSettings) Build() (proto.Message, error) {
|
|
return &burst.HealthPingConfig{
|
|
Destination: h.Destination,
|
|
Connectivity: h.Connectivity,
|
|
Interval: int64(h.Interval),
|
|
Timeout: int64(h.Timeout),
|
|
SamplingCount: int32(h.SamplingCount),
|
|
}, nil
|
|
}
|
|
|
|
// Build implements Buildable.
|
|
func (v *strategyLeastLoadConfig) Build() (proto.Message, error) {
|
|
config := &router.StrategyLeastLoadConfig{}
|
|
config.Costs = v.Costs
|
|
config.Tolerance = float32(v.Tolerance)
|
|
if config.Tolerance < 0 {
|
|
config.Tolerance = 0
|
|
}
|
|
if config.Tolerance > 1 {
|
|
config.Tolerance = 1
|
|
}
|
|
config.Expected = v.Expected
|
|
if config.Expected < 0 {
|
|
config.Expected = 0
|
|
}
|
|
config.MaxRTT = int64(v.MaxRTT)
|
|
if config.MaxRTT < 0 {
|
|
config.MaxRTT = 0
|
|
}
|
|
config.Baselines = make([]int64, 0)
|
|
for _, b := range v.Baselines {
|
|
if b <= 0 {
|
|
continue
|
|
}
|
|
config.Baselines = append(config.Baselines, int64(b))
|
|
}
|
|
return config, nil
|
|
}
|