Commit 11b727d7 authored by rui.zheng's avatar rui.zheng

fix chain route

parent 8cb22691
......@@ -16,6 +16,7 @@ var (
// Chain is a proxy chain that holds a list of proxy nodes.
type Chain struct {
isRoute bool
nodeGroups []*NodeGroup
}
......@@ -28,6 +29,12 @@ func NewChain(nodes ...Node) *Chain {
return chain
}
func newRoute(nodes ...Node) *Chain {
chain := NewChain(nodes...)
chain.isRoute = true
return chain
}
// Nodes returns the proxy nodes that the chain holds.
// If a node is a node group, the first node in the group will be returned.
func (c *Chain) Nodes() (nodes []Node) {
......@@ -165,8 +172,12 @@ func (c *Chain) getConn(route *Chain) (conn net.Conn, err error) {
}
func (c *Chain) selectRoute() (route *Chain, err error) {
if c.isRoute {
return c, nil
}
buf := bytes.Buffer{}
route = NewChain()
route = newRoute()
for _, group := range c.nodeGroups {
selector := group.Selector
if selector == nil {
......@@ -186,7 +197,7 @@ func (c *Chain) selectRoute() (route *Chain, err error) {
node.DialOptions = append(node.DialOptions,
ChainDialOption(route),
)
route = NewChain() // cutoff the chain for multiplex
route = newRoute() // cutoff the chain for multiplex
}
route.AddNode(node)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment