[Git][NTPsec/ntpsec][master] In the Pyton code, create a class to encapsulate peer state.

Eric S. Raymond gitlab at mg.gitlab.com
Tue Oct 18 04:13:23 UTC 2016


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


Commits:
c70facd7 by Eric S. Raymond at 2016-10-18T00:13:11-04:00
In the Pyton code, create a class to encapsulate peer state.

- - - - -


1 changed file:

- pylib/packet.py


Changes:

=====================================
pylib/packet.py
=====================================
--- a/pylib/packet.py
+++ b/pylib/packet.py
@@ -146,6 +146,19 @@ class Mode6Packet(Packet):
          self.associd,
          self.offset) = Packet.analyze(self, data)
 
+class Peer:
+    "The information we have about an NTP peer."
+    def __init__(self, session, associd, status):
+        self.session = session
+        self.associd = associd
+        self.status = status
+        self.variables = {}
+    def readvars(self):
+        self.variables = self.session.readvars()
+    def __str__(self):
+        return "<Peer: associd=%s status=%s>" % (self.associd, self.status)
+    __repr__ = __str__
+
 SERR_BADFMT = "***Server reports a bad format request packet\n"
 SERR_PERMISSION = "***Server disallowed request (authentication?)\n"
 SERR_BADOP = "***Server reports a bad opcode in request\n"
@@ -512,7 +525,8 @@ class Mode6Session:
         if associd == 0:
             for i in range(len(self.response)//4):
                 data = self.response[4*i:4*i+4]
-                idlist.append(struct.unpack("!HH", data))
+                (associd, status) = struct.unpack("!HH", data)
+                idlist.append(Peer(self, associd, status))
         return idlist
 
     def readvar(self, associd=0, varlist=None):



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/c70facd79932f8934ded65048f1b203521a17d43
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20161018/db589306/attachment.html>


More information about the vc mailing list