Commit 2a50125d authored by Alexandre's avatar Alexandre
Browse files

Use a parent Request class

parent 9def6c35
......@@ -173,23 +173,25 @@ class CustomException(Exception):
pass
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
......@@ -370,6 +372,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)
......@@ -469,6 +472,7 @@ class ConnectionDoH(Connection):
self.buffer.close()
def send_and_receive(self, request):
request.to_wire()
self.prepare(request)
self.perform()
self.receive(request)
......
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