Commit 4dc02af2 authored by Alexandre's avatar Alexandre
Browse files

[DoH] Store all curl handles in Connection when using streams

parent a4f2463a
......@@ -494,6 +494,7 @@ class ConnectionDoH(Connection):
self.multistreams = multistreams
if self.multistreams:
self.multi = self.create_multi()
self.all_handles = []
else:
self.curl_handle = create_handle(self)
......@@ -562,13 +563,13 @@ class ConnectionDoH(Connection):
handle = self.curl_handle
else:
handle = create_handle(self)
self.all_handles.append(handle)
handle.prepare(handle, self, request)
if synchronous:
self.send_and_receive(handle)
request.check_response()
else:
self.multi.add_handle(handle)
return handle
def get_next_domain(input_file):
......@@ -626,13 +627,11 @@ def print_result(connection, request, prefix=None, display_err=True):
ok = False
return ok
# pending_requests must be an array
def read_results(connection, pending_handles):
for i in range(0, len(pending_handles)):
handle = pending_handles[i]
def read_results(connection):
for handle in connection.all_handles:
connection.receive(handle)
handle.request.check_response()
return pending_handles
print("Return code %s:\n%s\n" % (handle.request.rcode, handle.request.response))
def create_request(qname, qtype=rtype, use_edns=edns, want_dnssec=dnssec, dot=dot, trunc=False):
if dot:
......@@ -886,8 +885,6 @@ if not monitoring:
name = args[1]
if len(args) == 3:
rtype = args[2]
if multistreams:
pending = {}
else: # Monitoring plugin
dot = (me == "check_dot")
name = None
......@@ -1033,10 +1030,7 @@ for connectTo in ip_set:
request.head = head
request.post = post
try:
if dot:
conn.do_test(request, synchronous = not multistreams)
else:
handle = conn.do_test(request, synchronous = not multistreams)
conn.do_test(request, synchronous = not multistreams)
except (OpenSSL.SSL.Error, CustomException) as e:
ok = False
error(e)
......@@ -1044,18 +1038,14 @@ for connectTo in ip_set:
if not multistreams:
if not print_result(conn, request):
ok = False
else: # We do multistreams
pending[i] = handle # No result yet
if tests > 1 and i == 0:
start2 = time.time()
if delay is not None:
time.sleep(delay)
if multistreams:
conn.perform_multi()
print("")
handles = read_results(conn, pending)
for j in handles:
print("Return code %s: %s\n" % (handles[j].request.rcode, handles[j].request.response))
print()
read_results(conn)
else:
ok = run_check(conn) and ok # need to run run_check first
stop = time.time()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment