mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-04-26 07:29:09 -04:00
separate network and transport protocol
This commit is contained in:
@@ -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,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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user