1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 09:36:34 -05:00

refactor code

This commit is contained in:
V2Ray 2015-11-27 12:29:20 +01:00
parent 916403dd46
commit a8d07ce931
2 changed files with 13 additions and 13 deletions

View File

@ -101,25 +101,25 @@ func NewPoint(pConfig config.PointConfig) (*Point, error) {
// 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.
func (vp *Point) Start() error {
if vp.port <= 0 {
log.Error("Invalid port %d", vp.port)
func (this *Point) Start() error {
if this.port <= 0 {
log.Error("Invalid port %d", this.port)
return config.BadConfiguration
}
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 {
return err
}
log.Warning("Point server started on port %d", vp.port)
log.Warning("Point server started on port %d", this.port)
return nil
})
if err != nil {
return err
}
for _, detourHandler := range vp.idh {
for _, detourHandler := range this.idh {
err := detourHandler.Start()
if err != nil {
return err
@ -129,14 +129,14 @@ func (vp *Point) Start() error {
return nil
}
func (p *Point) DispatchToOutbound(packet v2net.Packet) ray.InboundRay {
func (this *Point) DispatchToOutbound(packet v2net.Packet) ray.InboundRay {
direct := ray.NewRay()
dest := packet.Destination()
if p.router != nil {
tag, err := p.router.TakeDetour(dest)
if this.router != nil {
tag, err := this.router.TakeDetour(dest)
if err == nil {
handler, found := p.odh[tag]
handler, found := this.odh[tag]
if found {
go handler.Dispatch(packet, 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
}

View File

@ -16,7 +16,7 @@ func NewBlackHole() *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 {
chunk.Release()
}
@ -31,7 +31,7 @@ func (bh *BlackHole) Dispatch(firstPacket v2net.Packet, ray ray.OutboundRay) err
type BlackHoleFactory struct {
}
func (factory BlackHoleFactory) Create(config interface{}) (connhandler.OutboundConnectionHandler, error) {
func (this BlackHoleFactory) Create(config interface{}) (connhandler.OutboundConnectionHandler, error) {
return NewBlackHole(), nil
}