Browse Source

add v4 json support for BurstObservatory & fix balancer reference

Shelikhoo 4 years ago
parent
commit
2cdad52334
3 changed files with 36 additions and 14 deletions
  1. 15 0
      infra/conf/observatory.go
  2. 12 14
      infra/conf/router_strategy.go
  3. 9 0
      infra/conf/v2ray.go

+ 15 - 0
infra/conf/observatory.go

@@ -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
+	}
+}

+ 12 - 14
infra/conf/router_strategy.go

@@ -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{
-		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.Costs = v.Costs
 	config.Tolerance = float32(v.Tolerance)
 	config.Tolerance = float32(v.Tolerance)
 	if config.Tolerance < 0 {
 	if config.Tolerance < 0 {

+ 9 - 0
infra/conf/v2ray.go

@@ -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 {