1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-02 15:36:41 -05:00

Added json loading for the observatory

This commit is contained in:
Shelikhoo 2021-04-08 22:20:30 +01:00
parent fc2a37492a
commit 32f6af48d1
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316
3 changed files with 26 additions and 11 deletions

View File

@ -1,6 +1,7 @@
package conf
import (
"github.com/v2fly/v2ray-core/v4/app/observatory"
"strings"
"github.com/jhump/protoreflect/desc"
@ -34,6 +35,8 @@ func (c *APIConfig) Build() (*commander.Config, error) {
services = append(services, serial.ToTypedMessage(&loggerservice.Config{}))
case "statsservice":
services = append(services, serial.ToTypedMessage(&statsservice.Config{}))
case "observatoryservice":
services = append(services, serial.ToTypedMessage(&observatory.Config{}))
default:
if !strings.HasPrefix(s, "#") {
continue

14
infra/conf/observatory.go Normal file
View File

@ -0,0 +1,14 @@
package conf
import (
"github.com/golang/protobuf/proto"
"github.com/v2fly/v2ray-core/v4/app/observatory"
)
type ObservatoryConfig struct {
SubjectSelector []string `json:"subjectSelector"`
}
func (o ObservatoryConfig) Build() (proto.Message, error) {
return &observatory.Config{SubjectSelector: o.SubjectSelector}, nil
}

View File

@ -6,9 +6,6 @@ import (
"os"
"strings"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"
core "github.com/v2fly/v2ray-core/v4"
"github.com/v2fly/v2ray-core/v4/app/dispatcher"
"github.com/v2fly/v2ray-core/v4/app/proxyman"
@ -356,6 +353,7 @@ type Config struct {
Reverse *ReverseConfig `json:"reverse"`
FakeDNS *FakeDNSConfig `json:"fakeDns"`
BrowserForwarder *BrowserForwarderConfig `json:"browserForwarder"`
Observatory *ObservatoryConfig `json:"observatory"`
Services map[string]*json.RawMessage `json:"services"`
}
@ -572,6 +570,14 @@ func (c *Config) Build() (*core.Config, error) {
config.App = append(config.App, serial.ToTypedMessage(r))
}
if c.Observatory != nil {
r, err := c.Observatory.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 {
@ -579,14 +585,6 @@ func (c *Config) Build() (*core.Config, error) {
"This is used for developers to prototype new features or for an advanced client to use special features in V2Ray," +
" instead of allowing end user to enable it without special tool and knowledge.")
sb := strings.Builder{}
protoregistry.GlobalTypes.RangeMessages(func(messageType protoreflect.MessageType) bool {
switch d := messageType.Descriptor().(type) {
case protoreflect.MessageDescriptor:
sb.WriteString(string(d.FullName()))
sb.WriteString("\n")
}
return true
})
return nil, newError("Cannot load service").Base(developererr).Base(err).Base(newError(sb.String()))
} else {
config.App = append(config.App, msg...)