Browse Source

use protocol in string form

pull/1524/head^2 v3.34
Darien Raymond 6 years ago
parent
commit
b79ec5f1ed
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
  1. 92
      transport/internet/config.go
  2. 92
      transport/internet/config.pb.go
  3. 9
      transport/internet/config.proto
  4. 6
      transport/internet/dialer.go
  5. 4
      transport/internet/domainsocket/config.go
  6. 2
      transport/internet/domainsocket/dial.go
  7. 2
      transport/internet/domainsocket/listener.go
  8. 4
      transport/internet/http/config.go
  9. 2
      transport/internet/http/dialer.go
  10. 2
      transport/internet/http/hub.go
  11. 4
      transport/internet/kcp/config.go
  12. 2
      transport/internet/kcp/dialer.go
  13. 2
      transport/internet/kcp/listener.go
  14. 4
      transport/internet/tcp/config.go
  15. 2
      transport/internet/tcp/dialer.go
  16. 2
      transport/internet/tcp/hub.go
  17. 4
      transport/internet/tcp_hub.go
  18. 2
      transport/internet/udp/dialer.go
  19. 2
      transport/internet/udp/udp.go
  20. 4
      transport/internet/websocket/config.go
  21. 2
      transport/internet/websocket/dialer.go
  22. 2
      transport/internet/websocket/hub.go

92
transport/internet/config.go

@ -5,22 +5,59 @@ import "v2ray.com/core/common/serial"
type ConfigCreator func() interface{}
var (
globalTransportConfigCreatorCache = make(map[TransportProtocol]ConfigCreator)
globalTransportConfigCreatorCache = make(map[string]ConfigCreator)
globalTransportSettings []*TransportConfig
)
const unknownProtocol = "unknown"
func transportProtocolToString(protocol TransportProtocol) string {
switch protocol {
case TransportProtocol_TCP:
return "tcp"
case TransportProtocol_UDP:
return "udp"
case TransportProtocol_HTTP:
return "http"
case TransportProtocol_MKCP:
return "mkcp"
case TransportProtocol_WebSocket:
return "websocket"
case TransportProtocol_DomainSocket:
return "domainsocket"
default:
return unknownProtocol
}
}
func RegisterProtocolConfigCreator(protocol TransportProtocol, creator ConfigCreator) error {
if _, found := globalTransportConfigCreatorCache[protocol]; found {
return newError("protocol ", TransportProtocol_name[int32(protocol)], " is already registered").AtError()
name := transportProtocolToString(protocol)
if name == unknownProtocol {
return newError("protocol ", TransportProtocol_name[int32(protocol)], " is not supported").AtError()
}
globalTransportConfigCreatorCache[protocol] = creator
return RegisterProtocolConfigCreatorByName(name, creator)
}
func RegisterProtocolConfigCreatorByName(name string, creator ConfigCreator) error {
if _, found := globalTransportConfigCreatorCache[name]; found {
return newError("protocol ", name, " is already registered").AtError()
}
globalTransportConfigCreatorCache[name] = creator
return nil
}
func CreateTransportConfig(protocol TransportProtocol) (interface{}, error) {
creator, ok := globalTransportConfigCreatorCache[protocol]
name := transportProtocolToString(protocol)
if name == unknownProtocol {
return nil, newError("protocol ", TransportProtocol_name[int32(protocol)], " is not supported").AtError()
}
return CreateTransportConfigByName(name)
}
func CreateTransportConfigByName(name string) (interface{}, error) {
creator, ok := globalTransportConfigCreatorCache[name]
if !ok {
return nil, newError("unknown transport protocol: ", protocol)
return nil, newError("unknown transport protocol: ", name)
}
return creator(), nil
}
@ -29,48 +66,47 @@ func (c *TransportConfig) GetTypedSettings() (interface{}, error) {
return c.Settings.GetInstance()
}
func (c *StreamConfig) GetEffectiveProtocol() TransportProtocol {
if c == nil {
return TransportProtocol_TCP
func (c *TransportConfig) GetUnifiedProtocolName() string {
if len(c.ProtocolName) > 0 {
return c.ProtocolName
}
return c.Protocol
}
func (c *StreamConfig) GetEffectiveTransportSettings() (interface{}, error) {
protocol := c.GetEffectiveProtocol()
return transportProtocolToString(c.Protocol)
}
if c != nil {
for _, settings := range c.TransportSettings {
if settings.Protocol == protocol {
return settings.GetTypedSettings()
}
}
func (c *StreamConfig) GetEffectiveProtocol() string {
if c == nil {
return "tcp"
}
for _, settings := range globalTransportSettings {
if settings.Protocol == protocol {
return settings.GetTypedSettings()
}
if len(c.ProtocolName) > 0 {
return c.ProtocolName
}
return CreateTransportConfig(protocol)
return transportProtocolToString(c.Protocol)
}
func (c *StreamConfig) GetEffectiveTransportSettings() (interface{}, error) {
protocol := c.GetEffectiveProtocol()
return c.GetTransportSettingsFor(protocol)
}
func (c *StreamConfig) GetTransportSettingsFor(protocol TransportProtocol) (interface{}, error) {
func (c *StreamConfig) GetTransportSettingsFor(protocol string) (interface{}, error) {
if c != nil {
for _, settings := range c.TransportSettings {
if settings.Protocol == protocol {
if settings.GetUnifiedProtocolName() == protocol {
return settings.GetTypedSettings()
}
}
}
for _, settings := range globalTransportSettings {
if settings.Protocol == protocol {
if settings.GetUnifiedProtocolName() == protocol {
return settings.GetTypedSettings()
}
}
return CreateTransportConfig(protocol)
return CreateTransportConfigByName(protocol)
}
func (c *StreamConfig) GetEffectiveSecuritySettings() (interface{}, error) {

92
transport/internet/config.pb.go

@ -48,12 +48,15 @@ func (x TransportProtocol) String() string {
return proto.EnumName(TransportProtocol_name, int32(x))
}
func (TransportProtocol) EnumDescriptor() ([]byte, []int) {
return fileDescriptor_config_027b4c7f353c31be, []int{0}
return fileDescriptor_config_59931ebeb80dc13e, []int{0}
}
type TransportConfig struct {
// Type of network that this settings supports.
// Deprecated. Use the string form below.
Protocol TransportProtocol `protobuf:"varint,1,opt,name=protocol,proto3,enum=v2ray.core.transport.internet.TransportProtocol" json:"protocol,omitempty"`
// Type of network that this settings supports.
ProtocolName string `protobuf:"bytes,3,opt,name=protocol_name,json=protocolName,proto3" json:"protocol_name,omitempty"`
// Specific settings. Must be of the transports.
Settings *serial.TypedMessage `protobuf:"bytes,2,opt,name=settings,proto3" json:"settings,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
@ -65,7 +68,7 @@ func (m *TransportConfig) Reset() { *m = TransportConfig{} }
func (m *TransportConfig) String() string { return proto.CompactTextString(m) }
func (*TransportConfig) ProtoMessage() {}
func (*TransportConfig) Descriptor() ([]byte, []int) {
return fileDescriptor_config_027b4c7f353c31be, []int{0}
return fileDescriptor_config_59931ebeb80dc13e, []int{0}
}
func (m *TransportConfig) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_TransportConfig.Unmarshal(m, b)
@ -92,6 +95,13 @@ func (m *TransportConfig) GetProtocol() TransportProtocol {
return TransportProtocol_TCP
}
func (m *TransportConfig) GetProtocolName() string {
if m != nil {
return m.ProtocolName
}
return ""
}
func (m *TransportConfig) GetSettings() *serial.TypedMessage {
if m != nil {
return m.Settings
@ -100,8 +110,10 @@ func (m *TransportConfig) GetSettings() *serial.TypedMessage {
}
type StreamConfig struct {
// Effective network. Deprecated. Use the string form below.
Protocol TransportProtocol `protobuf:"varint,1,opt,name=protocol,proto3,enum=v2ray.core.transport.internet.TransportProtocol" json:"protocol,omitempty"` // Deprecated: Do not use.
// Effective network.
Protocol TransportProtocol `protobuf:"varint,1,opt,name=protocol,proto3,enum=v2ray.core.transport.internet.TransportProtocol" json:"protocol,omitempty"`
ProtocolName string `protobuf:"bytes,5,opt,name=protocol_name,json=protocolName,proto3" json:"protocol_name,omitempty"`
TransportSettings []*TransportConfig `protobuf:"bytes,2,rep,name=transport_settings,json=transportSettings,proto3" json:"transport_settings,omitempty"`
// Type of security. Must be a message name of the settings proto.
SecurityType string `protobuf:"bytes,3,opt,name=security_type,json=securityType,proto3" json:"security_type,omitempty"`
@ -116,7 +128,7 @@ func (m *StreamConfig) Reset() { *m = StreamConfig{} }
func (m *StreamConfig) String() string { return proto.CompactTextString(m) }
func (*StreamConfig) ProtoMessage() {}
func (*StreamConfig) Descriptor() ([]byte, []int) {
return fileDescriptor_config_027b4c7f353c31be, []int{1}
return fileDescriptor_config_59931ebeb80dc13e, []int{1}
}
func (m *StreamConfig) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_StreamConfig.Unmarshal(m, b)
@ -136,6 +148,7 @@ func (m *StreamConfig) XXX_DiscardUnknown() {
var xxx_messageInfo_StreamConfig proto.InternalMessageInfo
// Deprecated: Do not use.
func (m *StreamConfig) GetProtocol() TransportProtocol {
if m != nil {
return m.Protocol
@ -143,6 +156,13 @@ func (m *StreamConfig) GetProtocol() TransportProtocol {
return TransportProtocol_TCP
}
func (m *StreamConfig) GetProtocolName() string {
if m != nil {
return m.ProtocolName
}
return ""
}
func (m *StreamConfig) GetTransportSettings() []*TransportConfig {
if m != nil {
return m.TransportSettings
@ -175,7 +195,7 @@ func (m *ProxyConfig) Reset() { *m = ProxyConfig{} }
func (m *ProxyConfig) String() string { return proto.CompactTextString(m) }
func (*ProxyConfig) ProtoMessage() {}
func (*ProxyConfig) Descriptor() ([]byte, []int) {
return fileDescriptor_config_027b4c7f353c31be, []int{2}
return fileDescriptor_config_59931ebeb80dc13e, []int{2}
}
func (m *ProxyConfig) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_ProxyConfig.Unmarshal(m, b)
@ -210,34 +230,36 @@ func init() {
}
func init() {
proto.RegisterFile("v2ray.com/core/transport/internet/config.proto", fileDescriptor_config_027b4c7f353c31be)
}
var fileDescriptor_config_027b4c7f353c31be = []byte{
// 393 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x91, 0xcf, 0x6a, 0xdb, 0x40,
0x10, 0x87, 0x2b, 0xc9, 0x6d, 0xe5, 0xb1, 0xdd, 0xae, 0xf7, 0x64, 0x0a, 0xa6, 0xae, 0x0b, 0x45,
0xf4, 0xb0, 0x32, 0xea, 0x1b, 0x58, 0x3e, 0xb4, 0xb4, 0xa6, 0x42, 0x52, 0x5b, 0x30, 0x14, 0xb3,
0xde, 0x6c, 0x84, 0x88, 0xa5, 0x35, 0xab, 0x4d, 0x88, 0x9e, 0x27, 0xb7, 0xdc, 0xf3, 0x7e, 0x41,
0xff, 0x16, 0x93, 0x80, 0xf1, 0x25, 0xb7, 0x41, 0xf3, 0x9b, 0x6f, 0x3e, 0xcd, 0x02, 0xb9, 0xf1,
0x24, 0x2d, 0x09, 0x13, 0x99, 0xcb, 0x84, 0xe4, 0xae, 0x92, 0x34, 0x2f, 0x0e, 0x42, 0x2a, 0x37,
0xcd, 0x15, 0x97, 0x39, 0x57, 0x2e, 0x13, 0xf9, 0x65, 0x9a, 0x90, 0x83, 0x14, 0x4a, 0xe0, 0x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, 0xc1, 0x6f, 0xc1, 0x8a, 0xfd, 0x00,
0xbd, 0xaa, 0x8a, 0x3f, 0xab, 0x00, 0x19, 0xd8, 0x86, 0xde, 0xfa, 0xa7, 0x1f, 0x20, 0x13, 0x8f,
0xa0, 0xff, 0x8f, 0xef, 0x22, 0xc1, 0xae, 0xb8, 0x42, 0x56, 0xd5, 0xf8, 0x1e, 0xc7, 0x01, 0xea,
0x61, 0x04, 0xc3, 0x95, 0xc8, 0x68, 0x9a, 0xb7, 0xbd, 0xd7, 0xcb, 0xdf, 0xf0, 0x89, 0x89, 0xec,
0xf4, 0xf9, 0x02, 0x63, 0x63, 0x77, 0xf5, 0xbd, 0x39, 0xfd, 0xeb, 0x85, 0xb4, 0x24, 0x7e, 0x95,
0xd5, 0x5a, 0xe4, 0x47, 0xdb, 0xdf, 0xbd, 0xa9, 0x1f, 0xec, 0xdb, 0x63, 0x00, 0x00, 0x00, 0xff,
0xff, 0xa2, 0xdf, 0xde, 0xa4, 0x35, 0x03, 0x00, 0x00,
proto.RegisterFile("v2ray.com/core/transport/internet/config.proto", fileDescriptor_config_59931ebeb80dc13e)
}
var fileDescriptor_config_59931ebeb80dc13e = []byte{
// 419 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x91, 0xd1, 0x8a, 0x13, 0x31,
0x14, 0x86, 0xcd, 0x4c, 0x57, 0xdb, 0xd3, 0xae, 0xa6, 0xb9, 0x2a, 0xc2, 0x62, 0xad, 0x20, 0xc5,
0x8b, 0xcc, 0x32, 0xbe, 0x41, 0xbb, 0x17, 0x8a, 0xae, 0x86, 0xe9, 0xa8, 0xb0, 0x20, 0x25, 0x1b,
0x63, 0x19, 0xdc, 0x24, 0x25, 0x13, 0xc5, 0x79, 0x25, 0x9f, 0xc4, 0xa7, 0xf0, 0x59, 0x24, 0x33,
0x93, 0xb0, 0xa8, 0x94, 0x82, 0x77, 0x87, 0x9c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x2a, 0x5d,
0x8e, 0x73, 0x7a, 0xec, 0x02, 0x1d, 0x42, 0x31, 0x8d, 0x9a, 0x4d, 0x6f, 0xe4, 0x77, 0xa8, 0xa5,
0xf8, 0x6a, 0x2b, 0xd7, 0x6c, 0xfd, 0x45, 0x43, 0x9e, 0xe1, 0xd1, 0xa7, 0x43, 0x36, 0x30, 0x8d,
0xa2, 0xb8, 0xc2, 0xa0, 0x5d, 0xe1, 0xd8, 0x60, 0x71, 0x30, 0x08, 0x93, 0x17, 0x8f, 0x60, 0xcc,
0xac, 0xf9, 0xde, 0xf4, 0xf1, 0x62, 0x48, 0x1d, 0xdf, 0xb5, 0xc9, 0x8e, 0x0a, 0x5f, 0x3e, 0xbb,
0x82, 0xe9, 0x5f, 0x09, 0x92, 0x7b, 0x90, 0x96, 0x6b, 0x86, 0xef, 0xf8, 0xe2, 0xdd, 0x05, 0xc3,
0x88, 0x0c, 0x61, 0x70, 0xf9, 0x6a, 0xcd, 0x70, 0x42, 0x4e, 0x61, 0xf4, 0x41, 0x5e, 0x6f, 0x8c,
0xf8, 0x22, 0x1d, 0x4e, 0x7d, 0xe3, 0x45, 0x59, 0x32, 0x3c, 0x20, 0x18, 0x26, 0x17, 0x46, 0xf1,
0x4a, 0xf7, 0xbd, 0x93, 0xd5, 0x5b, 0x78, 0x2c, 0x8c, 0x3a, 0x1c, 0x1f, 0x43, 0x57, 0xc3, 0x50,
0xff, 0x48, 0xce, 0xde, 0xe7, 0x05, 0x6f, 0xe8, 0xda, 0x6b, 0xe3, 0x5a, 0xf4, 0x65, 0xdf, 0xbf,
0xbe, 0xdb, 0x1e, 0xed, 0xf9, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0x1c, 0x47, 0x39, 0x56, 0x83,
0x03, 0x00, 0x00,
}

9
transport/internet/config.proto

@ -19,15 +19,22 @@ enum TransportProtocol {
message TransportConfig {
// Type of network that this settings supports.
// Deprecated. Use the string form below.
TransportProtocol protocol = 1;
// Type of network that this settings supports.
string protocol_name = 3;
// Specific settings. Must be of the transports.
v2ray.core.common.serial.TypedMessage settings = 2;
}
message StreamConfig {
// Effective network. Deprecated. Use the string form below.
TransportProtocol protocol = 1 [deprecated = true];
// Effective network.
TransportProtocol protocol = 1;
string protocol_name = 5;
repeated TransportConfig transport_settings = 2;

6
transport/internet/dialer.go

@ -9,10 +9,10 @@ import (
type Dialer func(ctx context.Context, dest net.Destination) (Connection, error)
var (
transportDialerCache = make(map[TransportProtocol]Dialer)
transportDialerCache = make(map[string]Dialer)
)
func RegisterTransportDialer(protocol TransportProtocol, dialer Dialer) error {
func RegisterTransportDialer(protocol string, dialer Dialer) error {
if _, found := transportDialerCache[protocol]; found {
return newError(protocol, " dialer already registered").AtError()
}
@ -44,7 +44,7 @@ func Dial(ctx context.Context, dest net.Destination) (Connection, error) {
return dialer(ctx, dest)
}
udpDialer := transportDialerCache[TransportProtocol_UDP]
udpDialer := transportDialerCache["udp"]
if udpDialer == nil {
return nil, newError("UDP dialer not registered").AtError()
}

4
transport/internet/domainsocket/config.go

@ -6,6 +6,8 @@ import (
"v2ray.com/core/transport/internet"
)
const protocolName = "domainsocket"
func (c *Config) GetUnixAddr() (*net.UnixAddr, error) {
path := c.Path
if len(path) == 0 {
@ -21,7 +23,7 @@ func (c *Config) GetUnixAddr() (*net.UnixAddr, error) {
}
func init() {
common.Must(internet.RegisterProtocolConfigCreator(internet.TransportProtocol_DomainSocket, func() interface{} {
common.Must(internet.RegisterProtocolConfigCreatorByName(protocolName, func() interface{} {
return new(Config)
}))
}

2
transport/internet/domainsocket/dial.go

@ -43,5 +43,5 @@ func Dial(ctx context.Context, dest net.Destination) (internet.Connection, error
}
func init() {
common.Must(internet.RegisterTransportDialer(internet.TransportProtocol_DomainSocket, Dial))
common.Must(internet.RegisterTransportDialer(protocolName, Dial))
}

2
transport/internet/domainsocket/listener.go

@ -127,5 +127,5 @@ func (fl *fileLocker) Release() {
}
func init() {
common.Must(internet.RegisterTransportListener(internet.TransportProtocol_DomainSocket, Listen))
common.Must(internet.RegisterTransportListener(protocolName, Listen))
}

4
transport/internet/http/config.go

@ -6,6 +6,8 @@ import (
"v2ray.com/core/transport/internet"
)
const protocolName = "http"
func (c *Config) getHosts() []string {
if len(c.Host) == 0 {
return []string{"www.example.com"}
@ -39,7 +41,7 @@ func (c *Config) getNormalizedPath() string {
}
func init() {
common.Must(internet.RegisterProtocolConfigCreator(internet.TransportProtocol_HTTP, func() interface{} {
common.Must(internet.RegisterProtocolConfigCreatorByName(protocolName, func() interface{} {
return new(Config)
}))
}

2
transport/internet/http/dialer.go

@ -121,5 +121,5 @@ func Dial(ctx context.Context, dest net.Destination) (internet.Connection, error
}
func init() {
common.Must(internet.RegisterTransportDialer(internet.TransportProtocol_HTTP, Dial))
common.Must(internet.RegisterTransportDialer(protocolName, Dial))
}

2
transport/internet/http/hub.go

@ -126,5 +126,5 @@ func Listen(ctx context.Context, address net.Address, port net.Port, handler int
}
func init() {
common.Must(internet.RegisterTransportListener(internet.TransportProtocol_HTTP, Listen))
common.Must(internet.RegisterTransportListener(protocolName, Listen))
}

4
transport/internet/kcp/config.go

@ -7,6 +7,8 @@ import (
"v2ray.com/core/transport/internet"
)
const protocolName = "mkcp"
// GetMTUValue returns the value of MTU settings.
func (c *Config) GetMTUValue() uint32 {
if c == nil || c.Mtu == nil {
@ -97,7 +99,7 @@ func (c *Config) GetReceivingBufferSize() uint32 {
}
func init() {
common.Must(internet.RegisterProtocolConfigCreator(internet.TransportProtocol_MKCP, func() interface{} {
common.Must(internet.RegisterProtocolConfigCreatorByName(protocolName, func() interface{} {
return new(Config)
}))
}

2
transport/internet/kcp/dialer.go

@ -95,5 +95,5 @@ func DialKCP(ctx context.Context, dest net.Destination) (internet.Connection, er
}
func init() {
common.Must(internet.RegisterTransportDialer(internet.TransportProtocol_MKCP, DialKCP))
common.Must(internet.RegisterTransportDialer(protocolName, DialKCP))
}

2
transport/internet/kcp/listener.go

@ -187,5 +187,5 @@ func ListenKCP(ctx context.Context, address net.Address, port net.Port, addConn
}
func init() {
common.Must(internet.RegisterTransportListener(internet.TransportProtocol_MKCP, ListenKCP))
common.Must(internet.RegisterTransportListener(protocolName, ListenKCP))
}

4
transport/internet/tcp/config.go

@ -5,8 +5,10 @@ import (
"v2ray.com/core/transport/internet"
)
const protocolName = "tcp"
func init() {
common.Must(internet.RegisterProtocolConfigCreator(internet.TransportProtocol_TCP, func() interface{} {
common.Must(internet.RegisterProtocolConfigCreatorByName(protocolName, func() interface{} {
return new(Config)
}))
}

2
transport/internet/tcp/dialer.go

@ -48,5 +48,5 @@ func Dial(ctx context.Context, dest net.Destination) (internet.Connection, error
}
func init() {
common.Must(internet.RegisterTransportDialer(internet.TransportProtocol_TCP, Dial))
common.Must(internet.RegisterTransportDialer(protocolName, Dial))
}

2
transport/internet/tcp/hub.go

@ -92,5 +92,5 @@ func (v *Listener) Close() error {
}
func init() {
common.Must(internet.RegisterTransportListener(internet.TransportProtocol_TCP, ListenTCP))
common.Must(internet.RegisterTransportListener(protocolName, ListenTCP))
}

4
transport/internet/tcp_hub.go

@ -7,10 +7,10 @@ import (
)
var (
transportListenerCache = make(map[TransportProtocol]ListenFunc)
transportListenerCache = make(map[string]ListenFunc)
)
func RegisterTransportListener(protocol TransportProtocol, listener ListenFunc) error {
func RegisterTransportListener(protocol string, listener ListenFunc) error {
if _, found := transportListenerCache[protocol]; found {
return newError(protocol, " listener already registered.").AtError()
}

2
transport/internet/udp/dialer.go

@ -9,7 +9,7 @@ import (
)
func init() {
common.Must(internet.RegisterTransportDialer(internet.TransportProtocol_UDP,
common.Must(internet.RegisterTransportDialer(protocolName,
func(ctx context.Context, dest net.Destination) (internet.Connection, error) {
src := internet.DialerSourceFromContext(ctx)
conn, err := internet.DialSystem(ctx, src, dest)

2
transport/internet/udp/udp.go

@ -1,3 +1,5 @@
package udp
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg udp -path Transport,Internet,UDP
const protocolName = "udp"

4
transport/internet/websocket/config.go

@ -7,6 +7,8 @@ import (
"v2ray.com/core/transport/internet"
)
const protocolName = "websocket"
func (c *Config) GetNormalizedPath() string {
path := c.Path
if len(path) == 0 {
@ -27,7 +29,7 @@ func (c *Config) GetRequestHeader() http.Header {
}
func init() {
common.Must(internet.RegisterProtocolConfigCreator(internet.TransportProtocol_WebSocket, func() interface{} {
common.Must(internet.RegisterProtocolConfigCreatorByName(protocolName, func() interface{} {
return new(Config)
}))
}

2
transport/internet/websocket/dialer.go

@ -25,7 +25,7 @@ func Dial(ctx context.Context, dest net.Destination) (internet.Connection, error
}
func init() {
common.Must(internet.RegisterTransportDialer(internet.TransportProtocol_WebSocket, Dial))
common.Must(internet.RegisterTransportDialer(protocolName, Dial))
}
func dialWebsocket(ctx context.Context, dest net.Destination) (net.Conn, error) {

2
transport/internet/websocket/hub.go

@ -115,5 +115,5 @@ func (ln *Listener) Close() error {
}
func init() {
common.Must(internet.RegisterTransportListener(internet.TransportProtocol_WebSocket, ListenWS))
common.Must(internet.RegisterTransportListener(protocolName, ListenWS))
}

Loading…
Cancel
Save