1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-10 05:54:22 -04:00
v2fly/proxy/registry/config_cache.go

45 lines
1.2 KiB
Go
Raw Normal View History

package registry
2016-06-10 16:26:39 -04:00
2016-10-13 05:14:24 -04:00
import (
"v2ray.com/core/common/loader"
2016-06-10 16:26:39 -04:00
2016-10-13 05:14:24 -04:00
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/any"
)
2016-09-21 08:39:07 -04:00
2016-10-13 05:14:24 -04:00
var (
inboundConfigCreatorCache = loader.ConfigCreatorCache{}
2016-09-21 08:39:07 -04:00
outboundConfigCreatorCache = loader.ConfigCreatorCache{}
2016-06-10 16:26:39 -04:00
)
func RegisterInboundConfig(protocol string, creator loader.ConfigCreator) error {
2016-09-21 08:39:07 -04:00
return inboundConfigCreatorCache.RegisterCreator(protocol, creator)
2016-06-10 16:26:39 -04:00
}
func RegisterOutboundConfig(protocol string, creator loader.ConfigCreator) error {
2016-09-21 08:39:07 -04:00
return outboundConfigCreatorCache.RegisterCreator(protocol, creator)
2016-06-10 16:26:39 -04:00
}
2016-10-13 05:14:24 -04:00
func MarshalInboundConfig(protocol string, settings *any.Any) (interface{}, error) {
config, err := inboundConfigCreatorCache.CreateConfig(protocol)
if err != nil {
return nil, err
}
if err := ptypes.UnmarshalAny(settings, config.(proto.Message)); err != nil {
return nil, err
}
return config, nil
2016-06-10 16:26:39 -04:00
}
2016-10-13 05:14:24 -04:00
func MarshalOutboundConfig(protocol string, settings *any.Any) (interface{}, error) {
config, err := outboundConfigCreatorCache.CreateConfig(protocol)
if err != nil {
return nil, err
}
if err := ptypes.UnmarshalAny(settings, config.(proto.Message)); err != nil {
return nil, err
}
return config, nil
2016-06-10 16:26:39 -04:00
}