FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat: speed up generating answers (#1262) · python-zeroconf/python-zeroconf@50a8f06 · GitHub

Repository navigation

Commit 50a8f06

Browse files
authored
feat: speed up generating answers (#1262)
1 parent 24f276e commit 50a8f06

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

‎build_ext.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def build(setup_kwargs: Any) -> None:
2929
"src/zeroconf/_listener.py",
3030
"src/zeroconf/_protocol/incoming.py",
3131
"src/zeroconf/_protocol/outgoing.py",
32+
"src/zeroconf/_handlers/answers.py",
3233
"src/zeroconf/_handlers/record_manager.py",
3334
"src/zeroconf/_handlers/query_handler.py",
3435
"src/zeroconf/_services/registry.py",

‎src/zeroconf/_handlers/answers.pxd‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
import cython
3+
4+
from .._protocol.outgoing cimport DNSOutgoing
5+
6+
7+
cdef object _FLAGS_QR_RESPONSE_AA
8+
cdef object NAME_GETTER
9+
10+
cpdef construct_outgoing_multicast_answers(cython.dict answers)
11+
12+
cpdef construct_outgoing_unicast_answers(
13+
cython.dict answers, object ucast_source, cython.list questions, object id_
14+
)
15+
16+
cdef _add_answers_additionals(DNSOutgoing out, cython.dict answers)

‎src/zeroconf/_handlers/answers.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@
2929

3030
_AnswerWithAdditionalsType = Dict[DNSRecord, Set[DNSRecord]]
3131

32+
int_ = int
33+
3234

3335
MULTICAST_DELAY_RANDOM_INTERVAL = (20, 120)
3436

3537
NAME_GETTER = attrgetter('name')
3638

39+
_FLAGS_QR_RESPONSE_AA = _FLAGS_QR_RESPONSE | _FLAGS_AA
40+
3741

3842
class QuestionAnswers(NamedTuple):
3943
ucast: _AnswerWithAdditionalsType
@@ -52,16 +56,16 @@ class AnswerGroup(NamedTuple):
5256

5357
def construct_outgoing_multicast_answers(answers: _AnswerWithAdditionalsType) -> DNSOutgoing:
5458
"""Add answers and additionals to a DNSOutgoing."""
55-
out = DNSOutgoing(_FLAGS_QR_RESPONSE | _FLAGS_AA, multicast=True)
59+
out = DNSOutgoing(_FLAGS_QR_RESPONSE_AA, True)
5660
_add_answers_additionals(out, answers)
5761
return out
5862

5963

6064
def construct_outgoing_unicast_answers(
61-
answers: _AnswerWithAdditionalsType, ucast_source: bool, questions: List[DNSQuestion], id_: int
65+
answers: _AnswerWithAdditionalsType, ucast_source: bool, questions: List[DNSQuestion], id_: int_
6266
) -> DNSOutgoing:
6367
"""Add answers and additionals to a DNSOutgoing."""
64-
out = DNSOutgoing(_FLAGS_QR_RESPONSE | _FLAGS_AA, multicast=False, id_=id_)
68+
out = DNSOutgoing(_FLAGS_QR_RESPONSE_AA, False, id_)
6569
# Adding the questions back when the source is legacy unicast behavior
6670
if ucast_source:
6771
for question in questions:

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL