mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-11-16 09:26:21 -05:00
remove use of InboundConnectionHandlerWithPort in InboundDetourHandlerDynamic
This commit is contained in:
parent
9ae258de3d
commit
8fd9d51fba
@ -18,8 +18,8 @@ type InboundDetourHandlerDynamic struct {
|
|||||||
space app.Space
|
space app.Space
|
||||||
config *InboundDetourConfig
|
config *InboundDetourConfig
|
||||||
portsInUse map[v2net.Port]bool
|
portsInUse map[v2net.Port]bool
|
||||||
ichInUse []*InboundConnectionHandlerWithPort
|
ichInUse []proxy.InboundHandler
|
||||||
ich2Recycle []*InboundConnectionHandlerWithPort
|
ich2Recycle []proxy.InboundHandler
|
||||||
lastRefresh time.Time
|
lastRefresh time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,18 +30,14 @@ func NewInboundDetourHandlerDynamic(space app.Space, config *InboundDetourConfig
|
|||||||
portsInUse: make(map[v2net.Port]bool),
|
portsInUse: make(map[v2net.Port]bool),
|
||||||
}
|
}
|
||||||
ichCount := config.Allocation.Concurrency
|
ichCount := config.Allocation.Concurrency
|
||||||
ichArray := make([]*InboundConnectionHandlerWithPort, ichCount*2)
|
ichArray := make([]proxy.InboundHandler, ichCount*2)
|
||||||
for idx, _ := range ichArray {
|
for idx, _ := range ichArray {
|
||||||
//port := handler.pickUnusedPort()
|
|
||||||
ich, err := proxyrepo.CreateInboundHandler(config.Protocol, space, config.Settings)
|
ich, err := proxyrepo.CreateInboundHandler(config.Protocol, space, config.Settings)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Point: Failed to create inbound connection handler: ", err)
|
log.Error("Point: Failed to create inbound connection handler: ", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
ichArray[idx] = &InboundConnectionHandlerWithPort{
|
ichArray[idx] = ich
|
||||||
port: 0,
|
|
||||||
handler: ich,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
handler.ichInUse = ichArray[:ichCount]
|
handler.ichInUse = ichArray[:ichCount]
|
||||||
handler.ich2Recycle = ichArray[ichCount:]
|
handler.ich2Recycle = ichArray[ichCount:]
|
||||||
@ -69,19 +65,19 @@ func (this *InboundDetourHandlerDynamic) GetConnectionHandler() (proxy.InboundHa
|
|||||||
if until < 0 {
|
if until < 0 {
|
||||||
until = 0
|
until = 0
|
||||||
}
|
}
|
||||||
return ich.handler, int(until)
|
return ich, int(until)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *InboundDetourHandlerDynamic) Close() {
|
func (this *InboundDetourHandlerDynamic) Close() {
|
||||||
this.Lock()
|
this.Lock()
|
||||||
defer this.Unlock()
|
defer this.Unlock()
|
||||||
for _, ich := range this.ichInUse {
|
for _, ich := range this.ichInUse {
|
||||||
ich.handler.Close()
|
ich.Close()
|
||||||
}
|
}
|
||||||
if this.ich2Recycle != nil {
|
if this.ich2Recycle != nil {
|
||||||
for _, ich := range this.ich2Recycle {
|
for _, ich := range this.ich2Recycle {
|
||||||
if ich != nil && ich.handler != nil {
|
if ich != nil {
|
||||||
ich.handler.Close()
|
ich.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,13 +91,13 @@ func (this *InboundDetourHandlerDynamic) refresh() error {
|
|||||||
|
|
||||||
this.ich2Recycle, this.ichInUse = this.ichInUse, this.ich2Recycle
|
this.ich2Recycle, this.ichInUse = this.ichInUse, this.ich2Recycle
|
||||||
for _, ich := range this.ichInUse {
|
for _, ich := range this.ichInUse {
|
||||||
delete(this.portsInUse, ich.port)
|
delete(this.portsInUse, ich.Port())
|
||||||
ich.handler.Close()
|
ich.Close()
|
||||||
ich.port = this.pickUnusedPort()
|
port := this.pickUnusedPort()
|
||||||
err := retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
|
err := retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
|
||||||
err := ich.handler.Listen(ich.port)
|
err := ich.Listen(port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Point: Failed to start inbound detour on port ", ich.port, ": ", err)
|
log.Error("Point: Failed to start inbound detour on port ", port, ": ", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user