Fix route

This commit is contained in:
世界
2022-07-04 19:34:45 +08:00
parent dfde4e34c0
commit b8e45853c0
5 changed files with 69 additions and 27 deletions

View File

@@ -2,6 +2,7 @@ package box
import (
"context"
"time"
"github.com/sagernet/sing-box/adapter"
"github.com/sagernet/sing-box/inbound"
@@ -11,6 +12,7 @@ import (
"github.com/sagernet/sing-box/route"
"github.com/sagernet/sing/common"
E "github.com/sagernet/sing/common/exceptions"
F "github.com/sagernet/sing/common/format"
)
var _ adapter.Service = (*Service)(nil)
@@ -20,9 +22,11 @@ type Service struct {
logger log.Logger
inbounds []adapter.Inbound
outbounds []adapter.Outbound
createdAt time.Time
}
func NewService(ctx context.Context, options option.Options) (*Service, error) {
createdAt := time.Now()
logger, err := log.NewLogger(common.PtrValueOrDefault(options.Log))
if err != nil {
return nil, E.Cause(err, "parse log options")
@@ -63,6 +67,7 @@ func NewService(ctx context.Context, options option.Options) (*Service, error) {
logger: logger,
inbounds: inbounds,
outbounds: outbounds,
createdAt: createdAt,
}, nil
}
@@ -71,15 +76,18 @@ func (s *Service) Start() error {
if err != nil {
return err
}
err = s.router.Start()
if err != nil {
return err
}
for _, in := range s.inbounds {
err = in.Start()
if err != nil {
return err
}
}
return common.AnyError(
s.router.Start(),
)
s.logger.Info("sing-box started (", F.Seconds(time.Since(s.createdAt).Seconds()), "s)")
return nil
}
func (s *Service) Close() error {