interface for inbound connection handler manager

This commit is contained in:
v2ray committed 2016-01-01 23:44:11 +01:00
1 parent 6344369eb4
commit 3baa1f5bc5
24 files changed
+269 -167

No files matched your search

+2 -7
View File
@@ -5,6 +5,7 @@ import (
"github.com/v2ray/v2ray-core/common/log"
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/common/retry"
"github.com/v2ray/v2ray-core/proxy"
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
)
@@ -21,17 +22,11 @@ type InboundDetourHandler struct {
}
func (this *InboundDetourHandler) Initialize() error {
ichFactory := connhandler.GetInboundConnectionHandlerFactory(this.config.Protocol())
if ichFactory == nil {
log.Error("Unknown inbound connection handler factory %s", this.config.Protocol())
return BadConfiguration
}
ports := this.config.PortRange()
this.ich = make([]*InboundConnectionHandlerWithPort, 0, ports.To()-ports.From()+1)
for i := ports.From(); i <= ports.To(); i++ {
ichConfig := this.config.Settings()
ich, err := ichFactory.Create(this.space, ichConfig)
ich, err := proxy.CreateInboundConnectionHandler(this.config.Protocol(), this.space, ichConfig)
if err != nil {
log.Error("Failed to create inbound connection handler: %v", err)
return err
+4 -18
View File
@@ -11,6 +11,7 @@ import (
"github.com/v2ray/v2ray-core/common/log"
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/common/retry"
"github.com/v2ray/v2ray-core/proxy"
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
"github.com/v2ray/v2ray-core/transport/ray"
)
@@ -54,26 +55,16 @@ func NewPoint(pConfig PointConfig) (*Point, error) {
vpoint.space = controller.New()
vpoint.space.Bind(vpoint)
ichFactory := connhandler.GetInboundConnectionHandlerFactory(pConfig.InboundConfig().Protocol())
if ichFactory == nil {
log.Error("Unknown inbound connection handler factory %s", pConfig.InboundConfig().Protocol())
return nil, BadConfiguration
}
ichConfig := pConfig.InboundConfig().Settings()
ich, err := ichFactory.Create(vpoint.space.ForContext("vpoint-default-inbound"), ichConfig)
ich, err := proxy.CreateInboundConnectionHandler(pConfig.InboundConfig().Protocol(), vpoint.space.ForContext("vpoint-default-inbound"), ichConfig)
if err != nil {
log.Error("Failed to create inbound connection handler: %v", err)
return nil, err
}
vpoint.ich = ich
ochFactory := connhandler.GetOutboundConnectionHandlerFactory(pConfig.OutboundConfig().Protocol())
if ochFactory == nil {
log.Error("Unknown outbound connection handler factory %s", pConfig.OutboundConfig().Protocol())
return nil, BadConfiguration
}
ochConfig := pConfig.OutboundConfig().Settings()
och, err := ochFactory.Create(vpoint.space.ForContext("vpoint-default-outbound"), ochConfig)
och, err := proxy.CreateOutboundConnectionHandler(pConfig.OutboundConfig().Protocol(), vpoint.space.ForContext("vpoint-default-outbound"), ochConfig)
if err != nil {
log.Error("Failed to create outbound connection handler: %v", err)
return nil, err
@@ -100,12 +91,7 @@ func NewPoint(pConfig PointConfig) (*Point, error) {
if len(outboundDetours) > 0 {
vpoint.odh = make(map[string]connhandler.OutboundConnectionHandler)
for _, detourConfig := range outboundDetours {
detourFactory := connhandler.GetOutboundConnectionHandlerFactory(detourConfig.Protocol())
if detourFactory == nil {
log.Error("Unknown detour outbound connection handler factory %s", detourConfig.Protocol())
return nil, BadConfiguration
}
detourHandler, err := detourFactory.Create(vpoint.space.ForContext(detourConfig.Tag()), detourConfig.Settings())
detourHandler, err := proxy.CreateOutboundConnectionHandler(detourConfig.Protocol(), vpoint.space.ForContext(detourConfig.Tag()), detourConfig.Settings())
if err != nil {
log.Error("Failed to create detour outbound connection handler: %v", err)
return nil, err