mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 15:36:41 -05:00
add v4 json support for BurstObservatory & fix balancer reference
This commit is contained in:
parent
b122200c2a
commit
2cdad52334
@ -2,6 +2,7 @@ package conf
|
||||
|
||||
import (
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/v2fly/v2ray-core/v4/app/observatory/burst"
|
||||
|
||||
"github.com/v2fly/v2ray-core/v4/app/observatory"
|
||||
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/duration"
|
||||
@ -16,3 +17,17 @@ type ObservatoryConfig struct {
|
||||
func (o *ObservatoryConfig) Build() (proto.Message, error) {
|
||||
return &observatory.Config{SubjectSelector: o.SubjectSelector, ProbeUrl: o.ProbeURL, ProbeInterval: int64(o.ProbeInterval)}, nil
|
||||
}
|
||||
|
||||
type BurstObservatoryConfig struct {
|
||||
SubjectSelector []string `json:"subjectSelector"`
|
||||
// health check settings
|
||||
HealthCheck *healthCheckSettings `json:"pingConfig,omitempty"`
|
||||
}
|
||||
|
||||
func (b BurstObservatoryConfig) Build() (proto.Message, error) {
|
||||
if result, err := b.HealthCheck.Build(); err != nil {
|
||||
return &burst.Config{SubjectSelector: b.SubjectSelector, PingConfig: result.(*burst.HealthPingConfig)}, nil
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package conf
|
||||
|
||||
import (
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/v2fly/v2ray-core/v4/app/observatory/burst"
|
||||
|
||||
"github.com/v2fly/v2ray-core/v4/app/router"
|
||||
)
|
||||
@ -27,8 +28,6 @@ func (v *strategyEmptyConfig) Build() (proto.Message, error) {
|
||||
}
|
||||
|
||||
type strategyLeastLoadConfig struct {
|
||||
// health check settings
|
||||
HealthCheck *healthCheckSettings `json:"healthCheck,omitempty"`
|
||||
// weight settings
|
||||
Costs []*router.StrategyWeight `json:"costs,omitempty"`
|
||||
// ping rtt baselines
|
||||
@ -50,20 +49,19 @@ type healthCheckSettings struct {
|
||||
Timeout 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{
|
||||
HealthCheck: &router.HealthPingConfig{},
|
||||
}
|
||||
if v.HealthCheck != nil {
|
||||
config.HealthCheck = &router.HealthPingConfig{
|
||||
Destination: v.HealthCheck.Destination,
|
||||
Connectivity: v.HealthCheck.Connectivity,
|
||||
Interval: int64(v.HealthCheck.Interval),
|
||||
Timeout: int64(v.HealthCheck.Timeout),
|
||||
SamplingCount: int32(v.HealthCheck.SamplingCount),
|
||||
}
|
||||
}
|
||||
config := &router.StrategyLeastLoadConfig{}
|
||||
config.Costs = v.Costs
|
||||
config.Tolerance = float32(v.Tolerance)
|
||||
if config.Tolerance < 0 {
|
||||
|
@ -351,6 +351,7 @@ type Config struct {
|
||||
FakeDNS *FakeDNSConfig `json:"fakeDns"`
|
||||
BrowserForwarder *BrowserForwarderConfig `json:"browserForwarder"`
|
||||
Observatory *ObservatoryConfig `json:"observatory"`
|
||||
BurstObservatory *BurstObservatoryConfig `json:"burstObservatory"`
|
||||
|
||||
Services map[string]*json.RawMessage `json:"services"`
|
||||
}
|
||||
@ -491,6 +492,14 @@ func (c *Config) Build() (*core.Config, error) {
|
||||
config.App = append(config.App, serial.ToTypedMessage(r))
|
||||
}
|
||||
|
||||
if c.BurstObservatory != nil {
|
||||
r, err := c.BurstObservatory.Build()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config.App = append(config.App, serial.ToTypedMessage(r))
|
||||
}
|
||||
|
||||
// Load Additional Services that do not have a json translator
|
||||
|
||||
if msg, err := c.BuildServices(c.Services); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user