config loader

pull/314/head
Darien Raymond 8 years ago
parent 84f660bbbc
commit 35a0ed6fb4
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

@ -1,9 +1,6 @@
package core package core
import ( import (
"io"
"v2ray.com/core/common"
"v2ray.com/core/proxy/registry" "v2ray.com/core/proxy/registry"
) )
@ -31,16 +28,3 @@ func (this *InboundConnectionConfig) GetAllocationStrategyValue() *AllocationStr
func (this *InboundConnectionConfig) GetTypedSettings() (interface{}, error) { func (this *InboundConnectionConfig) GetTypedSettings() (interface{}, error) {
return registry.MarshalInboundConfig(this.Protocol, this.Settings) return registry.MarshalInboundConfig(this.Protocol, this.Settings)
} }
type ConfigLoader func(input io.Reader) (*Config, error)
var (
configLoader ConfigLoader
)
func LoadConfig(input io.Reader) (*Config, error) {
if configLoader == nil {
return nil, common.ErrBadConfiguration
}
return configLoader(input)
}

@ -41,6 +41,27 @@ var _ = math.Inf
// proto package needs to be updated. // proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
type ConfigFormat int32
const (
ConfigFormat_Protobuf ConfigFormat = 0
ConfigFormat_JSON ConfigFormat = 1
)
var ConfigFormat_name = map[int32]string{
0: "Protobuf",
1: "JSON",
}
var ConfigFormat_value = map[string]int32{
"Protobuf": 0,
"JSON": 1,
}
func (x ConfigFormat) String() string {
return proto.EnumName(ConfigFormat_name, int32(x))
}
func (ConfigFormat) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
type AllocationStrategy_Type int32 type AllocationStrategy_Type int32
const ( const (
@ -262,57 +283,59 @@ func init() {
proto.RegisterType((*InboundConnectionConfig)(nil), "v2ray.core.InboundConnectionConfig") proto.RegisterType((*InboundConnectionConfig)(nil), "v2ray.core.InboundConnectionConfig")
proto.RegisterType((*OutboundConnectionConfig)(nil), "v2ray.core.OutboundConnectionConfig") proto.RegisterType((*OutboundConnectionConfig)(nil), "v2ray.core.OutboundConnectionConfig")
proto.RegisterType((*Config)(nil), "v2ray.core.Config") proto.RegisterType((*Config)(nil), "v2ray.core.Config")
proto.RegisterEnum("v2ray.core.ConfigFormat", ConfigFormat_name, ConfigFormat_value)
proto.RegisterEnum("v2ray.core.AllocationStrategy_Type", AllocationStrategy_Type_name, AllocationStrategy_Type_value) proto.RegisterEnum("v2ray.core.AllocationStrategy_Type", AllocationStrategy_Type_name, AllocationStrategy_Type_value)
} }
func init() { proto.RegisterFile("v2ray.com/core/config.proto", fileDescriptor0) } func init() { proto.RegisterFile("v2ray.com/core/config.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{ var fileDescriptor0 = []byte{
// 723 bytes of a gzipped FileDescriptorProto // 751 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xa4, 0x95, 0xdb, 0x6e, 0xd3, 0x30, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xa4, 0x95, 0xed, 0x6e, 0xeb, 0x34,
0x18, 0xc7, 0xe9, 0x61, 0x5d, 0xfb, 0x75, 0x8c, 0xca, 0x4c, 0x90, 0x15, 0x86, 0x4a, 0x77, 0xa0, 0x1c, 0xc6, 0xd7, 0x97, 0x75, 0xe9, 0xbf, 0x63, 0x54, 0x66, 0x82, 0xac, 0x30, 0x54, 0xba, 0x17,
0x88, 0x29, 0x81, 0xa1, 0x09, 0x84, 0x04, 0x63, 0x07, 0x2e, 0x26, 0x2e, 0x5a, 0x65, 0xbb, 0xe2, 0x0a, 0x4c, 0x09, 0x0c, 0x4d, 0x20, 0x24, 0x18, 0x7b, 0x01, 0x69, 0x20, 0xd1, 0x2a, 0xdd, 0x27,
0xa6, 0xf2, 0x12, 0x2f, 0x8b, 0x94, 0xda, 0x91, 0xed, 0x6e, 0xe4, 0x11, 0x78, 0x01, 0x5e, 0x6e, 0xbe, 0x54, 0x5e, 0xe2, 0x65, 0x91, 0x12,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54, 0x54, 0x34, 0xef, 0xff, 0x04, 0x00, 0x00, 0xff, 0xff, 0x05, 0x33, 0xc3, 0x7f, 0x57, 0x87, 0xf6, 0x06, 0xb2, 0xa0, 0xfe, 0xd7, 0x68, 0xf0, 0x4f, 0xbb, 0x72, 0x79, 0x00, 0x3b, 0x3e,
0x07, 0x00, 0x00, 0x4b, 0x66, 0x5c, 0x2f, 0x5b, 0x9a, 0x53, 0xea, 0x7f, 0xeb, 0xf9, 0xa7, 0xbb, 0x86, 0xaa, 0xf0,
0xc7, 0xb7, 0x01, 0x00, 0x00, 0xff, 0xff, 0xba, 0x3e, 0xa7, 0x09, 0x7f, 0x07, 0x00, 0x00,
} }

@ -15,6 +15,11 @@ import "v2ray.com/core/transport/config.proto";
import "google/protobuf/any.proto"; import "google/protobuf/any.proto";
enum ConfigFormat {
Protobuf = 0;
JSON = 1;
}
message AllocationStrategyConcurrency { message AllocationStrategyConcurrency {
uint32 value = 1; uint32 value = 1;
} }

@ -0,0 +1,36 @@
package core
import (
"io"
"io/ioutil"
"v2ray.com/core/common"
"github.com/golang/protobuf/proto"
)
type ConfigLoader func(input io.Reader) (*Config, error)
var configLoaderCache map[ConfigFormat]ConfigLoader
func RegisterConfigLoader(format ConfigFormat, loader ConfigLoader) error {
configLoaderCache[format] = loader
return nil
}
func LoadConfig(format ConfigFormat, input io.Reader) (*Config, error) {
loader, found := configLoaderCache[format]
if !found {
return nil, common.ErrBadConfiguration
}
return loader(input)
}
func LoadProtobufConfig(input io.Reader) (*Config, error) {
config := new(Config)
data, _ := ioutil.ReadAll(input)
if err := proto.Unmarshal(data, config); err != nil {
return nil, err
}
return config, nil
}
Loading…
Cancel
Save