1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-09-25 11:44:02 -04:00

leverage global object creator in proxies.

This commit is contained in:
Darien Raymond
2017-01-13 00:56:21 +01:00
parent db1c9131f0
commit 148e4832eb
23 changed files with 353 additions and 269 deletions

View File

@@ -1,6 +1,7 @@
package dokodemo
import (
"context"
"sync"
"v2ray.com/core/app"
@@ -10,7 +11,6 @@ import (
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/common/serial"
"v2ray.com/core/common/signal"
"v2ray.com/core/proxy"
"v2ray.com/core/transport/internet"
@@ -31,7 +31,15 @@ type DokodemoDoor struct {
meta *proxy.InboundHandlerMeta
}
func NewDokodemoDoor(config *Config, space app.Space, meta *proxy.InboundHandlerMeta) *DokodemoDoor {
func NewDokodemoDoor(ctx context.Context, config *Config) (*DokodemoDoor, error) {
space := app.SpaceFromContext(ctx)
if space == nil {
return nil, errors.New("Dokodemo: No space in context.")
}
meta := proxy.InboundMetaFromContext(ctx)
if meta == nil {
return nil, errors.New("Dokodemo: No outbound meta in context.")
}
d := &DokodemoDoor{
config: config,
address: config.GetPredefinedAddress(),
@@ -45,7 +53,7 @@ func NewDokodemoDoor(config *Config, space app.Space, meta *proxy.InboundHandler
}
return nil
})
return d
return d, nil
}
func (v *DokodemoDoor) Port() v2net.Port {
@@ -205,12 +213,8 @@ func (v *DokodemoDoor) HandleTCPConnection(conn internet.Connection) {
}
}
type Factory struct{}
func (v *Factory) Create(space app.Space, rawConfig interface{}, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error) {
return NewDokodemoDoor(rawConfig.(*Config), space, meta), nil
}
func init() {
common.Must(proxy.RegisterInboundHandlerCreator(serial.GetMessageType(new(Config)), new(Factory)))
common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
return NewDokodemoDoor(ctx, config.(*Config))
}))
}