Skip to content

Commit

Permalink
fix: cannot start tun
Browse files Browse the repository at this point in the history
  • Loading branch information
AkinoKaede committed May 28, 2023
1 parent 422f9e9 commit 8fe706e
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions app/tun/tun.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}))
}

0 comments on commit 8fe706e

Please sign in to comment.