From c04c28e1fd78d797e6eed8b79d0c0539c34ee1cd Mon Sep 17 00:00:00 2001 From: ginuerzh Date: Mon, 8 Jan 2024 21:22:20 +0800 Subject: [PATCH] add protocol based node selection for hop --- hop/hop.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/hop/hop.go b/hop/hop.go index dec6392b..b528f2ec 100644 --- a/hop/hop.go +++ b/hop/hop.go @@ -168,16 +168,24 @@ func (p *chainHop) Select(ctx context.Context, opts ...hop.SelectOption) *chain. if len(filters) == 0 { filters = nodes } - } else if protocol := options.Protocol; protocol != "" { - filters = nil - for _, node := range ns { + } + + if protocol := options.Protocol; protocol != "" { + p.options.logger.Debugf("filter by protocol: %s", protocol) + var nodes []*chain.Node + for _, node := range filters { if node == nil { continue } + if node.Options().Protocol == "" { + nodes = append(nodes, node) + continue + } if node.Options().Protocol == protocol { - filters = append(filters, node) + nodes = append(nodes, node) } } + filters = nodes } // filter by path