mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-06-06 19:24:56 +03:00
Fix route
This commit is contained in:
14
service.go
14
service.go
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user