mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-26 02:21:28 +00:00
Start outbounds before router
This commit is contained in:
parent
f381f8d35a
commit
d0fa79044a
40
box.go
40
box.go
|
@ -168,6 +168,26 @@ func New(ctx context.Context, options option.Options) (*Box, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Box) Start() error {
|
func (s *Box) Start() error {
|
||||||
|
for i, out := range s.outbounds {
|
||||||
|
if starter, isStarter := out.(common.Starter); isStarter {
|
||||||
|
err := starter.Start()
|
||||||
|
if err != nil {
|
||||||
|
for _, in := range s.inbounds {
|
||||||
|
common.Close(in)
|
||||||
|
}
|
||||||
|
for g := 0; g < i; g++ {
|
||||||
|
common.Close(s.outbounds[g])
|
||||||
|
}
|
||||||
|
var tag string
|
||||||
|
if out.Tag() == "" {
|
||||||
|
tag = F.ToString(i)
|
||||||
|
} else {
|
||||||
|
tag = out.Tag()
|
||||||
|
}
|
||||||
|
return E.Cause(err, "initialize outbound/", out.Type(), "[", tag, "]")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
err := s.router.Start()
|
err := s.router.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -187,26 +207,6 @@ func (s *Box) Start() error {
|
||||||
return E.Cause(err, "initialize inbound/", in.Type(), "[", tag, "]")
|
return E.Cause(err, "initialize inbound/", in.Type(), "[", tag, "]")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i, out := range s.outbounds {
|
|
||||||
if starter, isStarter := out.(common.Starter); isStarter {
|
|
||||||
err = starter.Start()
|
|
||||||
if err != nil {
|
|
||||||
for _, in := range s.inbounds {
|
|
||||||
common.Close(in)
|
|
||||||
}
|
|
||||||
for g := 0; g < i; g++ {
|
|
||||||
common.Close(s.outbounds[g])
|
|
||||||
}
|
|
||||||
var tag string
|
|
||||||
if out.Tag() == "" {
|
|
||||||
tag = F.ToString(i)
|
|
||||||
} else {
|
|
||||||
tag = out.Tag()
|
|
||||||
}
|
|
||||||
return E.Cause(err, "initialize outbound/", out.Type(), "[", tag, "]")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if s.clashServer != nil {
|
if s.clashServer != nil {
|
||||||
err = s.clashServer.Start()
|
err = s.clashServer.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue