mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 15:36:41 -05:00
use two-step register to register explicitly
This commit is contained in:
parent
45dae48d21
commit
653bbba843
@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
"github.com/v2fly/v2ray-core/v4/common/protoext"
|
"github.com/v2fly/v2ray-core/v4/common/protoext"
|
||||||
"github.com/v2fly/v2ray-core/v4/common/serial"
|
"github.com/v2fly/v2ray-core/v4/common/serial"
|
||||||
protov2 "google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/reflect/protoreflect"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -71,8 +71,8 @@ var globalImplementationRegistry = newImplementationRegistry()
|
|||||||
|
|
||||||
// RegisterImplementation register an implementation of a type of interface
|
// RegisterImplementation register an implementation of a type of interface
|
||||||
// loader(CustomLoader) is a private API, its interface is subject to breaking changes
|
// loader(CustomLoader) is a private API, its interface is subject to breaking changes
|
||||||
func RegisterImplementation(proto interface{}, loader CustomLoader) error {
|
func RegisterImplementation(proto protoreflect.MessageDescriptor, loader CustomLoader) error {
|
||||||
msgDesc := proto.(protov2.Message).ProtoReflect().Type().Descriptor()
|
msgDesc := proto
|
||||||
fullName := string(msgDesc.FullName())
|
fullName := string(msgDesc.FullName())
|
||||||
msgOpts, err := protoext.GetMessageOptions(msgDesc)
|
msgOpts, err := protoext.GetMessageOptions(msgDesc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -2,7 +2,6 @@ package common
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/v2fly/v2ray-core/v4/common/registry"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,8 +17,6 @@ func RegisterConfig(config interface{}, configCreator ConfigCreator) error {
|
|||||||
return newError(configType.Name() + " is already registered").AtError()
|
return newError(configType.Name() + " is already registered").AtError()
|
||||||
}
|
}
|
||||||
typeCreatorRegistry[configType] = configCreator
|
typeCreatorRegistry[configType] = configCreator
|
||||||
|
|
||||||
registry.RegisterImplementation(config, nil)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ package freedom
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/v2fly/v2ray-core/v4/common/registry"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
core "github.com/v2fly/v2ray-core/v4"
|
core "github.com/v2fly/v2ray-core/v4"
|
||||||
@ -38,6 +39,8 @@ func init() {
|
|||||||
fullConfig := &Config{}
|
fullConfig := &Config{}
|
||||||
return common.CreateObject(ctx, fullConfig)
|
return common.CreateObject(ctx, fullConfig)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
common.Must(registry.RegisterImplementation(new(SimplifiedConfig).ProtoReflect().Descriptor(), nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handler handles Freedom connections.
|
// Handler handles Freedom connections.
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"github.com/v2fly/v2ray-core/v4/common"
|
"github.com/v2fly/v2ray-core/v4/common"
|
||||||
"github.com/v2fly/v2ray-core/v4/common/protocol"
|
"github.com/v2fly/v2ray-core/v4/common/protocol"
|
||||||
|
"github.com/v2fly/v2ray-core/v4/common/registry"
|
||||||
"github.com/v2fly/v2ray-core/v4/proxy/socks"
|
"github.com/v2fly/v2ray-core/v4/proxy/socks"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -17,6 +18,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
return common.CreateObject(ctx, fullServer)
|
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) {
|
common.Must(common.RegisterConfig((*ClientConfig)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
|
||||||
simplifiedClient := config.(*ClientConfig)
|
simplifiedClient := config.(*ClientConfig)
|
||||||
@ -30,4 +32,5 @@ func init() {
|
|||||||
}
|
}
|
||||||
return common.CreateObject(ctx, fullClient)
|
return common.CreateObject(ctx, fullClient)
|
||||||
}))
|
}))
|
||||||
|
common.Must(registry.RegisterImplementation(new(ClientConfig).ProtoReflect().Descriptor(), nil))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user