Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: speed up decoding dns questions when processing incoming data #1168

Merged
merged 2 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/zeroconf/_protocol/incoming.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ from .._dns cimport (
DNSHinfo,
DNSNsec,
DNSPointer,
DNSQuestion,
DNSRecord,
DNSService,
DNSText,
Expand All @@ -48,11 +49,11 @@ cdef class DNSIncoming:

cdef bint _did_read_others
cdef public unsigned int flags
cdef object offset
cdef cython.uint offset
cdef public bytes data
cdef unsigned int _data_len
cdef public cython.dict name_cache
cdef public object questions
cdef public cython.list questions
cdef object _answers
cdef public object id
cdef public cython.uint num_questions
Expand Down
9 changes: 6 additions & 3 deletions src/zeroconf/_protocol/incoming.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,12 @@ def _read_header(self) -> None:

def _read_questions(self) -> None:
"""Reads questions section of packet"""
self.questions = [
DNSQuestion(self._read_name(), *self._unpack(UNPACK_HH, 4)) for _ in range(self.num_questions)
]
for _ in range(self.num_questions):
name = self._read_name()
type_, class_ = UNPACK_HH(self.data, self.offset)
self.offset += 4
question = DNSQuestion(name, type_, class_)
self.questions.append(question)

def _read_character_string(self) -> bytes:
"""Reads a character string from the packet"""
Expand Down