[Git][NTPsec/ntpsec][master] 2 commits: Moved read_append() definition out of loop
Ian Bruene
gitlab at mg.gitlab.com
Thu Jul 20 04:50:07 UTC 2017
Ian Bruene pushed to branch master at NTPsec / ntpsec
Commits:
f81614f0 by Ian Bruene at 2017-07-19T18:28:27-05:00
Moved read_append() definition out of loop
- - - - -
729c5367 by Ian Bruene at 2017-07-19T18:47:20-05:00
Adjusted sleep behavior to be more logical
ntpdig now consistently sleeps() if a gap is set, and only between
actions that it would be logical to have a gap between.
It also no longer has unnecessary sleeps due to dumb loops
- - - - -
1 changed file:
- ntpclients/ntpdig
Changes:
=====================================
ntpclients/ntpdig
=====================================
--- a/ntpclients/ntpdig
+++ b/ntpclients/ntpdig
@@ -57,6 +57,28 @@ except ImportError as e:
sys.exit(1)
+def read_append(s, packets, packet, sockaddr):
+ d, a = s.recvfrom(1024)
+ if debug >= 2:
+ ntp.packet.dump_hex_printable(d)
+ if credentials:
+ if not ntp.packet.Authenticator.have_mac(d):
+ if debug:
+ log("no MAC on reply from %s" % packet.hostname)
+ if not credentials.verify_mac(d):
+ packet.trusted = False
+ log("MAC verification on reply from %s failed"
+ % sockaddr[0])
+ elif debug:
+ log("MAC verification on reply from %s succeeded"
+ % sockaddr[0])
+ pkt = ntp.packet.SyncPacket(d)
+ pkt.hostname = server
+ pkt.resolved = sockaddr[0]
+ packets.append(pkt)
+ return packets
+
+
def queryhost(server, concurrent, timeout=5, port=123):
"Query IP addresses associated with a specified host."
try:
@@ -72,7 +94,13 @@ def queryhost(server, concurrent, timeout=5, port=123):
request.transmit_timestamp = ntp.packet.SyncPacket.posix_to_ntp(
time.time())
packet = request.flatten()
+ needgap = (len(iptuples) > 1) and (gap > 0)
+ firstloop = True
for (family, socktype, proto, canonname, sockaddr) in iptuples:
+ if needgap and not firstloop:
+ time.sleep(gap)
+ if firstloop:
+ firstloop = False
if debug:
log("querying %s (%s)" % (sockaddr[0], server))
s = socket.socket(family, socktype)
@@ -94,41 +122,19 @@ def queryhost(server, concurrent, timeout=5, port=123):
if debug >= 2:
log("Sent to %s:" % (sockaddr[0],))
ntp.packet.dump_hex_printable(packet)
-
- def read_append(s, packets):
- d, a = s.recvfrom(1024)
- if debug >= 2:
- ntp.packet.dump_hex_printable(d)
- if credentials:
- if not ntp.packet.Authenticator.have_mac(d):
- if debug:
- log("no MAC on reply from %s" % packet.hostname)
- if not credentials.verify_mac(d):
- packet.trusted = False
- log("MAC verification on reply from %s failed"
- % sockaddr[0])
- elif debug:
- log("MAC verification on reply from %s succeeded"
- % sockaddr[0])
- pkt = ntp.packet.SyncPacket(d)
- pkt.hostname = server
- pkt.resolved = sockaddr[0]
- packets.append(pkt)
- time.sleep(gap)
if concurrent:
sockets.append(s)
else:
r, _, _ = select.select([s], [], [], timeout)
if not r:
return []
- read_append(s, packets)
- if concurrent:
+ read_append(s, packets, packet, sockaddr)
while sockets:
r, _, _ = select.select(sockets, [], [], timeout)
if not r:
return packets
for s in sockets:
- read_append(s, packets)
+ read_append(s, packets, packet, sockaddr)
sockets.remove(s)
return packets
@@ -384,7 +390,13 @@ if __name__ == '__main__':
returned = [packet]
else:
returned = []
+ needgap = (samples > 1) and (gap > 0)
+ firstloop = True
for s in range(samples):
+ if needgap and not firstloop:
+ time.sleep(gap)
+ if firstloop is True:
+ firstloop = False
for server in concurrent_hosts:
try:
returned += queryhost(server=server,
@@ -401,6 +413,7 @@ if __name__ == '__main__':
except ntp.packet.SyncException as e:
log(str(e))
continue
+
returned = clock_select(returned)
if returned:
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/a2fcf68cd762b478907d1c1288b76c3d16d25c69...729c536729694f9d6e2ea58d33b72087a8cfd5a1
---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/a2fcf68cd762b478907d1c1288b76c3d16d25c69...729c536729694f9d6e2ea58d33b72087a8cfd5a1
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/20170720/47f9ea69/attachment.html>
More information about the vc
mailing list