fix chain route
This commit is contained in:
parent
8cb2269159
commit
11b727d72b
15
chain.go
15
chain.go
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user