improve chain node bypass
This commit is contained in:
parent
ff51aef518
commit
81bf7b985a
@ -29,14 +29,15 @@ func (c *Chain) Route(network, address string) (r *Route) {
|
||||
chain: c,
|
||||
}
|
||||
for _, group := range c.groups {
|
||||
node := group.Next()
|
||||
if node == nil {
|
||||
return
|
||||
}
|
||||
if node.Bypass != nil && node.Bypass.Contains(address) {
|
||||
// hop level bypass test
|
||||
if group.bypass != nil && group.bypass.Contains(address) {
|
||||
break
|
||||
}
|
||||
|
||||
node := group.filter(address).Next()
|
||||
if node == nil {
|
||||
return
|
||||
}
|
||||
if node.Transport.Multiplex() {
|
||||
tr := node.Transport.Copy().
|
||||
WithRoute(r)
|
||||
|
@ -28,6 +28,7 @@ func (node *Node) Copy() *Node {
|
||||
type NodeGroup struct {
|
||||
nodes []*Node
|
||||
selector Selector
|
||||
bypass bypass.Bypass
|
||||
}
|
||||
|
||||
func NewNodeGroup(nodes ...*Node) *NodeGroup {
|
||||
@ -45,6 +46,25 @@ func (g *NodeGroup) WithSelector(selector Selector) *NodeGroup {
|
||||
return g
|
||||
}
|
||||
|
||||
func (g *NodeGroup) WithBypass(bypass bypass.Bypass) *NodeGroup {
|
||||
g.bypass = bypass
|
||||
return g
|
||||
}
|
||||
|
||||
func (g *NodeGroup) filter(addr string) *NodeGroup {
|
||||
var nodes []*Node
|
||||
for _, node := range g.nodes {
|
||||
if node.Bypass == nil || !node.Bypass.Contains(addr) {
|
||||
nodes = append(nodes, node)
|
||||
}
|
||||
}
|
||||
return &NodeGroup{
|
||||
nodes: nodes,
|
||||
selector: g.selector,
|
||||
bypass: g.bypass,
|
||||
}
|
||||
}
|
||||
|
||||
func (g *NodeGroup) Next() *Node {
|
||||
if g == nil || len(g.nodes) == 0 {
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user