diff --git a/chain.go b/chain.go index d328f32..8d304ba 100644 --- a/chain.go +++ b/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) }