Commit 3c2f26cd authored by Alexandre's avatar Alexandre
Browse files

Remove abstraction methods for Request creation

parent 6b627037
......@@ -509,19 +509,31 @@ def parse_opts(opts):
def run_default(name, connection, opts):
ok = True
start = time.time()
if opts.multistreams:
connection.init_multi()
for i in range (0, opts.tests):
if opts.tests > 1 and (opts.verbose or opts.display_results):
print("\nTest %i" % i)
if opts.ifile is not None:
name, opts.rtype = get_next_domain(input)
request = homer.create_request(name, qtype=opts.rtype, use_edns=opts.edns,
want_dnssec=opts.dnssec, no_ecs=opts.no_ecs, dot=opts.dot)
if connection.dot:
request = homer.RequestDOT(name, qtype=opts.rtype, use_edns=opts.edns,
want_dnssec=opts.dnssec, no_ecs=opts.no_ecs)
else:
request = homer.RequestDOH(name, qtype=opts.rtype, use_edns=opts.edns,
want_dnssec=opts.dnssec, no_ecs=opts.no_ecs)
request.to_wire()
request.i = i
if not opts.dot:
request.head = opts.head
request.post = opts.post
if not opts.pipelining:
try:
connection.do_test(request, synchronous = not opts.multistreams)
......@@ -538,10 +550,12 @@ def run_default(name, connection, opts):
time.sleep(opts.delay)
else: # We do pipelining
connection.pipelining_add_request(request)
if opts.multistreams:
connection.perform_multi(opts.show_time, display_results=opts.display_results)
if opts.dot and opts.pipelining:
print("")
print()
done = 0
current = connection.pipelining_init_pending(opts.max_in_flight)
while done < opts.tests:
......@@ -565,6 +579,7 @@ def run_default(name, connection, opts):
if current < len(connection.all_requests):
connection.pipelining_fill_pending(current)
current += 1
stop = time.time()
if opts.tests > 1 and not opts.pipelining and not opts.multistreams:
extra = ", %.2f ms/request if we ignore the first one" % ((stop-start2)*1000/(opts.tests-1))
......
......@@ -13,9 +13,6 @@ from .connection import ConnectionDOH
from .request import RequestDOT
from .request import RequestDOH
from .request import create_request
from .request import create_requests_list
from .exceptions import TimeoutConnectionError
from .exceptions import ConnectionException
......
......@@ -382,7 +382,8 @@ class ConnectionDOH(Connection):
# query the root NS because this should not impact the resover cache
if self.verbose:
print("Establishing multistreams connection...")
request = homer.create_request('.', qtype='NS', dot=False)
request = homer.RequestDOH('.', qtype='NS')
request.to_wire()
self.do_test(request, synchronous=False)
self.perform_multi(silent=True, display_results=False, show_time=False)
self.all_handles = []
......
......@@ -108,34 +108,3 @@ class RequestDOH(Request):
else:
self.response = self.response
return self.success
def create_request(qname, qtype='AAAA', use_edns=True, want_dnssec=False, no_ecs=True, dot=False, trunc=False):
if dot:
request = RequestDOT(qname, qtype, use_edns, want_dnssec, no_ecs)
else:
request = RequestDOH(qname, qtype, use_edns, want_dnssec, no_ecs)
if trunc:
request.trunc_data()
else:
request.to_wire()
return request
def create_requests_list(dot=False, **req_args):
requests = []
if dot:
requests.append(('Test 1', create_request(dot=dot, **req_args),
homer.mandatory_levels["legal"]))
requests.append(('Test 2', create_request(dot=dot, **req_args),
homer.mandatory_levels["necessary"])) # RFC 7858,
# section 3.3, SHOULD accept several requests on one connection.
# TODO we miss the tests of pipelining and out-of-order.
else:
requests.append(('Test GET', create_request(**req_args), homer.DOH_GET,
homer.mandatory_levels["legal"])) # RFC 8484, section 4.1
requests.append(('Test POST', create_request(**req_args), homer.DOH_POST,
homer.mandatory_levels["legal"])) # RFC 8484, section 4.1
requests.append(('Test HEAD', create_request(**req_args), homer.DOH_HEAD,
homer.mandatory_levels["nicetohave"])) # HEAD
# method is not mentioned in RFC 8484 (see section 4.1), so
# just "nice to have".
return requests
......@@ -175,11 +175,19 @@ def parse_opts_monitoring(me, opts):
return (url, name)
def run_default(name, connection, opts):
request = homer.create_request(name, qtype=opts.rtype, use_edns=opts.edns,
want_dnssec=opts.dnssec, no_ecs=opts.no_ecs, dot=opts.dot)
if connection.dot:
request = homer.RequestDOT(name, qtype=opts.rtype, use_edns=opts.edns,
want_dnssec=opts.dnssec, no_ecs=opts.no_ecs)
else:
request = homer.RequestDOH(name, qtype=opts.rtype, use_edns=opts.edns,
want_dnssec=opts.dnssec, no_ecs=opts.no_ecs)
request.to_wire()
if not opts.dot:
request.head = opts.head
request.post = opts.post
try:
connection.do_test(request)
except (OpenSSL.SSL.Error, homer.DOHException) as e:
......@@ -188,6 +196,7 @@ def run_default(name, connection, opts):
ok = request.success and request.has_expected_str(opts.expect)
print_result(connection, request)
return ok
# Main program
......
Markdown is supported
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