mirror of
https://github.com/v2ray/v2ray-core.git
synced 2026-11-19 23:03:08 +00:00
Move point to shell
This commit is contained in:
1 parent
cc61e88eca
commit
07582c5b60
21 files changed
+22
-22
No files matched your search
@@ -0,0 +1,56 @@
|
||||
package point
|
||||
|
||||
import (
|
||||
"github.com/v2ray/v2ray-core/common/log"
|
||||
"github.com/v2ray/v2ray-core/common/retry"
|
||||
"github.com/v2ray/v2ray-core/proxy/common/connhandler"
|
||||
"github.com/v2ray/v2ray-core/shell/point/config"
|
||||
)
|
||||
|
||||
type InboundConnectionHandlerWithPort struct {
|
||||
port uint16
|
||||
handler connhandler.InboundConnectionHandler
|
||||
}
|
||||
|
||||
type InboundDetourHandler struct {
|
||||
point *Point
|
||||
config config.InboundDetourConfig
|
||||
ich []*InboundConnectionHandlerWithPort
|
||||
}
|
||||
|
||||
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 config.BadConfiguration
|
||||
}
|
||||
|
||||
ports := this.config.PortRange()
|
||||
this.ich = make([]*InboundConnectionHandlerWithPort, 0, ports.From()-ports.To()+1)
|
||||
for i := ports.From(); i <= ports.To(); i++ {
|
||||
ichConfig := this.config.Settings()
|
||||
ich, err := ichFactory.Create(this.point, ichConfig)
|
||||
if err != nil {
|
||||
log.Error("Failed to create inbound connection handler: %v", err)
|
||||
return err
|
||||
}
|
||||
this.ich = append(this.ich, &InboundConnectionHandlerWithPort{
|
||||
port: i,
|
||||
handler: ich,
|
||||
})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *InboundDetourHandler) Start() error {
|
||||
for _, ich := range this.ich {
|
||||
return retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
|
||||
err := ich.handler.Listen(ich.port)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user