add chain

This commit is contained in:
ginuerzh
2021-10-26 21:07:46 +08:00
parent ce13b2a82a
commit 3351aa5974
78 changed files with 917 additions and 185 deletions

33
pkg/chain/chain.go Normal file
View File

@ -0,0 +1,33 @@
package chain
type Chain struct {
groups []*NodeGroup
}
func (c *Chain) AddNodeGroup(group *NodeGroup) {
c.groups = append(c.groups, group)
}
func (c *Chain) GetRoute() (r *Route) {
if c == nil || len(c.groups) == 0 {
return
}
r = &Route{}
for _, group := range c.groups {
node := group.Next()
if node == nil {
return
}
// TODO: bypass
if node.Transport().IsMultiplex() {
tr := node.Transport().WithRoute(r)
node = node.WithTransport(tr)
r = &Route{}
}
r.AddNode(node)
}
return r
}