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,
|
chain: c,
|
||||||
}
|
}
|
||||||
for _, group := range c.groups {
|
for _, group := range c.groups {
|
||||||
node := group.Next()
|
// hop level bypass test
|
||||||
if node == nil {
|
if group.bypass != nil && group.bypass.Contains(address) {
|
||||||
return
|
|
||||||
}
|
|
||||||
if node.Bypass != nil && node.Bypass.Contains(address) {
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
node := group.filter(address).Next()
|
||||||
|
if node == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
if node.Transport.Multiplex() {
|
if node.Transport.Multiplex() {
|
||||||
tr := node.Transport.Copy().
|
tr := node.Transport.Copy().
|
||||||
WithRoute(r)
|
WithRoute(r)
|
||||||
|
@ -28,6 +28,7 @@ func (node *Node) Copy() *Node {
|
|||||||
type NodeGroup struct {
|
type NodeGroup struct {
|
||||||
nodes []*Node
|
nodes []*Node
|
||||||
selector Selector
|
selector Selector
|
||||||
|
bypass bypass.Bypass
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNodeGroup(nodes ...*Node) *NodeGroup {
|
func NewNodeGroup(nodes ...*Node) *NodeGroup {
|
||||||
@ -45,6 +46,25 @@ func (g *NodeGroup) WithSelector(selector Selector) *NodeGroup {
|
|||||||
return g
|
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 {
|
func (g *NodeGroup) Next() *Node {
|
||||||
if g == nil || len(g.nodes) == 0 {
|
if g == nil || len(g.nodes) == 0 {
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user