Jelajahi Sumber

separate network and transport protocol

Darien Raymond 8 tahun lalu
induk
melakukan
d24fe9dbfb
41 mengubah file dengan 259 tambahan dan 319 penghapusan
  1. 2 2
      app/proxy/proxy_test.go
  2. 1 9
      common/net/network.go
  3. 12 20
      common/net/network.pb.go
  4. 1 5
      common/net/network.proto
  5. 5 5
      common/protocol/server_spec.pb.go
  6. 0 7
      proxy/blackhole/blackhole.go
  7. 1 6
      proxy/creator.go
  8. 0 6
      proxy/dokodemo/dokodemo.go
  9. 4 4
      proxy/dokodemo/dokodemo_test.go
  10. 0 6
      proxy/freedom/freedom.go
  11. 2 2
      proxy/freedom/freedom_test.go
  12. 0 25
      proxy/handler_cache.go
  13. 0 7
      proxy/http/server.go
  14. 0 7
      proxy/shadowsocks/client.go
  15. 0 6
      proxy/shadowsocks/server.go
  16. 0 6
      proxy/socks/client.go
  17. 0 6
      proxy/socks/server.go
  18. 0 6
      proxy/vmess/inbound/inbound.go
  19. 0 6
      proxy/vmess/outbound/outbound.go
  20. 6 7
      tools/conf/transport.go
  21. 33 15
      tools/conf/transport_internet.go
  22. 3 3
      transport/config.go
  23. 11 12
      transport/config.pb.go
  24. 1 1
      transport/config.proto
  25. 29 23
      transport/internet/config.go
  26. 71 42
      transport/internet/config.pb.go
  27. 12 6
      transport/internet/config.proto
  28. 9 12
      transport/internet/dialer.go
  29. 3 3
      transport/internet/kcp/config.go
  30. 2 2
      transport/internet/kcp/dialer.go
  31. 6 6
      transport/internet/kcp/kcp_test.go
  32. 2 2
      transport/internet/kcp/listener.go
  33. 3 3
      transport/internet/tcp/config.go
  34. 2 2
      transport/internet/tcp/dialer.go
  35. 2 2
      transport/internet/tcp/hub.go
  36. 9 10
      transport/internet/tcp_hub.go
  37. 1 1
      transport/internet/udp/dialer.go
  38. 3 3
      transport/internet/websocket/config.go
  39. 3 3
      transport/internet/websocket/dialer.go
  40. 2 2
      transport/internet/websocket/hub.go
  41. 18 18
      transport/internet/websocket/ws_test.go

+ 2 - 2
app/proxy/proxy_test.go

@@ -26,7 +26,7 @@ func TestProxyDial(t *testing.T) {
 	common.Must(outboundManager.SetHandler("tag", freedom.New(&freedom.Config{}, space, &proxy.OutboundHandlerMeta{
 		Tag: "tag",
 		StreamSettings: &internet.StreamConfig{
-			Network: v2net.Network_TCP,
+			Protocol: internet.TransportProtocol_TCP,
 		},
 	})))
 
@@ -49,7 +49,7 @@ func TestProxyDial(t *testing.T) {
 
 	conn, err := proxy.Dial(v2net.LocalHostIP, dest, internet.DialerOptions{
 		Stream: &internet.StreamConfig{
-			Network: v2net.Network_TCP,
+			Protocol: internet.TransportProtocol_TCP,
 		},
 		Proxy: &internet.ProxyConfig{
 			Tag: "tag",

+ 1 - 9
common/net/network.go

@@ -13,10 +13,6 @@ func ParseNetwork(nwStr string) Network {
 		return Network_TCP
 	case "udp":
 		return Network_UDP
-	case "kcp":
-		return Network_KCP
-	case "ws":
-		return Network_WebSocket
 	default:
 		return Network_Unknown
 	}
@@ -32,7 +28,7 @@ func (v Network) SystemString() string {
 	switch v {
 	case Network_TCP:
 		return "tcp"
-	case Network_UDP, Network_KCP:
+	case Network_UDP:
 		return "udp"
 	default:
 		return "unknown"
@@ -45,10 +41,6 @@ func (v Network) URLPrefix() string {
 		return "tcp"
 	case Network_UDP:
 		return "udp"
-	case Network_KCP:
-		return "kcp"
-	case Network_WebSocket:
-		return "ws"
 	default:
 		return "unknown"
 	}

+ 12 - 20
common/net/network.pb.go

@@ -16,10 +16,8 @@ const (
 	// Native TCP provided by system.
 	Network_RawTCP Network = 1
 	// V2Ray specific TCP.
-	Network_TCP       Network = 2
-	Network_UDP       Network = 3
-	Network_KCP       Network = 4
-	Network_WebSocket Network = 5
+	Network_TCP Network = 2
+	Network_UDP Network = 3
 )
 
 var Network_name = map[int32]string{
@@ -27,16 +25,12 @@ var Network_name = map[int32]string{
 	1: "RawTCP",
 	2: "TCP",
 	3: "UDP",
-	4: "KCP",
-	5: "WebSocket",
 }
 var Network_value = map[string]int32{
-	"Unknown":   0,
-	"RawTCP":    1,
-	"TCP":       2,
-	"UDP":       3,
-	"KCP":       4,
-	"WebSocket": 5,
+	"Unknown": 0,
+	"RawTCP":  1,
+	"TCP":     2,
+	"UDP":     3,
 }
 
 func (x Network) String() string {
@@ -68,20 +62,18 @@ func init() {
 func init() { proto.RegisterFile("v2ray.com/core/common/net/network.proto", fileDescriptor2) }
 
 var fileDescriptor2 = []byte{
-	// 225 bytes of a gzipped FileDescriptorProto
+	// 203 bytes of a gzipped FileDescriptorProto
 	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0x52, 0x2f, 0x33, 0x2a, 0x4a,
 	0xac, 0xd4, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x4f, 0xce, 0xcf, 0xcd, 0xcd,
 	0xcf, 0xd3, 0xcf, 0x4b, 0x2d, 0x01, 0xe1, 0xf2, 0xfc, 0xa2, 0x6c, 0xbd, 0x82, 0xa2, 0xfc, 0x92,
 	0x7c, 0x21, 0x51, 0x98, 0xc2, 0xa2, 0x54, 0x3d, 0x88, 0x22, 0xbd, 0xbc, 0xd4, 0x12, 0x25, 0x77,
 	0x2e, 0x6e, 0x3f, 0x88, 0x3a, 0x9f, 0xcc, 0xe2, 0x12, 0x21, 0x0b, 0x2e, 0x76, 0xa8, 0x36, 0x09,
 	0x46, 0x05, 0x66, 0x0d, 0x3e, 0x23, 0x39, 0x3d, 0xac, 0xfa, 0xf4, 0xa0, 0x9a, 0x82, 0x60, 0xca,
-	0xb5, 0x02, 0xb8, 0xd8, 0xa1, 0x62, 0x42, 0xdc, 0x5c, 0xec, 0xa1, 0x79, 0xd9, 0x79, 0xf9, 0xe5,
+	0xb5, 0x2c, 0xb8, 0xd8, 0xa1, 0x62, 0x42, 0xdc, 0x5c, 0xec, 0xa1, 0x79, 0xd9, 0x79, 0xf9, 0xe5,
 	0x79, 0x02, 0x0c, 0x42, 0x7c, 0x5c, 0x6c, 0x41, 0x89, 0xe5, 0x21, 0xce, 0x01, 0x02, 0x8c, 0x52,
 	0x4c, 0x1c, 0x8c, 0x42, 0xec, 0x5c, 0xcc, 0x20, 0x0e, 0x13, 0x88, 0x11, 0xea, 0x12, 0x20, 0xc0,
-	0x0c, 0x62, 0x78, 0x3b, 0x07, 0x08, 0xb0, 0x08, 0xf1, 0x72, 0x71, 0x86, 0xa7, 0x26, 0x05, 0xe7,
-	0x27, 0x67, 0xa7, 0x96, 0x08, 0xb0, 0x3a, 0xb9, 0x71, 0x49, 0x26, 0xe7, 0xe7, 0x62, 0xb7, 0xdf,
-	0x89, 0x07, 0x6a, 0x59, 0x00, 0xc8, 0x73, 0x51, 0xcc, 0x79, 0xa9, 0x25, 0xab, 0x98, 0x44, 0xc3,
-	0x8c, 0x82, 0x12, 0x2b, 0xf5, 0x9c, 0x41, 0x4a, 0x9d, 0x21, 0x4a, 0xfd, 0x52, 0x4b, 0x92, 0xd8,
-	0xc0, 0x01, 0x60, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x45, 0xf9, 0x86, 0x63, 0x2b, 0x01, 0x00,
-	0x00,
+	0xec, 0xe4, 0xc6, 0x25, 0x99, 0x9c, 0x9f, 0x8b, 0xdd, 0x1e, 0x27, 0x1e, 0xa8, 0xa1, 0x01, 0x20,
+	0x4f, 0x44, 0x31, 0xe7, 0xa5, 0x96, 0xac, 0x62, 0x12, 0x0d, 0x33, 0x0a, 0x4a, 0xac, 0xd4, 0x73,
+	0x06, 0x29, 0x75, 0x86, 0x28, 0xf5, 0x4b, 0x2d, 0x49, 0x62, 0x03, 0x7b, 0xd4, 0x18, 0x10, 0x00,
+	0x00, 0xff, 0xff, 0x3c, 0x17, 0x32, 0x51, 0x13, 0x01, 0x00, 0x00,
 }

+ 1 - 5
common/net/network.proto

@@ -16,12 +16,8 @@ enum Network {
   TCP = 2;
 
   UDP = 3;
-
-  KCP = 4;
-  
-  WebSocket = 5;
 }
 
 message NetworkList {
   repeated Network network = 1;
-}
+}

+ 5 - 5
common/protocol/server_spec.pb.go

@@ -3,7 +3,7 @@ package protocol
 import proto "github.com/golang/protobuf/proto"
 import fmt "fmt"
 import math "math"
-import v2ray_core_common_net1 "v2ray.com/core/common/net"
+import v2ray_core_common_net "v2ray.com/core/common/net"
 
 // Reference imports to suppress errors if they are not otherwise used.
 var _ = proto.Marshal
@@ -11,9 +11,9 @@ var _ = fmt.Errorf
 var _ = math.Inf
 
 type ServerEndpoint struct {
-	Address *v2ray_core_common_net1.IPOrDomain `protobuf:"bytes,1,opt,name=address" json:"address,omitempty"`
-	Port    uint32                             `protobuf:"varint,2,opt,name=port" json:"port,omitempty"`
-	User    []*User                            `protobuf:"bytes,3,rep,name=user" json:"user,omitempty"`
+	Address *v2ray_core_common_net.IPOrDomain `protobuf:"bytes,1,opt,name=address" json:"address,omitempty"`
+	Port    uint32                            `protobuf:"varint,2,opt,name=port" json:"port,omitempty"`
+	User    []*User                           `protobuf:"bytes,3,rep,name=user" json:"user,omitempty"`
 }
 
 func (m *ServerEndpoint) Reset()                    { *m = ServerEndpoint{} }
@@ -21,7 +21,7 @@ func (m *ServerEndpoint) String() string            { return proto.CompactTextSt
 func (*ServerEndpoint) ProtoMessage()               {}
 func (*ServerEndpoint) Descriptor() ([]byte, []int) { return fileDescriptor2, []int{0} }
 
-func (m *ServerEndpoint) GetAddress() *v2ray_core_common_net1.IPOrDomain {
+func (m *ServerEndpoint) GetAddress() *v2ray_core_common_net.IPOrDomain {
 	if m != nil {
 		return m.Address
 	}

+ 0 - 7
proxy/blackhole/blackhole.go

@@ -41,13 +41,6 @@ func (v *Handler) Dispatch(destination v2net.Destination, ray ray.OutboundRay) {
 // Factory is an utility for creating blackhole handlers.
 type Factory struct{}
 
-// StreamCapability implements OutboundHandlerFactory.StreamCapability().
-func (v *Factory) StreamCapability() v2net.NetworkList {
-	return v2net.NetworkList{
-		Network: []v2net.Network{v2net.Network_TCP},
-	}
-}
-
 // Create implements OutboundHandlerFactory.Create().
 func (v *Factory) Create(space app.Space, config interface{}, meta *proxy.OutboundHandlerMeta) (proxy.OutboundHandler, error) {
 	return New(space, config.(*Config), meta)

+ 1 - 6
proxy/creator.go

@@ -1,16 +1,11 @@
 package proxy
 
-import (
-	"v2ray.com/core/app"
-	v2net "v2ray.com/core/common/net"
-)
+import "v2ray.com/core/app"
 
 type InboundHandlerFactory interface {
-	StreamCapability() v2net.NetworkList
 	Create(space app.Space, config interface{}, meta *InboundHandlerMeta) (InboundHandler, error)
 }
 
 type OutboundHandlerFactory interface {
-	StreamCapability() v2net.NetworkList
 	Create(space app.Space, config interface{}, meta *OutboundHandlerMeta) (OutboundHandler, error)
 }

+ 0 - 6
proxy/dokodemo/dokodemo.go

@@ -207,12 +207,6 @@ func (v *DokodemoDoor) HandleTCPConnection(conn internet.Connection) {
 
 type Factory struct{}
 
-func (v *Factory) StreamCapability() v2net.NetworkList {
-	return v2net.NetworkList{
-		Network: []v2net.Network{v2net.Network_TCP},
-	}
-}
-
 func (v *Factory) Create(space app.Space, rawConfig interface{}, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error) {
 	return NewDokodemoDoor(rawConfig.(*Config), space, meta), nil
 }

+ 4 - 4
proxy/dokodemo/dokodemo_test.go

@@ -49,7 +49,7 @@ func TestDokodemoTCP(t *testing.T) {
 			&proxy.OutboundHandlerMeta{
 				Address: v2net.LocalHostIP,
 				StreamSettings: &internet.StreamConfig{
-					Network: v2net.Network_TCP,
+					Protocol: internet.TransportProtocol_TCP,
 				},
 			}))
 
@@ -65,7 +65,7 @@ func TestDokodemoTCP(t *testing.T) {
 		Address: v2net.LocalHostIP,
 		Port:    port,
 		StreamSettings: &internet.StreamConfig{
-			Network: v2net.Network_TCP,
+			Protocol: internet.TransportProtocol_TCP,
 		}})
 	defer dokodemo.Close()
 
@@ -121,7 +121,7 @@ func TestDokodemoUDP(t *testing.T) {
 			&proxy.OutboundHandlerMeta{
 				Address: v2net.AnyIP,
 				StreamSettings: &internet.StreamConfig{
-					Network: v2net.Network_TCP,
+					Protocol: internet.TransportProtocol_TCP,
 				}}))
 
 	data2Send := "Data to be sent to remote."
@@ -136,7 +136,7 @@ func TestDokodemoUDP(t *testing.T) {
 		Address: v2net.LocalHostIP,
 		Port:    port,
 		StreamSettings: &internet.StreamConfig{
-			Network: v2net.Network_TCP,
+			Protocol: internet.TransportProtocol_TCP,
 		}})
 	defer dokodemo.Close()
 

+ 0 - 6
proxy/freedom/freedom.go

@@ -130,12 +130,6 @@ func (v *Handler) Dispatch(destination v2net.Destination, ray ray.OutboundRay) {
 
 type Factory struct{}
 
-func (v *Factory) StreamCapability() v2net.NetworkList {
-	return v2net.NetworkList{
-		Network: []v2net.Network{v2net.Network_TCP},
-	}
-}
-
 func (v *Factory) Create(space app.Space, config interface{}, meta *proxy.OutboundHandlerMeta) (proxy.OutboundHandler, error) {
 	return New(config.(*Config), space, meta), nil
 }

+ 2 - 2
proxy/freedom/freedom_test.go

@@ -43,7 +43,7 @@ func TestSinglePacket(t *testing.T) {
 		&proxy.OutboundHandlerMeta{
 			Address: v2net.AnyIP,
 			StreamSettings: &internet.StreamConfig{
-				Network: v2net.Network_TCP,
+				Protocol: internet.TransportProtocol_TCP,
 			},
 		})
 	assert.Error(space.Initialize()).IsNil()
@@ -83,7 +83,7 @@ func TestIPResolution(t *testing.T) {
 		&proxy.OutboundHandlerMeta{
 			Address: v2net.AnyIP,
 			StreamSettings: &internet.StreamConfig{
-				Network: v2net.Network_TCP,
+				Protocol: internet.TransportProtocol_TCP,
 			},
 		})
 

+ 0 - 25
proxy/handler_cache.go

@@ -4,8 +4,6 @@ import (
 	"v2ray.com/core/app"
 	"v2ray.com/core/common"
 	"v2ray.com/core/common/errors"
-	v2net "v2ray.com/core/common/net"
-	"v2ray.com/core/transport/internet"
 )
 
 var (
@@ -34,18 +32,6 @@ func CreateInboundHandler(name string, space app.Space, config interface{}, meta
 	if !found {
 		return nil, errors.New("Proxy: Unknown inbound name: " + name)
 	}
-	if meta.StreamSettings == nil {
-		meta.StreamSettings = &internet.StreamConfig{
-			Network: creator.StreamCapability().Get(0),
-		}
-	} else if meta.StreamSettings.Network == v2net.Network_Unknown {
-		meta.StreamSettings.Network = creator.StreamCapability().Get(0)
-	} else {
-		if !creator.StreamCapability().HasNetwork(meta.StreamSettings.Network) {
-			return nil, errors.New("Proxy: Invalid network: " + meta.StreamSettings.Network.String())
-		}
-	}
-
 	return creator.Create(space, config, meta)
 }
 
@@ -54,17 +40,6 @@ func CreateOutboundHandler(name string, space app.Space, config interface{}, met
 	if !found {
 		return nil, errors.New("Proxy: Unknown outbound name: " + name)
 	}
-	if meta.StreamSettings == nil {
-		meta.StreamSettings = &internet.StreamConfig{
-			Network: creator.StreamCapability().Get(0),
-		}
-	} else if meta.StreamSettings.Network == v2net.Network_Unknown {
-		meta.StreamSettings.Network = creator.StreamCapability().Get(0)
-	} else {
-		if !creator.StreamCapability().HasNetwork(meta.StreamSettings.Network) {
-			return nil, errors.New("Proxy: Invalid network: " + meta.StreamSettings.Network.String())
-		}
-	}
 
 	return creator.Create(space, config, meta)
 }

+ 0 - 7
proxy/http/server.go

@@ -288,13 +288,6 @@ func (v *Server) handlePlainHTTP(request *http.Request, session *proxy.SessionIn
 // ServerFactory is a InboundHandlerFactory.
 type ServerFactory struct{}
 
-// StreamCapability implements InboundHandlerFactory.StreamCapability().
-func (v *ServerFactory) StreamCapability() v2net.NetworkList {
-	return v2net.NetworkList{
-		Network: []v2net.Network{v2net.Network_TCP},
-	}
-}
-
 // Create implements InboundHandlerFactory.Create().
 func (v *ServerFactory) Create(space app.Space, rawConfig interface{}, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error) {
 	return NewServer(rawConfig.(*ServerConfig), space, meta), nil

+ 0 - 7
proxy/shadowsocks/client.go

@@ -167,13 +167,6 @@ func (v *Client) Dispatch(destination v2net.Destination, ray ray.OutboundRay) {
 // ClientFactory is a OutboundHandlerFactory.
 type ClientFactory struct{}
 
-// StreamCapability implements OutboundHandlerFactory.StreamCapability().
-func (ClientFactory) StreamCapability() v2net.NetworkList {
-	return v2net.NetworkList{
-		Network: []v2net.Network{v2net.Network_TCP},
-	}
-}
-
 // Create implements OutboundHandlerFactory.Create().
 func (ClientFactory) Create(space app.Space, rawConfig interface{}, meta *proxy.OutboundHandlerMeta) (proxy.OutboundHandler, error) {
 	return NewClient(rawConfig.(*ClientConfig), space, meta)

+ 0 - 6
proxy/shadowsocks/server.go

@@ -218,12 +218,6 @@ func (v *Server) handleConnection(conn internet.Connection) {
 
 type ServerFactory struct{}
 
-func (v *ServerFactory) StreamCapability() v2net.NetworkList {
-	return v2net.NetworkList{
-		Network: []v2net.Network{v2net.Network_TCP},
-	}
-}
-
 func (v *ServerFactory) Create(space app.Space, rawConfig interface{}, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error) {
 	return NewServer(rawConfig.(*ServerConfig), space, meta)
 }

+ 0 - 6
proxy/socks/client.go

@@ -114,12 +114,6 @@ func (c *Client) Dispatch(destination net.Destination, ray ray.OutboundRay) {
 
 type ClientFactory struct{}
 
-func (ClientFactory) StreamCapability() net.NetworkList {
-	return net.NetworkList{
-		Network: []net.Network{net.Network_TCP},
-	}
-}
-
 func (ClientFactory) Create(space app.Space, rawConfig interface{}, meta *proxy.OutboundHandlerMeta) (proxy.OutboundHandler, error) {
 	return NewClient(rawConfig.(*ClientConfig), space, meta)
 }

+ 0 - 6
proxy/socks/server.go

@@ -183,12 +183,6 @@ func (v *Server) transport(reader io.Reader, writer io.Writer, session *proxy.Se
 
 type ServerFactory struct{}
 
-func (v *ServerFactory) StreamCapability() v2net.NetworkList {
-	return v2net.NetworkList{
-		Network: []v2net.Network{v2net.Network_TCP},
-	}
-}
-
 func (v *ServerFactory) Create(space app.Space, rawConfig interface{}, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error) {
 	return NewServer(rawConfig.(*ServerConfig), space, meta), nil
 }

+ 0 - 6
proxy/vmess/inbound/inbound.go

@@ -253,12 +253,6 @@ func (v *VMessInboundHandler) HandleConnection(connection internet.Connection) {
 
 type Factory struct{}
 
-func (v *Factory) StreamCapability() v2net.NetworkList {
-	return v2net.NetworkList{
-		Network: []v2net.Network{v2net.Network_TCP, v2net.Network_KCP, v2net.Network_WebSocket},
-	}
-}
-
 func (v *Factory) Create(space app.Space, rawConfig interface{}, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error) {
 	config := rawConfig.(*Config)
 

+ 0 - 6
proxy/vmess/outbound/outbound.go

@@ -145,12 +145,6 @@ func (v *VMessOutboundHandler) Dispatch(target v2net.Destination, outboundRay ra
 // Factory is a proxy factory for VMess outbound.
 type Factory struct{}
 
-func (v *Factory) StreamCapability() v2net.NetworkList {
-	return v2net.NetworkList{
-		Network: []v2net.Network{v2net.Network_TCP, v2net.Network_KCP, v2net.Network_WebSocket},
-	}
-}
-
 func (v *Factory) Create(space app.Space, rawConfig interface{}, meta *proxy.OutboundHandlerMeta) (proxy.OutboundHandler, error) {
 	vOutConfig := rawConfig.(*Config)
 

+ 6 - 7
tools/conf/transport.go

@@ -2,7 +2,6 @@ package conf
 
 import (
 	"v2ray.com/core/common/errors"
-	v2net "v2ray.com/core/common/net"
 	"v2ray.com/core/transport"
 	"v2ray.com/core/transport/internet"
 )
@@ -21,8 +20,8 @@ func (v *TransportConfig) Build() (*transport.Config, error) {
 		if err != nil {
 			return nil, errors.Base(err).Message("Failed to build TCP config.")
 		}
-		config.NetworkSettings = append(config.NetworkSettings, &internet.NetworkSettings{
-			Network:  v2net.Network_TCP,
+		config.TransportSettings = append(config.TransportSettings, &internet.TransportSettings{
+			Protocol: internet.TransportProtocol_TCP,
 			Settings: ts,
 		})
 	}
@@ -32,8 +31,8 @@ func (v *TransportConfig) Build() (*transport.Config, error) {
 		if err != nil {
 			return nil, errors.Base(err).Message("Failed to build mKCP config.")
 		}
-		config.NetworkSettings = append(config.NetworkSettings, &internet.NetworkSettings{
-			Network:  v2net.Network_KCP,
+		config.TransportSettings = append(config.TransportSettings, &internet.TransportSettings{
+			Protocol: internet.TransportProtocol_MKCP,
 			Settings: ts,
 		})
 	}
@@ -43,8 +42,8 @@ func (v *TransportConfig) Build() (*transport.Config, error) {
 		if err != nil {
 			return nil, errors.Base(err).Message("Failed to build WebSocket config.")
 		}
-		config.NetworkSettings = append(config.NetworkSettings, &internet.NetworkSettings{
-			Network:  v2net.Network_WebSocket,
+		config.TransportSettings = append(config.TransportSettings, &internet.TransportSettings{
+			Protocol: internet.TransportProtocol_WebSocket,
 			Settings: ts,
 		})
 	}

+ 33 - 15
tools/conf/transport_internet.go

@@ -6,7 +6,6 @@ import (
 	"strings"
 
 	"v2ray.com/core/common/errors"
-	v2net "v2ray.com/core/common/net"
 	"v2ray.com/core/common/serial"
 	"v2ray.com/core/transport/internet"
 	"v2ray.com/core/transport/internet/kcp"
@@ -175,21 +174,40 @@ func (v *TLSConfig) Build() (*serial.TypedMessage, error) {
 	return serial.ToTypedMessage(config), nil
 }
 
+type TransportProtocol string
+
+func (p TransportProtocol) Build() (internet.TransportProtocol, error) {
+	switch strings.ToLower(string(p)) {
+	case "tcp":
+		return internet.TransportProtocol_TCP, nil
+	case "kcp", "mkcp":
+		return internet.TransportProtocol_MKCP, nil
+	case "ws", "websocket":
+		return internet.TransportProtocol_WebSocket, nil
+	default:
+		return internet.TransportProtocol_TCP, errors.New("Config: unknown transport protocol: ", p)
+	}
+}
+
 type StreamConfig struct {
-	Network     *Network         `json:"network"`
-	Security    string           `json:"security"`
-	TLSSettings *TLSConfig       `json:"tlsSettings"`
-	TCPSettings *TCPConfig       `json:"tcpSettings"`
-	KCPSettings *KCPConfig       `json:"kcpSettings"`
-	WSSettings  *WebSocketConfig `json:"wsSettings"`
+	Network     *TransportProtocol `json:"network"`
+	Security    string             `json:"security"`
+	TLSSettings *TLSConfig         `json:"tlsSettings"`
+	TCPSettings *TCPConfig         `json:"tcpSettings"`
+	KCPSettings *KCPConfig         `json:"kcpSettings"`
+	WSSettings  *WebSocketConfig   `json:"wsSettings"`
 }
 
 func (v *StreamConfig) Build() (*internet.StreamConfig, error) {
 	config := &internet.StreamConfig{
-		Network: v2net.Network_TCP,
+		Protocol: internet.TransportProtocol_TCP,
 	}
 	if v.Network != nil {
-		config.Network = (*v.Network).Build()
+		protocol, err := (*v.Network).Build()
+		if err != nil {
+			return nil, err
+		}
+		config.Protocol = protocol
 	}
 	if strings.ToLower(v.Security) == "tls" {
 		tlsSettings := v.TLSSettings
@@ -208,8 +226,8 @@ func (v *StreamConfig) Build() (*internet.StreamConfig, error) {
 		if err != nil {
 			return nil, errors.Base(err).Message("Failed to build TCP config.")
 		}
-		config.NetworkSettings = append(config.NetworkSettings, &internet.NetworkSettings{
-			Network:  v2net.Network_TCP,
+		config.TransportSettings = append(config.TransportSettings, &internet.TransportSettings{
+			Protocol: internet.TransportProtocol_TCP,
 			Settings: ts,
 		})
 	}
@@ -218,8 +236,8 @@ func (v *StreamConfig) Build() (*internet.StreamConfig, error) {
 		if err != nil {
 			return nil, errors.Base(err).Message("Failed to build mKCP config.")
 		}
-		config.NetworkSettings = append(config.NetworkSettings, &internet.NetworkSettings{
-			Network:  v2net.Network_KCP,
+		config.TransportSettings = append(config.TransportSettings, &internet.TransportSettings{
+			Protocol: internet.TransportProtocol_MKCP,
 			Settings: ts,
 		})
 	}
@@ -228,8 +246,8 @@ func (v *StreamConfig) Build() (*internet.StreamConfig, error) {
 		if err != nil {
 			return nil, errors.Base(err).Message("Failed to build WebSocket config.")
 		}
-		config.NetworkSettings = append(config.NetworkSettings, &internet.NetworkSettings{
-			Network:  v2net.Network_WebSocket,
+		config.TransportSettings = append(config.TransportSettings, &internet.TransportSettings{
+			Protocol: internet.TransportProtocol_WebSocket,
 			Settings: ts,
 		})
 	}

+ 3 - 3
transport/config.go

@@ -5,11 +5,11 @@ import (
 )
 
 // Apply applies this Config.
-func (v *Config) Apply() error {
-	if v == nil {
+func (c *Config) Apply() error {
+	if c == nil {
 		return nil
 	}
-	if err := internet.ApplyGlobalNetworkSettings(v.NetworkSettings); err != nil {
+	if err := internet.ApplyGlobalTransportSettings(c.TransportSettings); err != nil {
 		return err
 	}
 	return nil

+ 11 - 12
transport/config.pb.go

@@ -18,7 +18,7 @@ const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
 
 // Global transport settings. This affects all type of connections that go through V2Ray.
 type Config struct {
-	NetworkSettings []*v2ray_core_transport_internet.NetworkSettings `protobuf:"bytes,1,rep,name=network_settings,json=networkSettings" json:"network_settings,omitempty"`
+	TransportSettings []*v2ray_core_transport_internet.TransportSettings `protobuf:"bytes,1,rep,name=transport_settings,json=transportSettings" json:"transport_settings,omitempty"`
 }
 
 func (m *Config) Reset()                    { *m = Config{} }
@@ -26,9 +26,9 @@ func (m *Config) String() string            { return proto.CompactTextString(m)
 func (*Config) ProtoMessage()               {}
 func (*Config) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
 
-func (m *Config) GetNetworkSettings() []*v2ray_core_transport_internet.NetworkSettings {
+func (m *Config) GetTransportSettings() []*v2ray_core_transport_internet.TransportSettings {
 	if m != nil {
-		return m.NetworkSettings
+		return m.TransportSettings
 	}
 	return nil
 }
@@ -40,17 +40,16 @@ func init() {
 func init() { proto.RegisterFile("v2ray.com/core/transport/config.proto", fileDescriptor0) }
 
 var fileDescriptor0 = []byte{
-	// 180 bytes of a gzipped FileDescriptorProto
+	// 174 bytes of a gzipped FileDescriptorProto
 	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0x52, 0x2d, 0x33, 0x2a, 0x4a,
 	0xac, 0xd4, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x2f, 0x29, 0x4a, 0xcc, 0x2b,
 	0x2e, 0xc8, 0x2f, 0x2a, 0xd1, 0x4f, 0xce, 0xcf, 0x4b, 0xcb, 0x4c, 0xd7, 0x2b, 0x28, 0xca, 0x2f,
 	0xc9, 0x17, 0x12, 0x81, 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e8, 0x42, 0x4e, 0x9e, 0x5c, 0x12, 0xc9, 0xf9, 0xb9, 0x58,
+	0x4d, 0x72, 0xe2, 0x86, 0x38, 0x22, 0x00, 0xe4, 0xa6, 0x28, 0x4e, 0xb8, 0xf8, 0x2a, 0x26, 0x91,
+	0x30, 0xa3, 0xa0, 0xc4, 0x4a, 0x3d, 0x67, 0x90, 0x72, 0xb8, 0x2d, 0x49, 0x6c, 0x60, 0xc7, 0x1b,
+	0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x4b, 0xd3, 0xcc, 0x90, 0x2b, 0x01, 0x00, 0x00,
 }

+ 1 - 1
transport/config.proto

@@ -10,5 +10,5 @@ import "v2ray.com/core/transport/internet/config.proto";
 
 // Global transport settings. This affects all type of connections that go through V2Ray.
 message Config {
-  repeated v2ray.core.transport.internet.NetworkSettings network_settings = 1;
+  repeated v2ray.core.transport.internet.TransportSettings transport_settings = 1;
 }

+ 29 - 23
transport/internet/config.go

@@ -2,52 +2,58 @@ package internet
 
 import (
 	"v2ray.com/core/common/errors"
-	"v2ray.com/core/common/log"
-	v2net "v2ray.com/core/common/net"
 	"v2ray.com/core/common/serial"
 )
 
 type ConfigCreator func() interface{}
 
 var (
-	globalNetworkConfigCreatorCache = make(map[v2net.Network]ConfigCreator)
-
-	globalNetworkSettings []*NetworkSettings
-
-	ErrUnconfiguredNetwork = errors.New("Network config creator not set.")
+	globalTransportConfigCreatorCache = make(map[TransportProtocol]ConfigCreator)
+	globalTransportSettings           []*TransportSettings
 )
 
-func RegisterNetworkConfigCreator(network v2net.Network, creator ConfigCreator) error {
+func RegisterProtocolConfigCreator(protocol TransportProtocol, creator ConfigCreator) error {
 	// TODO: check duplicate
-	globalNetworkConfigCreatorCache[network] = creator
+	globalTransportConfigCreatorCache[protocol] = creator
 	return nil
 }
 
-func CreateNetworkConfig(network v2net.Network) (interface{}, error) {
-	creator, ok := globalNetworkConfigCreatorCache[network]
+func CreateTransportConfig(protocol TransportProtocol) (interface{}, error) {
+	creator, ok := globalTransportConfigCreatorCache[protocol]
 	if !ok {
-		log.Warning("Internet: Network config creator not found: ", network)
-		return nil, ErrUnconfiguredNetwork
+		return nil, errors.New("Internet: Unknown transport protocol: ", protocol)
 	}
 	return creator(), nil
 }
 
-func (v *NetworkSettings) GetTypedSettings() (interface{}, error) {
+func (v *TransportSettings) GetTypedSettings() (interface{}, error) {
 	return v.Settings.GetInstance()
 }
 
-func (v *StreamConfig) GetEffectiveNetworkSettings() (interface{}, error) {
-	for _, settings := range v.NetworkSettings {
-		if settings.Network == v.Network {
-			return settings.GetTypedSettings()
+func (v *StreamConfig) GetEffectiveProtocol() TransportProtocol {
+	if v == nil {
+		return TransportProtocol_TCP
+	}
+	return v.Protocol
+}
+
+func (v *StreamConfig) GetEffectiveTransportSettings() (interface{}, error) {
+	protocol := v.GetEffectiveProtocol()
+
+	if v != nil {
+		for _, settings := range v.TransportSettings {
+			if settings.Protocol == protocol {
+				return settings.GetTypedSettings()
+			}
 		}
 	}
-	for _, settings := range globalNetworkSettings {
-		if settings.Network == v.Network {
+
+	for _, settings := range globalTransportSettings {
+		if settings.Protocol == protocol {
 			return settings.GetTypedSettings()
 		}
 	}
-	return CreateNetworkConfig(v.Network)
+	return CreateTransportConfig(protocol)
 }
 
 func (v *StreamConfig) GetEffectiveSecuritySettings() (interface{}, error) {
@@ -63,8 +69,8 @@ func (v *StreamConfig) HasSecuritySettings() bool {
 	return len(v.SecurityType) > 0
 }
 
-func ApplyGlobalNetworkSettings(settings []*NetworkSettings) error {
-	globalNetworkSettings = settings
+func ApplyGlobalTransportSettings(settings []*TransportSettings) error {
+	globalTransportSettings = settings
 	return nil
 }
 

+ 71 - 42
transport/internet/config.pb.go

@@ -3,7 +3,6 @@ package internet
 import proto "github.com/golang/protobuf/proto"
 import fmt "fmt"
 import math "math"
-import v2ray_core_common_net "v2ray.com/core/common/net"
 import v2ray_core_common_serial "v2ray.com/core/common/serial"
 
 // Reference imports to suppress errors if they are not otherwise used.
@@ -17,26 +16,53 @@ var _ = math.Inf
 // proto package needs to be updated.
 const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
 
-type NetworkSettings struct {
+type TransportProtocol int32
+
+const (
+	TransportProtocol_TCP       TransportProtocol = 0
+	TransportProtocol_UDP       TransportProtocol = 1
+	TransportProtocol_MKCP      TransportProtocol = 2
+	TransportProtocol_WebSocket TransportProtocol = 3
+)
+
+var TransportProtocol_name = map[int32]string{
+	0: "TCP",
+	1: "UDP",
+	2: "MKCP",
+	3: "WebSocket",
+}
+var TransportProtocol_value = map[string]int32{
+	"TCP":       0,
+	"UDP":       1,
+	"MKCP":      2,
+	"WebSocket": 3,
+}
+
+func (x TransportProtocol) String() string {
+	return proto.EnumName(TransportProtocol_name, int32(x))
+}
+func (TransportProtocol) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
+
+type TransportSettings struct {
 	// Type of network that this settings supports.
-	Network v2ray_core_common_net.Network `protobuf:"varint,1,opt,name=network,enum=v2ray.core.common.net.Network" json:"network,omitempty"`
+	Protocol TransportProtocol `protobuf:"varint,1,opt,name=protocol,enum=v2ray.core.transport.internet.TransportProtocol" json:"protocol,omitempty"`
 	// Specific settings.
 	Settings *v2ray_core_common_serial.TypedMessage `protobuf:"bytes,2,opt,name=settings" json:"settings,omitempty"`
 }
 
-func (m *NetworkSettings) Reset()                    { *m = NetworkSettings{} }
-func (m *NetworkSettings) String() string            { return proto.CompactTextString(m) }
-func (*NetworkSettings) ProtoMessage()               {}
-func (*NetworkSettings) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
+func (m *TransportSettings) Reset()                    { *m = TransportSettings{} }
+func (m *TransportSettings) String() string            { return proto.CompactTextString(m) }
+func (*TransportSettings) ProtoMessage()               {}
+func (*TransportSettings) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
 
-func (m *NetworkSettings) GetNetwork() v2ray_core_common_net.Network {
+func (m *TransportSettings) GetProtocol() TransportProtocol {
 	if m != nil {
-		return m.Network
+		return m.Protocol
 	}
-	return v2ray_core_common_net.Network_Unknown
+	return TransportProtocol_TCP
 }
 
-func (m *NetworkSettings) GetSettings() *v2ray_core_common_serial.TypedMessage {
+func (m *TransportSettings) GetSettings() *v2ray_core_common_serial.TypedMessage {
 	if m != nil {
 		return m.Settings
 	}
@@ -45,8 +71,8 @@ func (m *NetworkSettings) GetSettings() *v2ray_core_common_serial.TypedMessage {
 
 type StreamConfig struct {
 	// Effective network.
-	Network         v2ray_core_common_net.Network `protobuf:"varint,1,opt,name=network,enum=v2ray.core.common.net.Network" json:"network,omitempty"`
-	NetworkSettings []*NetworkSettings            `protobuf:"bytes,2,rep,name=network_settings,json=networkSettings" json:"network_settings,omitempty"`
+	Protocol          TransportProtocol    `protobuf:"varint,1,opt,name=protocol,enum=v2ray.core.transport.internet.TransportProtocol" json:"protocol,omitempty"`
+	TransportSettings []*TransportSettings `protobuf:"bytes,2,rep,name=transport_settings,json=transportSettings" 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" json:"security_type,omitempty"`
 	SecuritySettings []*v2ray_core_common_serial.TypedMessage `protobuf:"bytes,4,rep,name=security_settings,json=securitySettings" json:"security_settings,omitempty"`
@@ -57,16 +83,16 @@ func (m *StreamConfig) String() string            { return proto.CompactTextStri
 func (*StreamConfig) ProtoMessage()               {}
 func (*StreamConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
 
-func (m *StreamConfig) GetNetwork() v2ray_core_common_net.Network {
+func (m *StreamConfig) GetProtocol() TransportProtocol {
 	if m != nil {
-		return m.Network
+		return m.Protocol
 	}
-	return v2ray_core_common_net.Network_Unknown
+	return TransportProtocol_TCP
 }
 
-func (m *StreamConfig) GetNetworkSettings() []*NetworkSettings {
+func (m *StreamConfig) GetTransportSettings() []*TransportSettings {
 	if m != nil {
-		return m.NetworkSettings
+		return m.TransportSettings
 	}
 	return nil
 }
@@ -102,35 +128,38 @@ func (m *ProxyConfig) GetTag() string {
 }
 
 func init() {
-	proto.RegisterType((*NetworkSettings)(nil), "v2ray.core.transport.internet.NetworkSettings")
+	proto.RegisterType((*TransportSettings)(nil), "v2ray.core.transport.internet.TransportSettings")
 	proto.RegisterType((*StreamConfig)(nil), "v2ray.core.transport.internet.StreamConfig")
 	proto.RegisterType((*ProxyConfig)(nil), "v2ray.core.transport.internet.ProxyConfig")
+	proto.RegisterEnum("v2ray.core.transport.internet.TransportProtocol", TransportProtocol_name, TransportProtocol_value)
 }
 
 func init() { proto.RegisterFile("v2ray.com/core/transport/internet/config.proto", fileDescriptor0) }
 
 var fileDescriptor0 = []byte{
-	// 344 bytes of a gzipped FileDescriptorProto
-	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xa4, 0x92, 0xcf, 0x4a, 0xc3, 0x40,
-	0x10, 0xc6, 0x49, 0x2b, 0xda, 0x6e, 0xab, 0xad, 0x39, 0x95, 0x42, 0xb5, 0x56, 0xd0, 0x9c, 0x26,
-	0x12, 0x2f, 0x9e, 0xdb, 0x93, 0x87, 0x8a, 0xa4, 0x45, 0xd0, 0x4b, 0x59, 0xe3, 0x18, 0x82, 0x66,
-	0xb7, 0xec, 0x8e, 0x7f, 0xf2, 0x14, 0x3e, 0x81, 0x2f, 0xe0, 0x53, 0x4a, 0x92, 0xdd, 0x50, 0x4a,
-	0x29, 0x82, 0xb7, 0x21, 0xf9, 0xe6, 0xcb, 0x6f, 0x7e, 0x84, 0xc1, 0x7b, 0xa0, 0x78, 0x06, 0x91,
-	0x4c, 0xfd, 0x48, 0x2a, 0xf4, 0x49, 0x71, 0xa1, 0x97, 0x52, 0x91, 0x9f, 0x08, 0x42, 0x25, 0x90,
-	0xfc, 0x48, 0x8a, 0xe7, 0x24, 0x86, 0xa5, 0x92, 0x24, 0xdd, 0x81, 0xcd, 0x2b, 0x84, 0x2a, 0x0b,
-	0x36, 0xdb, 0x3f, 0x5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, 0x9a, 0x61, 0x3e, 0x8e, 0xa7, 0xec, 0x24, 0x92, 0xe9,
-	0xf6, 0x03, 0x1f, 0x1a, 0x76, 0xfa, 0xa9, 0x0d, 0xee, 0x82, 0x90, 0x67, 0x30, 0xc9, 0x93, 0xf3,
-	0x2a, 0x79, 0x6d, 0xde, 0x3f, 0xee, 0x16, 0x3f, 0xca, 0xe5, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff,
-	0x5e, 0x2e, 0x73, 0x09, 0xd4, 0x02, 0x00, 0x00,
+	// 372 bytes of a gzipped FileDescriptorProto
+	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xac, 0x92, 0x4f, 0x4b, 0xf3, 0x40,
+	0x10, 0xc6, 0xdf, 0x24, 0xe5, 0x35, 0x9d, 0xb6, 0x92, 0xee, 0xa9, 0x08, 0xc5, 0x5a, 0x41, 0x82,
+	0x87, 0x4d, 0x89, 0x77, 0x0f, 0x8d, 0x17, 0xd1, 0x42, 0x48, 0xaa, 0x82, 0x97, 0x90, 0xae, 0x6b,
+	0x08, 0x36, 0xd9, 0xb2, 0x59, 0xc5, 0x7c, 0x20, 0x2f, 0x7e, 0x01, 0xbf, 0x9e, 0xe4, 0xcf, 0x2e,
+	0x45, 0xa1, 0xf4, 0xe0, 0x6d, 0xc8, 0x3c, 0xf3, 0x9b, 0x27, 0xcf, 0x2c, 0xe0, 0x37, 0x97, 0xc7,
+	0x25, 0x26, 0x2c, 0x73, 0x08, 0xe3, 0xd4, 0x11, 0x3c, 0xce, 0x8b, 0x0d, 0xe3, 0xc2, 0x49, 0x73,
+	0x41, 0x79, 0x4e, 0x85, 0x43, 0x58, 0xfe, 0x9c, 0x26, 0x78, 0xc3, 0x99, 0x60, 0x68, 0x2c, 0xf5,
+	0x9c, 0x62, 0xa5, 0xc5, 0x52, 0x7b, 0x34, 0xfb, 0x81, 0x23, 0x2c, 0xcb, 0x58, 0xee, 0x14, 0x94,
+	0x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0x43, 0x26, 0x74, 0x16, 0x37, 0x9e, 0x6f, 0xe9, 0x68, 0x00, 0xdd,
+	0x07, 0xba, 0x0a, 0x19, 0x79, 0xa1, 0xc2, 0x32, 0xe6, 0x0b, 0x38, 0x21, 0x2c, 0xdb, 0x1d, 0xd2,
+	0xa3, 0x29, 0xab, 0x4f, 0x7d, 0x7c, 0xef, 0x06, 0x71, 0x89, 0xbd, 0x4a, 0xa9, 0x16, 0xe3, 0xeb,
+	0xb6, 0xbf, 0xfa, 0x5f, 0x1f, 0xe5, 0xe2, 0x3b, 0x00, 0x00, 0xff, 0xff, 0xca, 0x28, 0x5d, 0x77,
+	0x1b, 0x03, 0x00, 0x00,
 }

+ 12 - 6
transport/internet/config.proto

@@ -5,12 +5,18 @@ option csharp_namespace = "V2Ray.Core.Transport.Internet";
 option go_package = "internet";
 option java_package = "com.v2ray.core.transport.internet";
 
-import "v2ray.com/core/common/net/network.proto";
 import "v2ray.com/core/common/serial/typed_message.proto";
 
-message NetworkSettings {
+enum TransportProtocol {
+  TCP = 0;
+  UDP = 1;
+  MKCP = 2;
+  WebSocket = 3;
+}
+
+message TransportSettings {
   // Type of network that this settings supports.
-  v2ray.core.common.net.Network network = 1;
+  TransportProtocol protocol = 1;
 
   // Specific settings.
   v2ray.core.common.serial.TypedMessage settings = 2;
@@ -18,9 +24,9 @@ message NetworkSettings {
 
 message StreamConfig {
   // Effective network.
-  v2ray.core.common.net.Network network = 1;
+  TransportProtocol protocol = 1;
 
-  repeated NetworkSettings network_settings = 2;
+  repeated TransportSettings transport_settings = 2;
 
   // Type of security. Must be a message name of the settings proto.
   string security_type = 3;
@@ -30,4 +36,4 @@ message StreamConfig {
 
 message ProxyConfig {
   string tag = 1;
-}
+}

+ 9 - 12
transport/internet/dialer.go

@@ -8,10 +8,6 @@ import (
 	v2net "v2ray.com/core/common/net"
 )
 
-var (
-	ErrUnsupportedStreamType = errors.New("Unsupported stream type.")
-)
-
 type DialerOptions struct {
 	Stream *StreamConfig
 	Proxy  *ProxyConfig
@@ -20,16 +16,16 @@ type DialerOptions struct {
 type Dialer func(src v2net.Address, dest v2net.Destination, options DialerOptions) (Connection, error)
 
 var (
-	networkDialerCache = make(map[v2net.Network]Dialer)
+	transportDialerCache = make(map[TransportProtocol]Dialer)
 
 	ProxyDialer Dialer
 )
 
-func RegisterNetworkDialer(network v2net.Network, dialer Dialer) error {
-	if _, found := networkDialerCache[network]; found {
-		return errors.New("Internet|Dialer: ", network, " dialer already registered.")
+func RegisterTransportDialer(protocol TransportProtocol, dialer Dialer) error {
+	if _, found := transportDialerCache[protocol]; found {
+		return errors.New("Internet|Dialer: ", protocol, " dialer already registered.")
 	}
-	networkDialerCache[network] = dialer
+	transportDialerCache[protocol] = dialer
 	return nil
 }
 
@@ -40,14 +36,15 @@ func Dial(src v2net.Address, dest v2net.Destination, options DialerOptions) (Con
 	}
 
 	if dest.Network == v2net.Network_TCP {
-		dialer := networkDialerCache[options.Stream.Network]
+		protocol := options.Stream.GetEffectiveProtocol()
+		dialer := transportDialerCache[protocol]
 		if dialer == nil {
-			return nil, errors.New("Internet|Dialer: ", options.Stream.Network, " dialer not registered.")
+			return nil, errors.New("Internet|Dialer: ", options.Stream.Protocol, " dialer not registered.")
 		}
 		return dialer(src, dest, options)
 	}
 
-	udpDialer := networkDialerCache[v2net.Network_UDP]
+	udpDialer := transportDialerCache[TransportProtocol_UDP]
 	if udpDialer == nil {
 		return nil, errors.New("Internet|Dialer: UDP dialer not registered.")
 	}

+ 3 - 3
transport/internet/kcp/config.go

@@ -3,7 +3,7 @@ package kcp
 import (
 	"crypto/cipher"
 
-	v2net "v2ray.com/core/common/net"
+	"v2ray.com/core/common"
 	"v2ray.com/core/transport/internet"
 )
 
@@ -104,7 +104,7 @@ func (v *Config) IsConnectionReuse() bool {
 }
 
 func init() {
-	internet.RegisterNetworkConfigCreator(v2net.Network_KCP, func() interface{} {
+	common.Must(internet.RegisterProtocolConfigCreator(internet.TransportProtocol_MKCP, func() interface{} {
 		return new(Config)
-	})
+	}))
 }

+ 2 - 2
transport/internet/kcp/dialer.go

@@ -129,7 +129,7 @@ func DialKCP(src v2net.Address, dest v2net.Destination, options internet.DialerO
 		conn = c
 	}
 
-	networkSettings, err := options.Stream.GetEffectiveNetworkSettings()
+	networkSettings, err := options.Stream.GetEffectiveTransportSettings()
 	if err != nil {
 		log.Error("KCP|Dialer: Failed to get KCP settings: ", err)
 		return nil, err
@@ -173,5 +173,5 @@ func DialKCP(src v2net.Address, dest v2net.Destination, options internet.DialerO
 }
 
 func init() {
-	common.Must(internet.RegisterNetworkDialer(v2net.Network_KCP, DialKCP))
+	common.Must(internet.RegisterTransportDialer(internet.TransportProtocol_MKCP, DialKCP))
 }

+ 6 - 6
transport/internet/kcp/kcp_test.go

@@ -20,10 +20,10 @@ func TestDialAndListen(t *testing.T) {
 
 	listerner, err := NewListener(v2net.LocalHostIP, v2net.Port(0), internet.ListenOptions{
 		Stream: &internet.StreamConfig{
-			Network: v2net.Network_KCP,
-			NetworkSettings: []*internet.NetworkSettings{
+			Protocol: internet.TransportProtocol_MKCP,
+			TransportSettings: []*internet.TransportSettings{
 				{
-					Network:  v2net.Network_KCP,
+					Protocol: internet.TransportProtocol_MKCP,
 					Settings: serial.ToTypedMessage(&Config{}),
 				},
 			},
@@ -59,10 +59,10 @@ func TestDialAndListen(t *testing.T) {
 	for i := 0; i < 10; i++ {
 		clientConn, err := DialKCP(v2net.LocalHostIP, v2net.UDPDestination(v2net.LocalHostIP, port), internet.DialerOptions{
 			Stream: &internet.StreamConfig{
-				Network: v2net.Network_KCP,
-				NetworkSettings: []*internet.NetworkSettings{
+				Protocol: internet.TransportProtocol_MKCP,
+				TransportSettings: []*internet.TransportSettings{
 					{
-						Network:  v2net.Network_KCP,
+						Protocol: internet.TransportProtocol_MKCP,
 						Settings: serial.ToTypedMessage(&Config{}),
 					},
 				},

+ 2 - 2
transport/internet/kcp/listener.go

@@ -93,7 +93,7 @@ type Listener struct {
 }
 
 func NewListener(address v2net.Address, port v2net.Port, options internet.ListenOptions) (*Listener, error) {
-	networkSettings, err := options.Stream.GetEffectiveNetworkSettings()
+	networkSettings, err := options.Stream.GetEffectiveTransportSettings()
 	if err != nil {
 		log.Error("KCP|Listener: Failed to get KCP settings: ", err)
 		return nil, err
@@ -298,5 +298,5 @@ func ListenKCP(address v2net.Address, port v2net.Port, options internet.ListenOp
 }
 
 func init() {
-	common.Must(internet.RegisterNetworkListener(v2net.Network_KCP, ListenKCP))
+	common.Must(internet.RegisterTransportListener(internet.TransportProtocol_MKCP, ListenKCP))
 }

+ 3 - 3
transport/internet/tcp/config.go

@@ -1,7 +1,7 @@
 package tcp
 
 import (
-	v2net "v2ray.com/core/common/net"
+	"v2ray.com/core/common"
 	"v2ray.com/core/transport/internet"
 )
 
@@ -13,7 +13,7 @@ func (v *Config) IsConnectionReuse() bool {
 }
 
 func init() {
-	internet.RegisterNetworkConfigCreator(v2net.Network_TCP, func() interface{} {
+	common.Must(internet.RegisterProtocolConfigCreator(internet.TransportProtocol_TCP, func() interface{} {
 		return new(Config)
-	})
+	}))
 }

+ 2 - 2
transport/internet/tcp/dialer.go

@@ -22,7 +22,7 @@ func Dial(src v2net.Address, dest v2net.Destination, options internet.DialerOpti
 	if src == nil {
 		src = v2net.AnyIP
 	}
-	networkSettings, err := options.Stream.GetEffectiveNetworkSettings()
+	networkSettings, err := options.Stream.GetEffectiveTransportSettings()
 	if err != nil {
 		return nil, err
 	}
@@ -70,5 +70,5 @@ func Dial(src v2net.Address, dest v2net.Destination, options internet.DialerOpti
 }
 
 func init() {
-	common.Must(internet.RegisterNetworkDialer(v2net.Network_TCP, Dial))
+	common.Must(internet.RegisterTransportDialer(internet.TransportProtocol_TCP, Dial))
 }

+ 2 - 2
transport/internet/tcp/hub.go

@@ -42,7 +42,7 @@ func ListenTCP(address v2net.Address, port v2net.Port, options internet.ListenOp
 	if err != nil {
 		return nil, err
 	}
-	networkSettings, err := options.Stream.GetEffectiveNetworkSettings()
+	networkSettings, err := options.Stream.GetEffectiveTransportSettings()
 	if err != nil {
 		return nil, err
 	}
@@ -159,5 +159,5 @@ func (v *TCPListener) Close() error {
 }
 
 func init() {
-	common.Must(internet.RegisterNetworkListener(v2net.Network_TCP, ListenTCP))
+	common.Must(internet.RegisterTransportListener(internet.TransportProtocol_TCP, ListenTCP))
 }

+ 9 - 10
transport/internet/tcp_hub.go

@@ -11,16 +11,14 @@ import (
 )
 
 var (
-	ErrClosedConnection = errors.New("Connection already closed.")
-
-	networkListenerCache = make(map[v2net.Network]ListenFunc)
+	transportListenerCache = make(map[TransportProtocol]ListenFunc)
 )
 
-func RegisterNetworkListener(network v2net.Network, listener ListenFunc) error {
-	if _, found := networkListenerCache[network]; found {
-		return errors.New("Internet|TCPHub: ", network, " listener already registered.")
+func RegisterTransportListener(protocol TransportProtocol, listener ListenFunc) error {
+	if _, found := transportListenerCache[protocol]; found {
+		return errors.New("Internet|TCPHub: ", protocol, " listener already registered.")
 	}
-	networkListenerCache[network] = listener
+	transportListenerCache[protocol] = listener
 	return nil
 }
 
@@ -46,13 +44,14 @@ func ListenTCP(address v2net.Address, port v2net.Port, callback ConnectionHandle
 	options := ListenOptions{
 		Stream: settings,
 	}
-	listenFunc := networkListenerCache[settings.Network]
+	protocol := settings.GetEffectiveProtocol()
+	listenFunc := transportListenerCache[protocol]
 	if listenFunc == nil {
-		return nil, errors.New("Internet|TCPHub: ", settings.Network, " listener not registered.")
+		return nil, errors.New("Internet|TCPHub: ", protocol, " listener not registered.")
 	}
 	listener, err := listenFunc(address, port, options)
 	if err != nil {
-		return nil, errors.Base(err).Message("Interent|TCPHub: Failed to listen: ")
+		return nil, errors.Base(err).Message("Interent|TCPHub: Failed to listen on address: ", address, ":", port)
 	}
 
 	hub := &TCPHub{

+ 1 - 1
transport/internet/udp/dialer.go

@@ -8,7 +8,7 @@ import (
 )
 
 func init() {
-	common.Must(internet.RegisterNetworkDialer(v2net.Network_UDP,
+	common.Must(internet.RegisterTransportDialer(internet.TransportProtocol_UDP,
 		func(src v2net.Address, dest v2net.Destination, options internet.DialerOptions) (internet.Connection, error) {
 			conn, err := internet.DialSystem(src, dest)
 			if err != nil {

+ 3 - 3
transport/internet/websocket/config.go

@@ -1,7 +1,7 @@
 package websocket
 
 import (
-	v2net "v2ray.com/core/common/net"
+	"v2ray.com/core/common"
 	"v2ray.com/core/transport/internet"
 )
 
@@ -13,7 +13,7 @@ func (c *Config) IsConnectionReuse() bool {
 }
 
 func init() {
-	internet.RegisterNetworkConfigCreator(v2net.Network_WebSocket, func() interface{} {
+	common.Must(internet.RegisterProtocolConfigCreator(internet.TransportProtocol_WebSocket, func() interface{} {
 		return new(Config)
-	})
+	}))
 }

+ 3 - 3
transport/internet/websocket/dialer.go

@@ -22,7 +22,7 @@ func Dial(src v2net.Address, dest v2net.Destination, options internet.DialerOpti
 	if src == nil {
 		src = v2net.AnyIP
 	}
-	networkSettings, err := options.Stream.GetEffectiveNetworkSettings()
+	networkSettings, err := options.Stream.GetEffectiveTransportSettings()
 	if err != nil {
 		return nil, err
 	}
@@ -48,11 +48,11 @@ func Dial(src v2net.Address, dest v2net.Destination, options internet.DialerOpti
 }
 
 func init() {
-	common.Must(internet.RegisterNetworkDialer(v2net.Network_WebSocket, Dial))
+	common.Must(internet.RegisterTransportDialer(internet.TransportProtocol_WebSocket, Dial))
 }
 
 func wsDial(src v2net.Address, dest v2net.Destination, options internet.DialerOptions) (*wsconn, error) {
-	networkSettings, err := options.Stream.GetEffectiveNetworkSettings()
+	networkSettings, err := options.Stream.GetEffectiveTransportSettings()
 	if err != nil {
 		return nil, err
 	}

+ 2 - 2
transport/internet/websocket/hub.go

@@ -38,7 +38,7 @@ type WSListener struct {
 }
 
 func ListenWS(address v2net.Address, port v2net.Port, options internet.ListenOptions) (internet.Listener, error) {
-	networkSettings, err := options.Stream.GetEffectiveNetworkSettings()
+	networkSettings, err := options.Stream.GetEffectiveTransportSettings()
 	if err != nil {
 		return nil, err
 	}
@@ -199,5 +199,5 @@ func (v *WSListener) Close() error {
 }
 
 func init() {
-	common.Must(internet.RegisterNetworkListener(v2net.Network_WebSocket, ListenWS))
+	common.Must(internet.RegisterTransportListener(internet.TransportProtocol_WebSocket, ListenWS))
 }

+ 18 - 18
transport/internet/websocket/ws_test.go

@@ -21,10 +21,10 @@ func Test_listenWSAndDial(t *testing.T) {
 	assert := assert.On(t)
 	listen, err := ListenWS(v2net.DomainAddress("localhost"), 13146, internet.ListenOptions{
 		Stream: &internet.StreamConfig{
-			Network: v2net.Network_WebSocket,
-			NetworkSettings: []*internet.NetworkSettings{
+			Protocol: internet.TransportProtocol_WebSocket,
+			TransportSettings: []*internet.TransportSettings{
 				{
-					Network: v2net.Network_WebSocket,
+					Protocol: internet.TransportProtocol_WebSocket,
 					Settings: serial.ToTypedMessage(&Config{
 						Path: "ws",
 					}),
@@ -58,10 +58,10 @@ func Test_listenWSAndDial(t *testing.T) {
 	}()
 	conn, err := Dial(v2net.AnyIP, v2net.TCPDestination(v2net.DomainAddress("localhost"), 13146), internet.DialerOptions{
 		Stream: &internet.StreamConfig{
-			Network: v2net.Network_WebSocket,
-			NetworkSettings: []*internet.NetworkSettings{
+			Protocol: internet.TransportProtocol_WebSocket,
+			TransportSettings: []*internet.TransportSettings{
 				{
-					Network: v2net.Network_WebSocket,
+					Protocol: internet.TransportProtocol_WebSocket,
 					Settings: serial.ToTypedMessage(&Config{
 						Path: "ws",
 					}),
@@ -82,10 +82,10 @@ func Test_listenWSAndDial(t *testing.T) {
 	<-time.After(time.Second * 5)
 	conn, err = Dial(v2net.AnyIP, v2net.TCPDestination(v2net.DomainAddress("localhost"), 13146), internet.DialerOptions{
 		Stream: &internet.StreamConfig{
-			Network: v2net.Network_WebSocket,
-			NetworkSettings: []*internet.NetworkSettings{
+			Protocol: internet.TransportProtocol_WebSocket,
+			TransportSettings: []*internet.TransportSettings{
 				{
-					Network: v2net.Network_WebSocket,
+					Protocol: internet.TransportProtocol_WebSocket,
 					Settings: serial.ToTypedMessage(&Config{
 						Path: "ws",
 					}),
@@ -103,10 +103,10 @@ func Test_listenWSAndDial(t *testing.T) {
 	<-time.After(time.Second * 15)
 	conn, err = Dial(v2net.AnyIP, v2net.TCPDestination(v2net.DomainAddress("localhost"), 13146), internet.DialerOptions{
 		Stream: &internet.StreamConfig{
-			Network: v2net.Network_WebSocket,
-			NetworkSettings: []*internet.NetworkSettings{
+			Protocol: internet.TransportProtocol_WebSocket,
+			TransportSettings: []*internet.TransportSettings{
 				{
-					Network: v2net.Network_WebSocket,
+					Protocol: internet.TransportProtocol_WebSocket,
 					Settings: serial.ToTypedMessage(&Config{
 						Path: "ws",
 					}),
@@ -145,10 +145,10 @@ func Test_listenWSAndDial_TLS(t *testing.T) {
 		Stream: &internet.StreamConfig{
 			SecurityType:     serial.GetMessageType(new(v2tls.Config)),
 			SecuritySettings: []*serial.TypedMessage{serial.ToTypedMessage(tlsSettings)},
-			Network:          v2net.Network_WebSocket,
-			NetworkSettings: []*internet.NetworkSettings{
+			Protocol:         internet.TransportProtocol_WebSocket,
+			TransportSettings: []*internet.TransportSettings{
 				{
-					Network: v2net.Network_WebSocket,
+					Protocol: internet.TransportProtocol_WebSocket,
 					Settings: serial.ToTypedMessage(&Config{
 						Path: "wss",
 						ConnectionReuse: &ConnectionReuse{
@@ -170,10 +170,10 @@ func Test_listenWSAndDial_TLS(t *testing.T) {
 		Stream: &internet.StreamConfig{
 			SecurityType:     serial.GetMessageType(new(v2tls.Config)),
 			SecuritySettings: []*serial.TypedMessage{serial.ToTypedMessage(tlsSettings)},
-			Network:          v2net.Network_WebSocket,
-			NetworkSettings: []*internet.NetworkSettings{
+			Protocol:         internet.TransportProtocol_WebSocket,
+			TransportSettings: []*internet.TransportSettings{
 				{
-					Network: v2net.Network_WebSocket,
+					Protocol: internet.TransportProtocol_WebSocket,
 					Settings: serial.ToTypedMessage(&Config{
 						Path: "wss",
 						ConnectionReuse: &ConnectionReuse{