Start outbounds before router

This commit is contained in:
世界 2022-08-20 09:13:00 +08:00
parent f381f8d35a
commit d0fa79044a
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

40
box.go
View file

@ -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 {