2016-08-17 17:30:15 -04:00
|
|
|
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
|
|
|
}
|