- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add high-level boundary management interface
I rewrote the router's boundary management part to implement dynamic management from a high-level box interface. This also includes a number of changes I made in the process of rewriting some messy parts, such as the Outbound tree bottom-top starter.
Showing
13 changed files
with
503 additions
and
352 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package route | ||
|
||
import ( | ||
"github.com/sagernet/sing-box/adapter" | ||
"github.com/sagernet/sing-box/common/taskmonitor" | ||
E "github.com/sagernet/sing/common/exceptions" | ||
) | ||
|
||
type OutboundStarter struct { | ||
outboundByTag map[string]adapter.Outbound | ||
startedTags map[string]struct{} | ||
monitor *taskmonitor.Monitor | ||
} | ||
|
||
func (s *OutboundStarter) Start(tag string, pathIncludesTags map[string]struct{}) error { | ||
adapter := s.outboundByTag[tag] | ||
if adapter == nil { | ||
return E.New("dependency[", tag, "] is not found") | ||
} | ||
|
||
// The outbound may have been started by another subtree in the previous, | ||
// we don't need to start it again. | ||
if _, ok := s.startedTags[tag]; ok { | ||
return nil | ||
} | ||
|
||
// If we detected the repetition of the tags in scope of tree evaluation, | ||
// the circular dependency is found, as it grows from bottom to top. | ||
if _, ok := pathIncludesTags[tag]; ok { | ||
return E.New("circular dependency related with outbound/", adapter.Type(), "[", tag, "]") | ||
} | ||
|
||
// This required to be done only if that outbound isn't already started, | ||
// because some dependencies may come to the same root, | ||
// but they aren't circular. | ||
pathIncludesTags[tag] = struct{}{} | ||
|
||
// Next, we are recursively starting all dependencies of the current | ||
// outbound and repeating the cycle. | ||
for _, dependencyTag := range adapter.Dependencies() { | ||
if err := s.Start(dependencyTag, pathIncludesTags); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
// Anyway, it will be finished soon, nothing will happen if I'll include | ||
// Startable interface typecasting too. | ||
s.monitor.Start("initialize outbound/", adapter.Type(), "[", tag, "]") | ||
defer s.monitor.Finish() | ||
|
||
// After the evaluation of entire tree let's begin to start all | ||
// the outbounds! | ||
if startable, isStartable := adapter.(interface{ Start() error }); isStartable { | ||
if err := startable.Start(); err != nil { | ||
return E.Cause(err, "initialize outbound/", adapter.Type(), "[", tag, "]") | ||
} | ||
} | ||
|
||
return nil | ||
} |