1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-03 06:30:42 +00:00

protobuf for kcp config

This commit is contained in:
Darien Raymond 2016-09-21 14:39:07 +02:00
parent 8f6a972970
commit 1a3f51ade7
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
23 changed files with 463 additions and 82 deletions

View File

@ -21,9 +21,10 @@ func (this *Config) UnmarshalJSON(data []byte) error {
this.Response = new(NoneResponse)
if jsonConfig.Response != nil {
loader := loader.NewJSONConfigLoader(loader.ConfigCreatorCache{}, "type", "")
loader.RegisterCreator("none", func() interface{} { return new(NoneResponse) })
loader.RegisterCreator("http", func() interface{} { return new(HTTPResponse) })
cache := loader.ConfigCreatorCache{}
loader := loader.NewJSONConfigLoader(cache, "type", "")
cache.RegisterCreator("none", func() interface{} { return new(NoneResponse) })
cache.RegisterCreator("http", func() interface{} { return new(HTTPResponse) })
response, _, err := loader.Load(jsonConfig.Response)
if err != nil {
return errors.New("Blackhole: Failed to parse response config: " + err.Error())

View File

@ -3,16 +3,19 @@ package registry
import "v2ray.com/core/common/loader"
var (
inboundConfigCache loader.ConfigLoader
outboundConfigCache loader.ConfigLoader
inboundConfigCreatorCache = loader.ConfigCreatorCache{}
inboundConfigCache loader.ConfigLoader
outboundConfigCreatorCache = loader.ConfigCreatorCache{}
outboundConfigCache loader.ConfigLoader
)
func RegisterInboundConfig(protocol string, creator loader.ConfigCreator) error {
return inboundConfigCache.RegisterCreator(protocol, creator)
return inboundConfigCreatorCache.RegisterCreator(protocol, creator)
}
func RegisterOutboundConfig(protocol string, creator loader.ConfigCreator) error {
return outboundConfigCache.RegisterCreator(protocol, creator)
return outboundConfigCreatorCache.RegisterCreator(protocol, creator)
}
func CreateInboundConfig(protocol string, data []byte) (interface{}, error) {

View File

@ -7,6 +7,6 @@ import (
)
func init() {
inboundConfigCache = loader.NewJSONConfigLoader(loader.ConfigCreatorCache{}, "protocol", "settings")
outboundConfigCache = loader.NewJSONConfigLoader(loader.ConfigCreatorCache{}, "protocol", "settings")
inboundConfigCache = loader.NewJSONConfigLoader(inboundConfigCreatorCache, "protocol", "settings")
outboundConfigCache = loader.NewJSONConfigLoader(outboundConfigCreatorCache, "protocol", "settings")
}

View File

@ -1,8 +1,14 @@
package internet
import (
"errors"
"v2ray.com/core/common"
"v2ray.com/core/common/alloc"
"v2ray.com/core/common/loader"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
)
type Authenticator interface {
@ -12,14 +18,39 @@ type Authenticator interface {
}
type AuthenticatorFactory interface {
Create(AuthenticatorConfig) Authenticator
Create(interface{}) Authenticator
}
type AuthenticatorConfig interface {
func (this *AuthenticatorConfig) GetInternalConfig() (interface{}, error) {
return configCache.CreateConfig(this.Name)
}
func NewAuthenticatorConfig(name string, config interface{}) (*AuthenticatorConfig, error) {
pbMsg, ok := config.(proto.Message)
if !ok {
return nil, errors.New("Internet|Authenticator: Failed to convert config into proto message.")
}
anyConfig, err := ptypes.MarshalAny(pbMsg)
if err != nil {
return nil, err
}
return &AuthenticatorConfig{
Name: name,
Settings: anyConfig,
}, nil
}
func (this *AuthenticatorConfig) CreateAuthenticator() (Authenticator, error) {
config, err := this.GetInternalConfig()
if err != nil {
return nil, err
}
return CreateAuthenticator(this.Name, config)
}
var (
authenticatorCache = make(map[string]AuthenticatorFactory)
configCache = loader.ConfigCreatorCache{}
)
func RegisterAuthenticator(name string, factory AuthenticatorFactory) error {
@ -30,7 +61,11 @@ func RegisterAuthenticator(name string, factory AuthenticatorFactory) error {
return nil
}
func CreateAuthenticator(name string, config AuthenticatorConfig) (Authenticator, error) {
func RegisterAuthenticatorConfig(name string, configCreator loader.ConfigCreator) error {
return configCache.RegisterCreator(name, configCreator)
}
func CreateAuthenticator(name string, config interface{}) (Authenticator, error) {
factory, found := authenticatorCache[name]
if !found {
return nil, common.ErrObjectNotFound

View File

@ -0,0 +1,71 @@
// Code generated by protoc-gen-go.
// source: v2ray.com/core/transport/internet/authenticator.proto
// DO NOT EDIT!
/*
Package internet is a generated protocol buffer package.
It is generated from these files:
v2ray.com/core/transport/internet/authenticator.proto
It has these top-level messages:
AuthenticatorConfig
*/
package internet
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import google_protobuf "github.com/golang/protobuf/ptypes/any"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
type AuthenticatorConfig struct {
Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
Settings *google_protobuf.Any `protobuf:"bytes,2,opt,name=settings" json:"settings,omitempty"`
}
func (m *AuthenticatorConfig) Reset() { *m = AuthenticatorConfig{} }
func (m *AuthenticatorConfig) String() string { return proto.CompactTextString(m) }
func (*AuthenticatorConfig) ProtoMessage() {}
func (*AuthenticatorConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
func (m *AuthenticatorConfig) GetSettings() *google_protobuf.Any {
if m != nil {
return m.Settings
}
return nil
}
func init() {
proto.RegisterType((*AuthenticatorConfig)(nil), "com.v2ray.core.transport.internet.AuthenticatorConfig")
}
func init() {
proto.RegisterFile("v2ray.com/core/transport/internet/authenticator.proto", fileDescriptor0)
}
var fileDescriptor0 = []byte{
// 183 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x4c, 0xce, 0xc1, 0x4a, 0x87, 0x40,
0x10, 0xc7, 0x71, 0x8c, 0x08, 0xdb, 0x6e, 0x5b, 0x07, 0xeb, 0x64, 0x9d, 0x3c, 0xcd, 0x86, 0xd1,
0x03, 0x58, 0x6f, 0xe0, 0xb1, 0x4e, 0xeb, 0x32, 0x6e, 0x0b, 0x39, 0x23, 0xe3, 0x18, 0xf8, 0xf6,
0x81, 0xb2, 0xf2, 0xbf, 0xcd, 0xe1, 0xf7, 0xf9, 0x32, 0xe6, 0xfd, 0xaf, 0x15, 0xbf, 0x41, 0xe0,
0xc9, 0x05, 0x16, 0x74, 0x2a, 0x9e, 0x96, 0x99, 0x45, 0x5d, 0x22, 0x45, 0x21, 0x54, 0xe7, 0x57,
0xfd, 0x41, 0xd2, 0x14, 0xbc, 0xb2, 0xc0, 0x2c, 0xac, 0x6c, 0x9f, 0x03, 0x4f, 0x90, 0xa9, 0x20,
0x9c, 0x0c, 0x32, 0x7b, 0x7a, 0x8c, 0xcc, 0xf1, 0x17, 0xdd, 0x0e, 0x86, 0x75, 0x74, 0x9e, 0xb6,
0x43, 0xbf, 0x7c, 0x9b, 0xfb, 0xee, 0x32, 0xfa, 0xc9, 0x34, 0xa6, 0x68, 0xad, 0xb9, 0x26, 0x3f,
0x61, 0x55, 0xd4, 0x45, 0x73, 0xdb, 0xef, 0xb7, 0x7d, 0x35, 0xe5, 0x82, 0xaa, 0x89, 0xe2, 0x52,
0x5d, 0xd5, 0x45, 0x73, 0xd7, 0x3e, 0xc0, 0x11, 0x86, 0x1c, 0x86, 0x8e, 0xb6, 0xfe, 0x5c, 0x7d,
0x98, 0xaf, 0x32, 0xff, 0x30, 0xdc, 0xec, 0x9b, 0xb7, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0x2f,
0x12, 0x08, 0x8a, 0xe6, 0x00, 0x00, 0x00,
}

View File

@ -0,0 +1,11 @@
syntax = "proto3";
package com.v2ray.core.transport.internet;
option go_package = "internet";
import "google/protobuf/any.proto";
message AuthenticatorConfig {
string name = 1;
google.protobuf.Any settings = 2;
}

View File

@ -7,13 +7,13 @@ import (
)
func CreateAuthenticatorConfig(rawConfig []byte) (string, interface{}, error) {
config, name, err := configCache.Load(rawConfig)
config, name, err := configLoader.Load(rawConfig)
if err != nil {
return name, nil, err
}
return name, config, nil
}
func init() {
configCache = loader.NewJSONConfigLoader(loader.ConfigCreatorCache{}, "type", "")
}
var (
configLoader = loader.NewJSONConfigLoader(loader.ConfigCreatorCache{}, "type", "")
)

View File

@ -0,0 +1,57 @@
// Code generated by protoc-gen-go.
// source: v2ray.com/core/transport/internet/authenticators/noop/config.proto
// DO NOT EDIT!
/*
Package noop is a generated protocol buffer package.
It is generated from these files:
v2ray.com/core/transport/internet/authenticators/noop/config.proto
It has these top-level messages:
Config
*/
package noop
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
type Config struct {
}
func (m *Config) Reset() { *m = Config{} }
func (m *Config) String() string { return proto.CompactTextString(m) }
func (*Config) ProtoMessage() {}
func (*Config) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
func init() {
proto.RegisterType((*Config)(nil), "com.v2ray.core.transport.internet.authenticators.noop.Config")
}
func init() {
proto.RegisterFile("v2ray.com/core/transport/internet/authenticators/noop/config.proto", fileDescriptor0)
}
var fileDescriptor0 = []byte{
// 128 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x54, 0xcc, 0x41, 0x0a, 0xc2, 0x40,
0x0c, 0x05, 0xd0, 0x8d, 0x0c, 0xd2, 0xa5, 0x47, 0xf0, 0x00, 0x09, 0x28, 0x5e, 0xa0, 0xde, 0xc2,
0x5d, 0x0c, 0x51, 0x67, 0xd1, 0xfc, 0x21, 0x8d, 0x82, 0xb7, 0x97, 0x16, 0x46, 0xe8, 0xf6, 0x2d,
0xde, 0x30, 0x7e, 0x4e, 0x21, 0x5f, 0x52, 0x4c, 0xac, 0x08, 0xe3, 0x0c, 0xf1, 0xb9, 0x21, 0x92,
0xab, 0xa7, 0x85, 0x5b, 0xb2, 0xbc, 0xf3, 0x65, 0x9e, 0x55, 0x25, 0x11, 0x33, 0x3b, 0xd0, 0x58,
0xe1, 0x8f, 0xfa, 0xa4, 0x16, 0x48, 0x1c, 0x2e, 0x8a, 0x89, 0xfa, 0x13, 0x46, 0xff, 0x83, 0xfa,
0x41, 0xdb, 0x83, 0x96, 0xe3, 0xb8, 0x1f, 0xca, 0x75, 0x6d, 0xc6, 0x72, 0xdb, 0x2d, 0x72, 0x2f,
0xeb, 0x77, 0xfe, 0x05, 0x00, 0x00, 0xff, 0xff, 0x83, 0x2b, 0x5a, 0x85, 0x95, 0x00, 0x00, 0x00,
}

View File

@ -0,0 +1,6 @@
syntax = "proto3";
package com.v2ray.core.transport.internet.authenticators.noop;
option go_package = "noop";
message Config {}

View File

@ -17,12 +17,11 @@ func (this NoOpAuthenticator) Seal(payload *alloc.Buffer) {}
type NoOpAuthenticatorFactory struct{}
func (this NoOpAuthenticatorFactory) Create(config internet.AuthenticatorConfig) internet.Authenticator {
func (this NoOpAuthenticatorFactory) Create(config interface{}) internet.Authenticator {
return NoOpAuthenticator{}
}
type NoOpAuthenticatorConfig struct{}
func init() {
internet.RegisterAuthenticator("none", NoOpAuthenticatorFactory{})
internet.RegisterAuthenticatorConfig("none", func() interface{} { return &Config{} })
}

View File

@ -1,11 +0,0 @@
// +build json
package noop
import (
"v2ray.com/core/transport/internet"
)
func init() {
internet.RegisterAuthenticatorConfig("none", func() interface{} { return &NoOpAuthenticatorConfig{} })
}

View File

@ -0,0 +1,70 @@
// Code generated by protoc-gen-go.
// source: v2ray.com/core/transport/internet/authenticators/srtp/config.proto
// DO NOT EDIT!
/*
Package srtp is a generated protocol buffer package.
It is generated from these files:
v2ray.com/core/transport/internet/authenticators/srtp/config.proto
It has these top-level messages:
Config
*/
package srtp
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
type Config struct {
Version uint32 `protobuf:"varint,1,opt,name=version" json:"version,omitempty"`
Padding bool `protobuf:"varint,2,opt,name=padding" json:"padding,omitempty"`
Extension bool `protobuf:"varint,3,opt,name=extension" json:"extension,omitempty"`
CsrcCount uint32 `protobuf:"varint,4,opt,name=csrc_count,json=csrcCount" json:"csrc_count,omitempty"`
Marker bool `protobuf:"varint,5,opt,name=marker" json:"marker,omitempty"`
PayloadType uint32 `protobuf:"varint,6,opt,name=payload_type,json=payloadType" json:"payload_type,omitempty"`
}
func (m *Config) Reset() { *m = Config{} }
func (m *Config) String() string { return proto.CompactTextString(m) }
func (*Config) ProtoMessage() {}
func (*Config) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
func init() {
proto.RegisterType((*Config)(nil), "com.v2ray.core.transport.internet.authenticators.srtp.Config")
}
func init() {
proto.RegisterFile("v2ray.com/core/transport/internet/authenticators/srtp/config.proto", fileDescriptor0)
}
var fileDescriptor0 = []byte{
// 237 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x54, 0x8f, 0xc1, 0x4a, 0x73, 0x31,
0x10, 0x85, 0xb9, 0xff, 0x5f, 0xa3, 0x8d, 0xba, 0xc9, 0x42, 0xb2, 0x50, 0xa8, 0xae, 0xba, 0x4a,
0x40, 0xf1, 0x05, 0xda, 0x37, 0x28, 0xae, 0xdc, 0x94, 0x98, 0x3b, 0xd6, 0xa0, 0x77, 0x26, 0x4c,
0xa6, 0xc5, 0xfb, 0x5e, 0x3e, 0xa0, 0x24, 0xf4, 0x2a, 0x2e, 0xcf, 0x77, 0x38, 0x1f, 0x33, 0x7a,
0x75, 0xb8, 0xe7, 0x30, 0xba, 0x48, 0x83, 0x8f, 0xc4, 0xe0, 0x85, 0x03, 0x96, 0x4c, 0x2c, 0x3e,
0xa1, 0x00, 0x23, 0x88, 0x0f, 0x7b, 0x79, 0x03, 0x94, 0x14, 0x83, 0x10, 0x17, 0x5f, 0x58, 0xb2,
0x8f, 0x84, 0xaf, 0x69, 0xe7, 0x32, 0x93, 0x90, 0x79, 0x8c, 0x34, 0xb8, 0xc9, 0xc3, 0xe0, 0x7e,
0x1c, 0x6e, 0x72, 0xb8, 0xbf, 0x0e, 0x57, 0x1d, 0x77, 0x5f, 0x9d, 0x56, 0xeb, 0xe6, 0x31, 0x56,
0x9f, 0x1e, 0x80, 0x4b, 0x22, 0xb4, 0xdd, 0xa2, 0x5b, 0x5e, 0x6e, 0xa6, 0x58, 0x9b, 0x1c, 0xfa,
0x3e, 0xe1, 0xce, 0xfe, 0x5b, 0x74, 0xcb, 0xb3, 0xcd, 0x14, 0xcd, 0xb5, 0x9e, 0xc3, 0xa7, 0x00,
0xb6, 0xd5, 0xff, 0xd6, 0xfd, 0x02, 0x73, 0xa3, 0x75, 0x2c, 0x1c, 0xb7, 0x91, 0xf6, 0x28, 0x76,
0xd6, 0xa4, 0xf3, 0x4a, 0xd6, 0x15, 0x98, 0x2b, 0xad, 0x86, 0xc0, 0xef, 0xc0, 0xf6, 0xa4, 0x2d,
0x8f, 0xc9, 0xdc, 0xea, 0x8b, 0x1c, 0xc6, 0x0f, 0x0a, 0xfd, 0x56, 0xc6, 0x0c, 0x56, 0xb5, 0xe1,
0xf9, 0x91, 0x3d, 0x8d, 0x19, 0x56, 0xea, 0x79, 0x56, 0xcf, 0x7f, 0x51, 0xed, 0xf9, 0x87, 0xef,
0x00, 0x00, 0x00, 0xff, 0xff, 0x4a, 0xdc, 0x7b, 0x73, 0x42, 0x01, 0x00, 0x00,
}

View File

@ -0,0 +1,13 @@
syntax = "proto3";
package com.v2ray.core.transport.internet.authenticators.srtp;
option go_package = "srtp";
message Config {
uint32 version = 1;
bool padding = 2;
bool extension = 3;
uint32 csrc_count = 4;
bool marker = 5;
uint32 payload_type = 6;
}

View File

@ -7,15 +7,6 @@ import (
"v2ray.com/core/transport/internet"
)
type Config struct {
Version byte
Padding bool
Extension bool
CSRCCount byte
Marker bool
PayloadType byte
}
type SRTP struct {
header uint16
number uint16
@ -39,7 +30,7 @@ func (this *SRTP) Seal(payload *alloc.Buffer) {
type SRTPFactory struct {
}
func (this SRTPFactory) Create(rawSettings internet.AuthenticatorConfig) internet.Authenticator {
func (this SRTPFactory) Create(rawSettings interface{}) internet.Authenticator {
return &SRTP{
header: 0xB5E8,
number: uint16(rand.Intn(65536)),
@ -48,4 +39,5 @@ func (this SRTPFactory) Create(rawSettings internet.AuthenticatorConfig) interne
func init() {
internet.RegisterAuthenticator("srtp", SRTPFactory{})
internet.RegisterAuthenticatorConfig("srtp", func() interface{} { return &Config{} })
}

View File

@ -1,11 +0,0 @@
// +build json
package srtp
import (
"v2ray.com/core/transport/internet"
)
func init() {
internet.RegisterAuthenticatorConfig("srtp", func() interface{} { return &Config{} })
}

View File

@ -0,0 +1,60 @@
// Code generated by protoc-gen-go.
// source: v2ray.com/core/transport/internet/authenticators/utp/config.proto
// DO NOT EDIT!
/*
Package utp is a generated protocol buffer package.
It is generated from these files:
v2ray.com/core/transport/internet/authenticators/utp/config.proto
It has these top-level messages:
Config
*/
package utp
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
type Config struct {
Version uint32 `protobuf:"varint,1,opt,name=version" json:"version,omitempty"`
}
func (m *Config) Reset() { *m = Config{} }
func (m *Config) String() string { return proto.CompactTextString(m) }
func (*Config) ProtoMessage() {}
func (*Config) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
func init() {
proto.RegisterType((*Config)(nil), "com.v2ray.core.transport.internet.authenticators.utp.Config")
}
func init() {
proto.RegisterFile("v2ray.com/core/transport/internet/authenticators/utp/config.proto", fileDescriptor0)
}
var fileDescriptor0 = []byte{
// 149 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x54, 0xcd, 0x31, 0x0a, 0xc2, 0x40,
0x10, 0x46, 0x61, 0x82, 0x18, 0x21, 0x60, 0x93, 0x2a, 0xa5, 0xa4, 0xb2, 0x9a, 0x01, 0xf5, 0x02,
0xea, 0x0d, 0x2c, 0xed, 0xd6, 0x65, 0xd4, 0x2d, 0x32, 0xb3, 0x4c, 0xfe, 0x0d, 0x78, 0x7b, 0x21,
0x10, 0xc1, 0xf2, 0x35, 0xdf, 0x6b, 0xce, 0xd3, 0xc1, 0xc3, 0x87, 0xa2, 0x0d, 0x1c, 0xcd, 0x85,
0xe1, 0x41, 0xc7, 0x6c, 0x0e, 0x4e, 0x0a, 0x71, 0x15, 0x70, 0x28, 0x78, 0x8b, 0x22, 0xc5, 0x00,
0xf3, 0x91, 0x0b, 0x32, 0x47, 0xd3, 0x67, 0x7a, 0x51, 0x76, 0x83, 0xb5, 0xa7, 0x68, 0x03, 0x2d,
0x8c, 0x0b, 0xfd, 0x08, 0x5a, 0x08, 0xfa, 0x27, 0xa8, 0x20, 0xf7, 0x7d, 0x53, 0x5f, 0x67, 0xa5,
0xed, 0x9a, 0xcd, 0x24, 0x3e, 0x26, 0xd3, 0xae, 0xda, 0x55, 0xfb, 0xed, 0x6d, 0xc9, 0xcb, 0xfa,
0xbe, 0x2a, 0xc8, 0x8f, 0x7a, 0xfe, 0x1c, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xba, 0xf9, 0x6d,
0x52, 0xac, 0x00, 0x00, 0x00,
}

View File

@ -0,0 +1,8 @@
syntax = "proto3";
package com.v2ray.core.transport.internet.authenticators.utp;
option go_package = "utp";
message Config {
uint32 version = 1;
}

View File

@ -7,10 +7,6 @@ import (
"v2ray.com/core/transport/internet"
)
type Config struct {
Version byte
}
type UTP struct {
header byte
extension byte
@ -33,7 +29,7 @@ func (this *UTP) Seal(payload *alloc.Buffer) {
type UTPFactory struct{}
func (this UTPFactory) Create(rawSettings internet.AuthenticatorConfig) internet.Authenticator {
func (this UTPFactory) Create(rawSettings interface{}) internet.Authenticator {
return &UTP{
header: 1,
extension: 0,
@ -43,4 +39,5 @@ func (this UTPFactory) Create(rawSettings internet.AuthenticatorConfig) internet
func init() {
internet.RegisterAuthenticator("utp", UTPFactory{})
internet.RegisterAuthenticatorConfig("utp", func() interface{} { return &Config{} })
}

View File

@ -1,11 +0,0 @@
// +build json
package utp
import (
"v2ray.com/core/transport/internet"
)
func init() {
internet.RegisterAuthenticatorConfig("utp", func() interface{} { return &Config{} })
}

View File

@ -4,18 +4,6 @@ import (
"v2ray.com/core/transport/internet"
)
type Config struct {
Mtu uint32 // Maximum transmission unit
Tti uint32
UplinkCapacity uint32
DownlinkCapacity uint32
Congestion bool
WriteBuffer uint32
ReadBuffer uint32
HeaderType string
HeaderConfig internet.AuthenticatorConfig
}
func (this *Config) Apply() {
effectiveConfig = *this
}
@ -23,7 +11,7 @@ func (this *Config) Apply() {
func (this *Config) GetAuthenticator() (internet.Authenticator, error) {
auth := NewSimpleAuthenticator()
if this.HeaderConfig != nil {
header, err := internet.CreateAuthenticator(this.HeaderType, this.HeaderConfig)
header, err := this.HeaderConfig.CreateAuthenticator()
if err != nil {
return nil, err
}

View File

@ -0,0 +1,82 @@
// Code generated by protoc-gen-go.
// source: v2ray.com/core/transport/internet/kcp/config.proto
// DO NOT EDIT!
/*
Package kcp is a generated protocol buffer package.
It is generated from these files:
v2ray.com/core/transport/internet/kcp/config.proto
It has these top-level messages:
Config
*/
package kcp
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import com_v2ray_core_transport_internet "v2ray.com/core/transport/internet"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
type Config struct {
Mtu uint32 `protobuf:"varint,1,opt,name=mtu" json:"mtu,omitempty"`
Tti uint32 `protobuf:"varint,2,opt,name=tti" json:"tti,omitempty"`
UplinkCapacity uint32 `protobuf:"varint,3,opt,name=uplink_capacity,json=uplinkCapacity" json:"uplink_capacity,omitempty"`
DownlinkCapacity uint32 `protobuf:"varint,4,opt,name=downlink_capacity,json=downlinkCapacity" json:"downlink_capacity,omitempty"`
Congestion bool `protobuf:"varint,5,opt,name=congestion" json:"congestion,omitempty"`
WriteBuffer uint32 `protobuf:"varint,6,opt,name=write_buffer,json=writeBuffer" json:"write_buffer,omitempty"`
ReadBuffer uint32 `protobuf:"varint,7,opt,name=read_buffer,json=readBuffer" json:"read_buffer,omitempty"`
HeaderConfig *com_v2ray_core_transport_internet.AuthenticatorConfig `protobuf:"bytes,8,opt,name=header_config,json=headerConfig" json:"header_config,omitempty"`
}
func (m *Config) Reset() { *m = Config{} }
func (m *Config) String() string { return proto.CompactTextString(m) }
func (*Config) ProtoMessage() {}
func (*Config) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
func (m *Config) GetHeaderConfig() *com_v2ray_core_transport_internet.AuthenticatorConfig {
if m != nil {
return m.HeaderConfig
}
return nil
}
func init() {
proto.RegisterType((*Config)(nil), "com.v2ray.core.transport.internet.kcp.Config")
}
func init() { proto.RegisterFile("v2ray.com/core/transport/internet/kcp/config.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 290 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x84, 0x90, 0x41, 0x4f, 0xc2, 0x30,
0x18, 0x86, 0x33, 0x10, 0x24, 0x05, 0x14, 0x7b, 0x6a, 0x3c, 0x28, 0x9a, 0x18, 0x97, 0x98, 0x74,
0xc9, 0x8c, 0xde, 0x85, 0x7f, 0xb0, 0xa3, 0x1e, 0x96, 0xd2, 0x75, 0xd0, 0xcc, 0xb5, 0xcd, 0xc7,
0x37, 0x09, 0xbf, 0xcf, 0x3f, 0x66, 0xd6, 0x32, 0x82, 0x27, 0x6e, 0xdb, 0xf3, 0x3d, 0xef, 0xdb,
0xe4, 0x25, 0xe9, 0x4f, 0x0a, 0x62, 0xcf, 0xa5, 0xad, 0x13, 0x69, 0x41, 0x25, 0x08, 0xc2, 0x6c,
0x9d, 0x05, 0x4c, 0xb4, 0x41, 0x05, 0x46, 0x61, 0x52, 0x49, 0x97, 0x48, 0x6b, 0x4a, 0xbd, 0xe6,
0x0e, 0x2c, 0x5a, 0xfa, 0x24, 0x6d, 0xcd, 0xbb, 0x1c, 0x28, 0x7e, 0xcc, 0xf0, 0x2e, 0xc3, 0x2b,
0xe9, 0x6e, 0xdf, 0xce, 0x57, 0x8b, 0x06, 0x37, 0xca, 0xa0, 0x96, 0x02, 0x2d, 0x84, 0xf6, 0xc7,
0xdf, 0x1e, 0x19, 0x2e, 0xfd, 0x73, 0x74, 0x46, 0xfa, 0x35, 0x36, 0x2c, 0x9a, 0x47, 0xf1, 0x34,
0x6b, 0x3f, 0x5b, 0x82, 0xa8, 0x59, 0x2f, 0x10, 0x44, 0x4d, 0x9f, 0xc9, 0x75, 0xe3, 0xbe, 0xb5,
0xa9, 0x72, 0x29, 0x9c, 0x90, 0x1a, 0xf7, 0xac, 0xef, 0xaf, 0x57, 0x01, 0x2f, 0x0f, 0x94, 0xbe,
0x90, 0x9b, 0xc2, 0xee, 0xcc, 0x7f, 0xf5, 0xc2, 0xab, 0xb3, 0xee, 0x70, 0x94, 0xef, 0x08, 0x91,
0xd6, 0xac, 0xd5, 0x16, 0xb5, 0x35, 0x6c, 0x30, 0x8f, 0xe2, 0x51, 0x76, 0x42, 0xe8, 0x03, 0x99,
0xec, 0x40, 0xa3, 0xca, 0x57, 0x4d, 0x59, 0x2a, 0x60, 0x43, 0xdf, 0x33, 0xf6, 0x6c, 0xe1, 0x11,
0xbd, 0x27, 0x63, 0x50, 0xa2, 0xe8, 0x8c, 0x4b, 0x6f, 0x90, 0x16, 0x1d, 0x84, 0x2f, 0x32, 0xdd,
0x28, 0x51, 0x28, 0xc8, 0xc3, 0xba, 0x6c, 0x34, 0x8f, 0xe2, 0x71, 0xfa, 0xce, 0xcf, 0xcf, 0xfb,
0x71, 0xba, 0x5b, 0x18, 0x2b, 0x9b, 0x84, 0xb2, 0xf0, 0xb7, 0x18, 0x7c, 0xf6, 0x2b, 0xe9, 0x56,
0x43, 0xbf, 0xe9, 0xeb, 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x04, 0xdb, 0x8e, 0xc7, 0xe7, 0x01,
0x00, 0x00,
}

View File

@ -0,0 +1,17 @@
syntax = "proto3";
package com.v2ray.core.transport.internet.kcp;
option go_package = "kcp";
import "v2ray.com/core/transport/internet/authenticator.proto";
message Config {
uint32 mtu = 1;
uint32 tti = 2;
uint32 uplink_capacity = 3;
uint32 downlink_capacity = 4;
bool congestion = 5;
uint32 write_buffer = 6;
uint32 read_buffer = 7;
com.v2ray.core.transport.internet.AuthenticatorConfig header_config = 8;
}

View File

@ -72,8 +72,12 @@ func (this *Config) UnmarshalJSON(data []byte) error {
log.Error("KCP|Config: Failed to parse header config: ", err)
return err
}
this.HeaderType = name
this.HeaderConfig = config
authConfig, err := internet.NewAuthenticatorConfig(name, config)
if err != nil {
log.Error("KCP:Config: Failed to create header config: ", err)
return err
}
this.HeaderConfig = authConfig
}
return nil