fix: cannot start tun

This commit is contained in:
AkinoKaede 2023-05-28 20:21:46 +08:00 committed by Shelikhoo
parent c6c1cdbb4f
commit 2617a4c332
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316
1 changed files with 11 additions and 12 deletions

View File

@ -57,22 +57,21 @@ func (t *TUN) Close() error {
return nil
}
func NewTUN(ctx context.Context, config *Config, dispatcher routing.Dispatcher) *TUN {
v := core.MustFromContext(ctx)
return &TUN{
ctx: ctx,
dispatcher: dispatcher,
config: config,
policyManager: v.GetFeature(policy.ManagerType()).(policy.Manager),
}
func (t *TUN) Init(ctx context.Context, config *Config, dispatcher routing.Dispatcher, policyManager policy.Manager) error {
t.ctx = ctx
t.config = config
t.dispatcher = dispatcher
t.policyManager = policyManager
return nil
}
func init() {
common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
tun := core.RequireFeatures(ctx, func(d routing.Dispatcher) *TUN {
return NewTUN(ctx, config.(*Config), d)
tun := new(TUN)
err := core.RequireFeatures(ctx, func(d routing.Dispatcher, p policy.Manager) error {
return tun.Init(ctx, config.(*Config), d, p)
})
return tun, nil
return tun, err
}))
}