[Git][NTPsec/ntpsec][master] 2 commits: In pyntpdig, recover from packet-analysis exceptions.
Eric S. Raymond
gitlab at mg.gitlab.com
Fri Nov 25 13:50:22 UTC 2016
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
c488fe38 by Eric S. Raymond at 2016-11-24T19:26:39-05:00
In pyntpdig, recover from packet-analysis exceptions.
- - - - -
bce00e87 by Eric S. Raymond at 2016-11-24T20:53:04-05:00
Initialize some exception classes correctly.
- - - - -
2 changed files:
- ntpdig/pyntpdig
- pylib/packet.py
Changes:
=====================================
ntpdig/pyntpdig
=====================================
--- a/ntpdig/pyntpdig
+++ b/ntpdig/pyntpdig
@@ -356,11 +356,19 @@ if __name__ == '__main__':
returned = []
for server in concurrent_hosts:
- returned += queryhost(server=server, concurrent=True, timeout=timeout)
+ try:
+ returned += queryhost(server=server, concurrent=True, timeout=timeout)
+ except SyncException:
+ log(e.message)
+ continue
if len(returned) >= samples:
break
for server in arguments:
- returned += queryhost(server=server, concurrent=False, timeout=timeout)
+ try:
+ returned += queryhost(server=server, concurrent=False, timeout=timeout)
+ except SyncException:
+ log(e.message)
+ continue
if len(returned) >= samples:
break
=====================================
pylib/packet.py
=====================================
--- a/pylib/packet.py
+++ b/pylib/packet.py
@@ -66,6 +66,54 @@ The RFC5905 diagram is slightly out of date in that the digest header assumes
a 128-bit (16-octet) MD5 hash, but it is also possible for the field to be a
160-bit (20-octet) SHA-1 hash.
+Here's how to interpret the payload fields:
+
+t_1, the origin timestamp, is the time according to the client at
+which the request was sent.
+
+t_2, the transmit timestamp, is the time according to the server at
+which the request was received.
+
+t_3, the receive timestamp, is the time according to the server at
+which the reply was sent.
+
+t_4, the destination timestamp, is the time according to the client at
+which the reply was received.
+
+Theta is the thing we want to estimate: the offset between the server
+clock and the client clock. The sign convention is that theta is
+positive iff the server is ahead of the client.
+
+Theta is estimated by [(t_2-t_1)+(t_3-t_4)]/2. The accuracy of this
+estimate is predicated upon network latency being symmetrical.
+
+Delta is the network round trip time, i.e. (t_4-t_1)-(t_3-t_2).
+(t_4-t_1) is the total time that the request was in flight, and
+(t_3-t_2) is time that the server spent processing it; when you
+subtract that out you're left with just network delays.
+
+Lambda nominally represents the maximum amount by which theta could be
+off. It's computed as delta/2 + epsilon. The delta/2 term usually
+dominates and represents the maximum amount by which network asymmetry
+could be throwing off the calculation. Epsilon is the sum of three
+other sources of error:
+
+rho_r: the (im)precision field from response packet, representing the
+server's inherent error in clock measurement.
+
+rho_s: the client's own (im)precision. This may not be available,
+e.g in ntpdig.
+
+PHI*(t_4-t_1): The amount by which the client's clock may plausibly
+have drifted while the packet was in flight. PHI is taken to be a
+constant of 15ppm.
+
+rho_r and rho_s are estimated by making back-to-back calls to
+clock_gettime() (or similar) and taking their difference. They're
+encoded on the wire as an eight-bit two's complement integer
+representing, to the nearest integer, log_2 of the value in seconds.
+
+
An extension field consists of a 32-bit network-order type field
length, followed by a 32-bit network-order payload length in octets,
followed by the payload (which must be padded to a 4-octet boundary).
@@ -267,8 +315,9 @@ class Packet:
def mode(self):
return self.li_vn_mode & 0x7
-class SyncException(BaseException):
+class SyncException(Exception):
def __init__(self, message, errorcode=0):
+ Exception.__init__(self)
self.message = message
self.errorcode = errorcode
@@ -580,8 +629,9 @@ class MRUList:
def __repr__(self):
return "<MRUList: entries=%s now=%s>" % (self.entries, self.now)
-class ControlException(BaseException):
+class ControlException(Exception):
def __init__(self, message, errorcode=0):
+ Exception.__init__(self)
self.message = message
self.errorcode = errorcode
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/115f94a9b28b63c850b0d7c64b662a4c44279cdc...bce00e8705509f9fffbf819363c2d3799fa28013
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20161125/cf497e8a/attachment.html>
More information about the vc
mailing list