mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 01:57:12 -05:00
refactor code
This commit is contained in:
parent
916403dd46
commit
a8d07ce931
@ -101,25 +101,25 @@ func NewPoint(pConfig config.PointConfig) (*Point, error) {
|
|||||||
|
|
||||||
// Start starts the Point server, and return any error during the process.
|
// Start starts the Point server, and return any error during the process.
|
||||||
// In the case of any errors, the state of the server is unpredicatable.
|
// In the case of any errors, the state of the server is unpredicatable.
|
||||||
func (vp *Point) Start() error {
|
func (this *Point) Start() error {
|
||||||
if vp.port <= 0 {
|
if this.port <= 0 {
|
||||||
log.Error("Invalid port %d", vp.port)
|
log.Error("Invalid port %d", this.port)
|
||||||
return config.BadConfiguration
|
return config.BadConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
err := retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
|
err := retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
|
||||||
err := vp.ich.Listen(vp.port)
|
err := this.ich.Listen(this.port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Warning("Point server started on port %d", vp.port)
|
log.Warning("Point server started on port %d", this.port)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, detourHandler := range vp.idh {
|
for _, detourHandler := range this.idh {
|
||||||
err := detourHandler.Start()
|
err := detourHandler.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -129,14 +129,14 @@ func (vp *Point) Start() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Point) DispatchToOutbound(packet v2net.Packet) ray.InboundRay {
|
func (this *Point) DispatchToOutbound(packet v2net.Packet) ray.InboundRay {
|
||||||
direct := ray.NewRay()
|
direct := ray.NewRay()
|
||||||
dest := packet.Destination()
|
dest := packet.Destination()
|
||||||
|
|
||||||
if p.router != nil {
|
if this.router != nil {
|
||||||
tag, err := p.router.TakeDetour(dest)
|
tag, err := this.router.TakeDetour(dest)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
handler, found := p.odh[tag]
|
handler, found := this.odh[tag]
|
||||||
if found {
|
if found {
|
||||||
go handler.Dispatch(packet, direct)
|
go handler.Dispatch(packet, direct)
|
||||||
return direct
|
return direct
|
||||||
@ -144,6 +144,6 @@ func (p *Point) DispatchToOutbound(packet v2net.Packet) ray.InboundRay {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
go p.och.Dispatch(packet, direct)
|
go this.och.Dispatch(packet, direct)
|
||||||
return direct
|
return direct
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ func NewBlackHole() *BlackHole {
|
|||||||
return &BlackHole{}
|
return &BlackHole{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bh *BlackHole) Dispatch(firstPacket v2net.Packet, ray ray.OutboundRay) error {
|
func (this *BlackHole) Dispatch(firstPacket v2net.Packet, ray ray.OutboundRay) error {
|
||||||
if chunk := firstPacket.Chunk(); chunk != nil {
|
if chunk := firstPacket.Chunk(); chunk != nil {
|
||||||
chunk.Release()
|
chunk.Release()
|
||||||
}
|
}
|
||||||
@ -31,7 +31,7 @@ func (bh *BlackHole) Dispatch(firstPacket v2net.Packet, ray ray.OutboundRay) err
|
|||||||
type BlackHoleFactory struct {
|
type BlackHoleFactory struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (factory BlackHoleFactory) Create(config interface{}) (connhandler.OutboundConnectionHandler, error) {
|
func (this BlackHoleFactory) Create(config interface{}) (connhandler.OutboundConnectionHandler, error) {
|
||||||
return NewBlackHole(), nil
|
return NewBlackHole(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user