[Git][NTPsec/ntpsec][master] fix ntpq/mru to work with multiple batches

Hal Murray gitlab at mg.gitlab.com
Tue Dec 20 05:08:26 UTC 2016


Hal Murray pushed to branch master at NTPsec / ntpsec


Commits:
917ad026 by Hal Murray at 2016-12-19T21:07:22-08:00
fix ntpq/mru to work with multiple batches

- - - - -


3 changed files:

- docs/mode6.txt
- pylib/packet.py
- pylib/util.py


Changes:

=====================================
docs/mode6.txt
=====================================
--- a/docs/mode6.txt
+++ b/docs/mode6.txt
@@ -291,6 +291,9 @@ limit::		Limit on MRU entries returned.  One of frags= or limit=
 
 mincount::	(decimal) Return entries with packet count >= mincount.
 
+maxlstint::	(decimal) Return entries with lstint <= maxlstint.
+		(lstint is now-time of most recent packet)
+
 laddr::		Return entries associated with the server's IP
 		address given.  No port specification is needed,
 		and any supplied is ignored.


=====================================
pylib/packet.py
=====================================
--- a/pylib/packet.py
+++ b/pylib/packet.py
@@ -1325,11 +1325,22 @@ class ControlSession:
                     rawhook(variables)
 
                 # Analyze the contents of this response into a span structure
+                curidx = -1
                 for (tag, val) in variables.items():
-                    if tag =="now":
+                    if self.debug >= 4:
+                        warn("tag=%s, val=%s\n" % (tag, val))
+                    if tag == "nonce":
+                        nonce = "%s=%s" % (tag, val)
+                    elif tag == "last.older":
+                        continue
+                    elif tag == "addr.older":
+                        continue
+                    if tag == "now":
+                        # Don't see this in debug output, Hal, 2016-Dec-19
                         span.now = ntp.ntpc.lfptofloat(val)
                         continue
                     elif tag == "last.newest":
+                        # Don't see this in debug output, Hal, 2016-Dec-19
                         continue
                     for prefix in ("addr", "last", "first", "ct", "mv", "rs"):
                         if tag.startswith(prefix + "."):
@@ -1338,11 +1349,12 @@ class ControlSession:
                                 idx = int(idx)
                             except ValueError:
                                 raise ControlException(SERR_BADTAG % tag)
-                            if idx >= len(span.entries):
-                                span.entries.append(MRUEntry())
-                            if type(val) != type(0) and val.startswith("0x"):
-                                val = ntp.ntpc.lfptofloat(val)
-                            setattr(span.entries[-1], prefix, val)
+                            if idx != curidx:
+                                # This makes duplicates
+                                curidx = idx
+                                mru = MRUEntry()
+                                span.entries.append(mru)
+                            setattr(mru, prefix, val)
 
                 # If we've seen the end sentinel on the span, break out
                 if span.is_complete():


=====================================
pylib/util.py
=====================================
--- a/pylib/util.py
+++ b/pylib/util.py
@@ -484,9 +484,11 @@ class MRUSummary:
     width = 79
 
     def summary(self, entry):
-        lstint = int(self.now - entry.last + 0.5)
-        active = float(entry.last - entry.first)
-        favgint = active / entry.ct
+        last = ntp.ntpc.lfptofloat(entry.last)
+        lstint = int(self.now - last + 0.5)
+        first = ntp.ntpc.lfptofloat(entry.first)
+        active = float(last - first)
+        favgint = active / entry.ct  # FIXME should be ct-1
         avgint = int(favgint + 0.5)
         stats = "%7d" % lstint
         if 5 < avgint or 1 == entry.ct:



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/917ad0268d8a8ace342751225625491509804ecc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20161220/83e35d3d/attachment.html>


More information about the vc mailing list