Commit f95c8dc7 authored by Alexandre's avatar Alexandre
Browse files

Define a parent Request class

parent c5341a67
......@@ -170,23 +170,25 @@ def validate_hostname(hostname, cert):
return False
class RequestDoT:
class Request:
def __init__(self, qname, qtype=rtype, use_edns=edns, want_dnssec=dnssec):
self.message = dns.message.make_query(qname, dns.rdatatype.from_text(qtype), use_edns=use_edns, want_dnssec=want_dnssec)
self.message.flags |= dns.flags.AD # Ask for validation
def to_wire(self):
self.data = self.message.to_wire()
class RequestDoT(Request):
def check_response(self):
if self.response.id != self.message.id:
raise Exception("The ID in the answer does not match the one in the query")
class RequestDoH:
class RequestDoH(Request):
def __init__(self, qname, qtype=rtype, use_edns=edns, want_dnssec=dnssec):
self.message = dns.message.make_query(qname, dns.rdatatype.from_text(qtype), use_edns=use_edns, want_dnssec=want_dnssec)
Request.__init__(self, qname, qtype=rtype, use_edns=edns, want_dnssec=dnssec)
self.message.id = 0 # DoH requests that
self.message.flags |= dns.flags.AD # Ask for validation
self.data = self.message.to_wire()
self.post = False
self.head = False
......@@ -368,6 +370,7 @@ class ConnectionDoT(Connection):
request.rcode = True
def send_and_receive(self, request):
request.to_wire()
self.send_data(request.data)
self.receive_data(request)
......@@ -470,6 +473,7 @@ class ConnectionDoH(Connection):
self.buffer.close()
def send_and_receive(self, request):
request.to_wire()
self.prepare(request)
self.perform()
self.receive(request)
......
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