mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-06-20 01:39:55 -04:00
testing with mock
This commit is contained in:
@@ -19,6 +19,16 @@ import (
|
||||
"v2ray.com/core/transport/pipe"
|
||||
)
|
||||
|
||||
func init() {
|
||||
common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
|
||||
d := new(DokodemoDoor)
|
||||
err := core.RequireFeatures(ctx, func(pm policy.Manager) error {
|
||||
return d.Init(config.(*Config), pm)
|
||||
})
|
||||
return d, err
|
||||
}))
|
||||
}
|
||||
|
||||
type DokodemoDoor struct {
|
||||
policyManager policy.Manager
|
||||
config *Config
|
||||
@@ -26,19 +36,17 @@ type DokodemoDoor struct {
|
||||
port net.Port
|
||||
}
|
||||
|
||||
func New(ctx context.Context, config *Config) (*DokodemoDoor, error) {
|
||||
// Init initializes the DokodemoDoor instance with necessary parameters.
|
||||
func (d *DokodemoDoor) Init(config *Config, pm policy.Manager) error {
|
||||
if config.NetworkList == nil || config.NetworkList.Size() == 0 {
|
||||
return nil, newError("no network specified")
|
||||
}
|
||||
v := core.MustFromContext(ctx)
|
||||
d := &DokodemoDoor{
|
||||
config: config,
|
||||
address: config.GetPredefinedAddress(),
|
||||
port: net.Port(config.Port),
|
||||
policyManager: v.GetFeature(policy.ManagerType()).(policy.Manager),
|
||||
return newError("no network specified")
|
||||
}
|
||||
d.config = config
|
||||
d.address = config.GetPredefinedAddress()
|
||||
d.port = net.Port(config.Port)
|
||||
d.policyManager = pm
|
||||
|
||||
return d, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *DokodemoDoor) Network() net.NetworkList {
|
||||
@@ -144,9 +152,3 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
|
||||
return New(ctx, config.(*Config))
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -22,6 +22,18 @@ import (
|
||||
"v2ray.com/core/transport/internet"
|
||||
)
|
||||
|
||||
func init() {
|
||||
common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
|
||||
h := new(Handler)
|
||||
if err := core.RequireFeatures(ctx, func(pm policy.Manager, d dns.Client) error {
|
||||
return h.Init(config.(*Config), pm, d)
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return h, nil
|
||||
}))
|
||||
}
|
||||
|
||||
// Handler handles Freedom connections.
|
||||
type Handler struct {
|
||||
policyManager policy.Manager
|
||||
@@ -29,18 +41,13 @@ type Handler struct {
|
||||
config Config
|
||||
}
|
||||
|
||||
// New creates a new Freedom handler.
|
||||
func New(ctx context.Context, config *Config) (*Handler, error) {
|
||||
f := &Handler{
|
||||
config: *config,
|
||||
}
|
||||
// Init initializes the Handler with necessary parameters.
|
||||
func (h *Handler) Init(config *Config, pm policy.Manager, d dns.Client) error {
|
||||
h.config = *config
|
||||
h.policyManager = pm
|
||||
h.dns = d
|
||||
|
||||
core.RequireFeatures(ctx, func(pm policy.Manager, d dns.Client) {
|
||||
f.policyManager = pm
|
||||
f.dns = d
|
||||
})
|
||||
|
||||
return f, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *Handler) policy() policy.Session {
|
||||
@@ -163,9 +170,3 @@ func (h *Handler) Process(ctx context.Context, link *vio.Link, dialer proxy.Dial
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
|
||||
return New(ctx, config.(*Config))
|
||||
}))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user