diff --git a/infra/conf/api.go b/infra/conf/api.go index b8f96b88b..428f56422 100644 --- a/infra/conf/api.go +++ b/infra/conf/api.go @@ -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 diff --git a/infra/conf/observatory.go b/infra/conf/observatory.go new file mode 100644 index 000000000..fd8038e7e --- /dev/null +++ b/infra/conf/observatory.go @@ -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 +} diff --git a/infra/conf/v2ray.go b/infra/conf/v2ray.go index 53aba3287..ea7e16012 100644 --- a/infra/conf/v2ray.go +++ b/infra/conf/v2ray.go @@ -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...)