From 6e55c1d2e362869138d4a47318681a6e6ad8777b Mon Sep 17 00:00:00 2001 From: Jack Doan Date: Mon, 14 Oct 2024 22:48:29 -0400 Subject: [PATCH] tighter loop --- hostmap.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/hostmap.go b/hostmap.go index 0439061fd..00173c45b 100644 --- a/hostmap.go +++ b/hostmap.go @@ -456,18 +456,19 @@ func (hm *HostMap) QueryVpnAddrsRelayFor(targetIps []netip.Addr, relayHostIp net hm.RLock() defer hm.RUnlock() - for _, targetIp := range targetIps { - h, ok := hm.Hosts[relayHostIp] - if !ok { - return nil, nil, errors.New("unable to find host") - } - for h != nil { + h, ok := hm.Hosts[relayHostIp] + if !ok { + return nil, nil, errors.New("unable to find host") + } + + for h != nil { + for _, targetIp := range targetIps { r, ok := h.relayState.QueryRelayForByIp(targetIp) if ok && r.State == Established { return h, r, nil } - h = h.next } + h = h.next } return nil, nil, errors.New("unable to find host with relay")