diff --git a/src/zeroconf/_dns.pxd b/src/zeroconf/_dns.pxd index 126fe451..afcb1985 100644 --- a/src/zeroconf/_dns.pxd +++ b/src/zeroconf/_dns.pxd @@ -136,3 +136,5 @@ cdef class DNSRRSet: record_sets=cython.list, ) cdef cython.dict _get_lookup(self) + + cpdef cython.set lookup_set(self) diff --git a/src/zeroconf/_dns.py b/src/zeroconf/_dns.py index 73b0c751..4c015eb3 100644 --- a/src/zeroconf/_dns.py +++ b/src/zeroconf/_dns.py @@ -22,7 +22,7 @@ import enum import socket -from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union, cast +from typing import TYPE_CHECKING, Any, Dict, List, Optional, Set, Union, cast from ._exceptions import AbstractMethodException from ._utils.net import _is_v6_address @@ -533,6 +533,10 @@ def lookup(self) -> Dict[DNSRecord, float]: """Return the lookup table.""" return self._get_lookup() + def lookup_set(self) -> Set[DNSRecord]: + """Return the lookup table as aset.""" + return set(self._get_lookup()) + def _get_lookup(self) -> Dict[DNSRecord, float]: """Return the lookup table, building it if needed.""" if self._lookup is None: diff --git a/src/zeroconf/_handlers/query_handler.pxd b/src/zeroconf/_handlers/query_handler.pxd index afbaab95..1f1e4da8 100644 --- a/src/zeroconf/_handlers/query_handler.pxd +++ b/src/zeroconf/_handlers/query_handler.pxd @@ -59,7 +59,7 @@ cdef class QueryHandler: cdef _add_address_answers(self, str lower_name, cython.dict answer_set, DNSRRSet known_answers, cython.uint type_) @cython.locals(question_lower_name=str, type_=cython.uint, service=ServiceInfo) - cdef _answer_question(self, DNSQuestion question, DNSRRSet known_answers) + cdef cython.dict _answer_question(self, DNSQuestion question, DNSRRSet known_answers) @cython.locals( msg=DNSIncoming, @@ -68,4 +68,4 @@ cdef class QueryHandler: known_answers=DNSRRSet, known_answers_set=cython.set, ) - cpdef async_response(self, cython.list msgs, object unicast_source) + cpdef async_response(self, cython.list msgs, cython.bint unicast_source) diff --git a/src/zeroconf/_handlers/query_handler.py b/src/zeroconf/_handlers/query_handler.py index 66deab43..f4243021 100644 --- a/src/zeroconf/_handlers/query_handler.py +++ b/src/zeroconf/_handlers/query_handler.py @@ -268,12 +268,12 @@ def async_response( # pylint: disable=unused-argument for msg in msgs: for question in msg.questions: - if not question.unicast: + if not question.unique: # unique and unicast are the same flag if not known_answers_set: # pragma: no branch - known_answers_set = set(known_answers.lookup) + known_answers_set = known_answers.lookup_set() self.question_history.add_question_at_time(question, msg.now, known_answers_set) answer_set = self._answer_question(question, known_answers) - if not ucast_source and question.unicast: + if not ucast_source and question.unique: # unique and unicast are the same flag query_res.add_qu_question_response(answer_set) continue if ucast_source: