svc/conntrack.in (kickpeers): Refactor and reformat the search loop.
authorMark Wooding <mdw@distorted.org.uk>
Fri, 29 Sep 2017 00:18:25 +0000 (01:18 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 28 Jun 2018 23:29:24 +0000 (00:29 +0100)
The `ip' variable wasn't doing anything except remembering whether we'd
found a match, so replace it with a flag.  This frees up the `ip' name,
so give that to the bizarrely named `ipq' variable which holds the
discovered local address.

svc/conntrack.in

index 99491b1..261cf64 100644 (file)
@@ -360,27 +360,23 @@ def kickpeers():
       if T._debug: print '#   check group %s' % g
 
       ## Find out which peer in the group ought to be active.
-      ip = None
       statemap = {}
       want = None
+      matchp = False
       for t, p, n in pp:
-        if p is None or not upness:
-          ipq = addr
-        else:
-          ipq = localaddr(p)
+        if p is None or not upness: ip = addr
+        else: ip = localaddr(p)
         if T._debug:
           info = 'peer=%s; target=%s; net=%s; local=%s' % (
-            t, p or '(default)', n, straddr(ipq))
-        if upness and ip is None and \
-              ipq is not None and ipq.withinp(n):
+            t, p or '(default)', n, straddr(ip))
+        if upness and not matchp and \
+              ip is not None and ip.withinp(n):
           if T._debug: print '#     %s: SELECTED' % info
           statemap[t] = 'up'
           select.append('%s=%s' % (g, t))
-          if t == 'down' or t.startswith('down/'):
-            want = None
-          else:
-            want = t
-          ip = ipq
+          if t == 'down' or t.startswith('down/'): want = None
+          else: want = t
+          matchp = True
         else:
           statemap[t] = 'down'
           if T._debug: print '#     %s: skipped' % info