From: Mark Wooding Date: Fri, 29 Sep 2017 00:18:25 +0000 (+0100) Subject: svc/conntrack.in (kickpeers): Refactor and reformat the search loop. X-Git-Tag: 1.5.0~41^2~6 X-Git-Url: https://git.distorted.org.uk/~mdw/tripe/commitdiff_plain/fa59a04b4daaa8d75e1fb0e875ed6ed5fb6d1304 svc/conntrack.in (kickpeers): Refactor and reformat the search loop. 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. --- diff --git a/svc/conntrack.in b/svc/conntrack.in index 99491b1c..261cf642 100644 --- a/svc/conntrack.in +++ b/svc/conntrack.in @@ -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