[Git][NTPsec/ntpsec][master] fetch_nonce() is a method.

Eric S. Raymond gitlab at mg.gitlab.com
Sat Nov 12 21:15:16 UTC 2016


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
1050e517 by Eric S. Raymond at 2016-11-12T16:15:04-05:00
fetch_nonce() is a method.

- - - - -


1 changed file:

- pylib/packet.py


Changes:

=====================================
pylib/packet.py
=====================================
--- a/pylib/packet.py
+++ b/pylib/packet.py
@@ -244,12 +244,15 @@ class Packet:
     def extension(self, x):
         self.__extension = polybytes(x)
 
-    def mode(self):
-        return self.li_vn_mode & 0x7
+    def leap(self):
+        return ("no-leap", "add-leap", "del-leap", "unsync")[(self.li_vn_mode & 0x60) >> 6]
 
     def version(self):
         return (self.li_vn_mode >> 3) & 0x7
 
+    def mode(self):
+        return self.li_vn_mode & 0x7
+
 class Mode3Packet(Packet):
     "Mode 3 request/response (actually usable for modes 1-5)"
 
@@ -267,8 +270,9 @@ class Mode3Packet(Packet):
         self.receive_timestamp = 0
         self.transmit_timestamp = 0
         self.extension = ''
-    format = "!BBBBHHHLLLL"
+    format = "!BBBBIIIQQQQ"
     HEADER_LEN = 48
+    UNIX_EPOCH = 2208988800	# Midnight 1 Jan 1970 in secs since NTP epoch
 
     def analyze(self, rawdata):
         (self.li_vn_mode,
@@ -304,16 +308,25 @@ class Mode3Packet(Packet):
     def send(self):
         self.session.sendpkt(self.flatten())
 
+    @staticmethod
+    def ntp_to_posix(t):
+        "Scale from NTP time to POSIX time"
+        # Note: assumes we're in the same NTP era as the transmitter...
+        return (t * 2**-32) - UNIX_EPOCH 
+
     def refid_octets(self):
+        "Analyze refid into octets."
         return ((self.refid >> 24) & 0xff,
                 (self.refid >> 16) & 0xff,
                 (self.refid >> 8) & 0xff,
                 self.refid & 0xff)
 
     def refid_as_string(self):
+        "Sometimes it's a clock name or KOD type"
         return polystr(struct.pack("BBBB" % self.refid_octets()))
 
     def refid_as_address(self):
+        "Sometimes it's an IPV4 address."
         return polystr("%d.%d.%d.%d" % self.refid_octets())
 
     def is_crypto_nak(self):
@@ -1138,7 +1151,7 @@ class Mode6Session:
                            parms)
 		nonce_uses += 1
                 if nonce_uses >= 4:
-                    nonce = fetch_nonce()
+                    nonce = self.fetch_nonce()
                     nonce_uses = 0
                 for i in range(len(span.entries)):
                     e = span.entries[len(span.entries) - i - 1]



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/1050e5176c4501e483941a3d8436749fcf8e2a70
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20161112/897cb341/attachment.html>


More information about the vc mailing list