1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-10-13 06:23:48 -04:00

use two-step register to register explicitly

This commit is contained in:
Shelikhoo 2021-09-04 22:55:12 +01:00
parent 45dae48d21
commit 653bbba843
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316
4 changed files with 9 additions and 6 deletions

View File

@ -6,7 +6,7 @@ import (
"github.com/golang/protobuf/proto"
"github.com/v2fly/v2ray-core/v4/common/protoext"
"github.com/v2fly/v2ray-core/v4/common/serial"
protov2 "google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
"strings"
)
@ -71,8 +71,8 @@ var globalImplementationRegistry = newImplementationRegistry()
// RegisterImplementation register an implementation of a type of interface
// loader(CustomLoader) is a private API, its interface is subject to breaking changes
func RegisterImplementation(proto interface{}, loader CustomLoader) error {
msgDesc := proto.(protov2.Message).ProtoReflect().Type().Descriptor()
func RegisterImplementation(proto protoreflect.MessageDescriptor, loader CustomLoader) error {
msgDesc := proto
fullName := string(msgDesc.FullName())
msgOpts, err := protoext.GetMessageOptions(msgDesc)
if err != nil {

View File

@ -2,7 +2,6 @@ package common
import (
"context"
"github.com/v2fly/v2ray-core/v4/common/registry"
"reflect"
)
@ -18,8 +17,6 @@ func RegisterConfig(config interface{}, configCreator ConfigCreator) error {
return newError(configType.Name() + " is already registered").AtError()
}
typeCreatorRegistry[configType] = configCreator
registry.RegisterImplementation(config, nil)
return nil
}

View File

@ -4,6 +4,7 @@ package freedom
import (
"context"
"github.com/v2fly/v2ray-core/v4/common/registry"
"time"
core "github.com/v2fly/v2ray-core/v4"
@ -38,6 +39,8 @@ func init() {
fullConfig := &Config{}
return common.CreateObject(ctx, fullConfig)
}))
common.Must(registry.RegisterImplementation(new(SimplifiedConfig).ProtoReflect().Descriptor(), nil))
}
// Handler handles Freedom connections.

View File

@ -4,6 +4,7 @@ import (
"context"
"github.com/v2fly/v2ray-core/v4/common"
"github.com/v2fly/v2ray-core/v4/common/protocol"
"github.com/v2fly/v2ray-core/v4/common/registry"
"github.com/v2fly/v2ray-core/v4/proxy/socks"
)
@ -17,6 +18,7 @@ func init() {
}
return common.CreateObject(ctx, fullServer)
}))
common.Must(registry.RegisterImplementation(new(ServerConfig).ProtoReflect().Descriptor(), nil))
common.Must(common.RegisterConfig((*ClientConfig)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
simplifiedClient := config.(*ClientConfig)
@ -30,4 +32,5 @@ func init() {
}
return common.CreateObject(ctx, fullClient)
}))
common.Must(registry.RegisterImplementation(new(ClientConfig).ProtoReflect().Descriptor(), nil))
}