mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 07:26:24 -05:00
Direct reflective json loader
This commit is contained in:
parent
99f761a12e
commit
f518b63157
@ -1,3 +1,5 @@
|
|||||||
|
// +build !confonly
|
||||||
|
|
||||||
package observatory
|
package observatory
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
1
go.sum
1
go.sum
@ -325,6 +325,7 @@ google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2
|
|||||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||||
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||||
|
google.golang.org/protobuf v1.25.1-0.20200805231151-a709e31e5d12 h1:OwhZOOMuf7leLaSCuxtQ9FW7ui2L2L6UKOtKAUqovUQ=
|
||||||
google.golang.org/protobuf v1.25.1-0.20200805231151-a709e31e5d12/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
google.golang.org/protobuf v1.25.1-0.20200805231151-a709e31e5d12/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||||
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
|
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package conf
|
package conf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/golang/protobuf/jsonpb"
|
"github.com/golang/protobuf/jsonpb"
|
||||||
"github.com/jhump/protoreflect/desc"
|
"github.com/jhump/protoreflect/desc"
|
||||||
@ -13,13 +12,13 @@ func (c *Config) BuildServices(service map[string]*json.RawMessage) ([]*serial.T
|
|||||||
var ret []*serial.TypedMessage
|
var ret []*serial.TypedMessage
|
||||||
for k, v := range service {
|
for k, v := range service {
|
||||||
message, err := desc.LoadMessageDescriptor(k)
|
message, err := desc.LoadMessageDescriptor(k)
|
||||||
if err != nil {
|
if err != nil || message == nil {
|
||||||
return nil, newError("Cannot find service", k, "").Base(err)
|
return nil, newError("Cannot find service", k, "").Base(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
serviceConfig := dynamic.NewMessage(message)
|
serviceConfig := dynamic.NewMessage(message)
|
||||||
|
|
||||||
if err := jsonpb.Unmarshal(bytes.NewReader(*v), serviceConfig); err != nil {
|
if err := serviceConfig.UnmarshalJSONPB(&jsonpb.Unmarshaler{AllowUnknownFields: false}, *v); err != nil {
|
||||||
return nil, newError("Cannot interpret service configure file", k, "").Base(err)
|
return nil, newError("Cannot interpret service configure file", k, "").Base(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@ package conf
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"google.golang.org/protobuf/reflect/protoreflect"
|
||||||
|
"google.golang.org/protobuf/reflect/protoregistry"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@ -575,7 +577,18 @@ func (c *Config) Build() (*core.Config, error) {
|
|||||||
developererr := newError("Loading a V2Ray Features as a service is intended for developers only. " +
|
developererr := newError("Loading a V2Ray Features as a service is intended for developers only. " +
|
||||||
"This is used for developers to prototype new features or for an advanced client to use special features in V2Ray," +
|
"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.")
|
" instead of allowing end user to enable it without special tool and knowledge.")
|
||||||
return nil, newError("Cannot load service").Base(developererr).Base(err)
|
sb := strings.Builder{}
|
||||||
|
protoregistry.GlobalTypes.RangeMessages(func(messageType protoreflect.MessageType) bool {
|
||||||
|
switch d := messageType.Descriptor().(type) {
|
||||||
|
case protoreflect.MessageDescriptor:
|
||||||
|
sb.WriteString(string(d.Name()))
|
||||||
|
sb.WriteString(":")
|
||||||
|
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 {
|
} else {
|
||||||
config.App = append(config.App, msg...)
|
config.App = append(config.App, msg...)
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,9 @@ import (
|
|||||||
// Fix dependency cycle caused by core import in internet package
|
// Fix dependency cycle caused by core import in internet package
|
||||||
_ "github.com/v2fly/v2ray-core/v4/transport/internet/tagged/taggedimpl"
|
_ "github.com/v2fly/v2ray-core/v4/transport/internet/tagged/taggedimpl"
|
||||||
|
|
||||||
|
// Developer preview features
|
||||||
|
_ "github.com/v2fly/v2ray-core/v4/app/observatory"
|
||||||
|
|
||||||
// Inbound and outbound proxies.
|
// Inbound and outbound proxies.
|
||||||
_ "github.com/v2fly/v2ray-core/v4/proxy/blackhole"
|
_ "github.com/v2fly/v2ray-core/v4/proxy/blackhole"
|
||||||
_ "github.com/v2fly/v2ray-core/v4/proxy/dns"
|
_ "github.com/v2fly/v2ray-core/v4/proxy/dns"
|
||||||
|
Loading…
Reference in New Issue
Block a user