[Git][NTPsec/ntpsec][master] 2 commits: Turned warndbg lambdas into ControlSession method.

Ian Bruene gitlab at mg.gitlab.com
Fri Dec 20 18:41:16 UTC 2019



Ian Bruene pushed to branch master at NTPsec / ntpsec


Commits:
3cf669fe by Ian Bruene at 2019-12-15T09:47:16-06:00
Turned warndbg lambdas into ControlSession method.

- - - - -
514d2d50 by Ian Bruene at 2019-12-17T10:12:32-06:00
Fixed missing variable update from extracting __mru_analyze.

- - - - -


1 changed file:

- pylib/packet.py


Changes:

=====================================
pylib/packet.py
=====================================
@@ -730,6 +730,9 @@ class ControlSession:
         self.logfp = sys.stdout
         self.nonce_xmit = 0
 
+    def warndbg(self, text, threshold):
+        ntp.util.dolog(self.logfp, text, self.debug, threshold)
+
     def close(self):
         if self.sock:
             self.sock.close()
@@ -1301,12 +1304,11 @@ This combats source address spoofing
         raise ControlException(SERR_BADNONCE)
 
     def __mru_analyze(self, variables, span, direct):
-        warndbg = (lambda txt, th: ntp.util.dolog(self.logfp, txt,
-                                                  self.debug, th))
         curidx = -1
         mru = None
+        nonce = None
         for (tag, val) in variables.items():
-            warndbg("tag=%s, val=%s" % (tag, val), 4)
+            self.warndbg("tag=%s, val=%s" % (tag, val), 4)
             if tag == "nonce":
                 nonce = "%s=%s" % (tag, val)
             elif tag == "last.older":
@@ -1343,44 +1345,43 @@ This combats source address spoofing
             span.entries.append(mru)
         if direct is not None:
             direct(span.entries)
+        return nonce
 
     def __mru_query_error(self, e, restarted_count, cap_frags, limit, frags):
-        warndbg = (lambda txt, th: ntp.util.dolog(self.logfp, txt,
-                                                  self.debug, th))
         if e.errorcode is None:
             raise e
         elif e.errorcode == ntp.control.CERR_UNKNOWNVAR:
             # None of the supplied prior entries match, so
             # toss them from our list and try again.
-            warndbg("no overlap between prior entries and "
-                    "server MRU list", 1)
+            self.warndbg("no overlap between prior entries and "
+                         "server MRU list", 1)
             restarted_count += 1
             if restarted_count > 8:
                 raise ControlException(SERR_STALL)
-            warndbg("--->   Restarting from the beginning, "
-                    "retry #%u" % restarted_count, 1)
+            self.warndbg("--->   Restarting from the beginning, "
+                         "retry #%u" % restarted_count, 1)
         elif e.errorcode == ntp.control.CERR_BADVALUE:
             if cap_frags:
                 cap_frags = False
-                warndbg("Reverted to row limit from "
-                        "fragments limit.", 1)
+                self.warndbg("Reverted to row limit from "
+                             "fragments limit.", 1)
             else:
                 # ntpd has lower cap on row limit
                 self.ntpd_row_limit -= 1
                 limit = min(limit, self.ntpd_row_limit)
-                warndbg("Row limit reduced to %d following "
-                        "CERR_BADVALUE." % limit, 1)
+                self.warndbg("Row limit reduced to %d following "
+                             "CERR_BADVALUE." % limit, 1)
         elif e.errorcode in (SERR_INCOMPLETE, SERR_TIMEOUT):
             # Reduce the number of rows/frags requested by
             # half to recover from lost response fragments.
             if cap_frags:
                 frags = max(2, frags / 2)
-                warndbg("Frag limit reduced to %d following "
-                        "incomplete response." % frags, 1)
+                self.warndbg("Frag limit reduced to %d following "
+                             "incomplete response." % frags, 1)
             else:
                 limit = max(2, limit / 2)
-                warndbg("Row limit reduced to %d following "
-                        " incomplete response." % limit, 1)
+                self.warndbg("Row limit reduced to %d following "
+                             " incomplete response." % limit, 1)
         elif e.errorcode:
             raise e
         return restarted_count, cap_frags, limit, frags
@@ -1389,8 +1390,6 @@ This combats source address spoofing
         "Retrieve MRU list data"
         restarted_count = 0
         cap_frags = True
-        warndbg = (lambda txt, th: ntp.util.dolog(self.logfp, txt,
-                                                  self.debug, th))
         sorter = None
         sortkey = None
         frags = MAXFRAGS
@@ -1443,7 +1442,9 @@ This combats source address spoofing
                     rawhook(variables)
 
                 # Analyze the contents of this response into a span structure
-                self.__mru_analyze(variables, span, direct)
+                newNonce = self.__mru_analyze(variables, span, direct)
+                if newNonce:
+                    nonce = newNonce
 
                 # If we've seen the end sentinel on the span, break out
                 if span.is_complete():



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/d941e8d02e9022d73c5bcaa4973d8d0f5f448826...514d2d50a50e4958e1a0683a049eeaccd05fb41f

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/d941e8d02e9022d73c5bcaa4973d8d0f5f448826...514d2d50a50e4958e1a0683a049eeaccd05fb41f
You're receiving this email because of your account on gitlab.com.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20191220/9bf1e9a2/attachment-0001.htm>


More information about the vc mailing list