initial commit

This commit is contained in:
ginuerzh
2022-03-16 19:40:29 +08:00
commit 7db81fcfeb
109 changed files with 8782 additions and 0 deletions

41
chain/chain.go Normal file
View File

@ -0,0 +1,41 @@
package chain
type Chainer interface {
Route(network, address string) *Route
}
type Chain struct {
groups []*NodeGroup
}
func (c *Chain) AddNodeGroup(group *NodeGroup) {
c.groups = append(c.groups, group)
}
func (c *Chain) Route(network, address string) (r *Route) {
if c == nil || len(c.groups) == 0 {
return
}
r = &Route{}
for _, group := range c.groups {
node := group.Next()
if node == nil {
return
}
if node.Bypass != nil && node.Bypass.Contains(address) {
break
}
if node.Transport.Multiplex() {
tr := node.Transport.Copy().
WithRoute(r)
node = node.Copy()
node.Transport = tr
r = &Route{}
}
r.addNode(node)
}
return r
}