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 (
|
import (
|
||||||
"github.com/golang/protobuf/proto"
|
"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/app/observatory"
|
||||||
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/duration"
|
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/duration"
|
||||||
@ -16,3 +17,17 @@ type ObservatoryConfig struct {
|
|||||||
func (o *ObservatoryConfig) Build() (proto.Message, error) {
|
func (o *ObservatoryConfig) Build() (proto.Message, error) {
|
||||||
return &observatory.Config{SubjectSelector: o.SubjectSelector, ProbeUrl: o.ProbeURL, ProbeInterval: int64(o.ProbeInterval)}, nil
|
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 (
|
import (
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
|
"github.com/v2fly/v2ray-core/v4/app/observatory/burst"
|
||||||
|
|
||||||
"github.com/v2fly/v2ray-core/v4/app/router"
|
"github.com/v2fly/v2ray-core/v4/app/router"
|
||||||
)
|
)
|
||||||
@ -27,8 +28,6 @@ func (v *strategyEmptyConfig) Build() (proto.Message, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type strategyLeastLoadConfig struct {
|
type strategyLeastLoadConfig struct {
|
||||||
// health check settings
|
|
||||||
HealthCheck *healthCheckSettings `json:"healthCheck,omitempty"`
|
|
||||||
// weight settings
|
// weight settings
|
||||||
Costs []*router.StrategyWeight `json:"costs,omitempty"`
|
Costs []*router.StrategyWeight `json:"costs,omitempty"`
|
||||||
// ping rtt baselines
|
// ping rtt baselines
|
||||||
@ -50,20 +49,19 @@ type healthCheckSettings struct {
|
|||||||
Timeout Duration `json:"timeout"`
|
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.
|
// Build implements Buildable.
|
||||||
func (v *strategyLeastLoadConfig) Build() (proto.Message, error) {
|
func (v *strategyLeastLoadConfig) Build() (proto.Message, error) {
|
||||||
config := &router.StrategyLeastLoadConfig{
|
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.Costs = v.Costs
|
config.Costs = v.Costs
|
||||||
config.Tolerance = float32(v.Tolerance)
|
config.Tolerance = float32(v.Tolerance)
|
||||||
if config.Tolerance < 0 {
|
if config.Tolerance < 0 {
|
||||||
|
@ -351,6 +351,7 @@ type Config struct {
|
|||||||
FakeDNS *FakeDNSConfig `json:"fakeDns"`
|
FakeDNS *FakeDNSConfig `json:"fakeDns"`
|
||||||
BrowserForwarder *BrowserForwarderConfig `json:"browserForwarder"`
|
BrowserForwarder *BrowserForwarderConfig `json:"browserForwarder"`
|
||||||
Observatory *ObservatoryConfig `json:"observatory"`
|
Observatory *ObservatoryConfig `json:"observatory"`
|
||||||
|
BurstObservatory *BurstObservatoryConfig `json:"burstObservatory"`
|
||||||
|
|
||||||
Services map[string]*json.RawMessage `json:"services"`
|
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))
|
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
|
// Load Additional Services that do not have a json translator
|
||||||
|
|
||||||
if msg, err := c.BuildServices(c.Services); err != nil {
|
if msg, err := c.BuildServices(c.Services); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user