Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions src/zeroconf/_protocol/outgoing.pxd
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

import cython

from .._dns cimport DNSEntry, DNSQuestion, DNSRecord
from .._cache cimport DNSCache
from .._dns cimport DNSEntry, DNSPointer, DNSQuestion, DNSRecord
from .incoming cimport DNSIncoming


Expand All @@ -14,6 +15,7 @@ cdef cython.uint _FLAGS_TC
cdef cython.uint _MAX_MSG_ABSOLUTE
cdef cython.uint _MAX_MSG_TYPICAL

cdef object TYPE_CHECKING

cdef class DNSOutgoing:

Expand Down Expand Up @@ -70,13 +72,31 @@ cdef class DNSOutgoing:
cpdef write_short(self, object value)

@cython.locals(
questions_offset=cython.uint,
answer_offset=cython.uint,
authority_offset=cython.uint,
additional_offset=cython.uint,
questions_written=cython.uint,
answers_written=cython.uint,
authorities_written=cython.uint,
additionals_written=cython.uint,
questions_offset=object,
answer_offset=object,
authority_offset=object,
additional_offset=object,
questions_written=object,
answers_written=object,
authorities_written=object,
additionals_written=object,
)
cdef _packets(self)

cpdef add_question_or_all_cache(self, DNSCache cache, object now, str name, object type_, object class_)

cpdef add_question_or_one_cache(self, DNSCache cache, object now, str name, object type_, object class_)

cpdef add_question(self, DNSQuestion question)

cpdef add_answer(self, DNSIncoming inp, DNSRecord record)

cpdef add_answer_at_time(self, DNSRecord record, object now)

cpdef add_authorative_answer(self, DNSPointer record)

cpdef add_additional_answer(self, DNSRecord record)

cpdef is_query(self)

cpdef is_response(self)
12 changes: 7 additions & 5 deletions src/zeroconf/_protocol/outgoing.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import enum
import logging
from typing import Dict, List, Optional, Sequence, Tuple, Union
from typing import TYPE_CHECKING, Dict, List, Optional, Sequence, Tuple, Union

from .._cache import DNSCache
from .._dns import DNSPointer, DNSQuestion, DNSRecord
Expand Down Expand Up @@ -176,7 +176,7 @@ def add_additional_answer(self, record: DNSRecord) -> None:
self.additionals.append(record)

def add_question_or_one_cache(
self, cache: DNSCache, now: float, name: str, type_: int, class_: int
self, cache: DNSCache, now: float_, name: str_, type_: int_, class_: int_
) -> None:
"""Add a question if it is not already cached."""
cached_entry = cache.get_by_details(name, type_, class_)
Expand All @@ -186,7 +186,7 @@ def add_question_or_one_cache(
self.add_answer_at_time(cached_entry, now)

def add_question_or_all_cache(
self, cache: DNSCache, now: float, name: str, type_: int, class_: int
self, cache: DNSCache, now: float_, name: str_, type_: int_, class_: int_
) -> None:
"""Add a question if it is not already cached.
This is currently only used for IPv6 addresses.
Expand Down Expand Up @@ -223,7 +223,8 @@ def _write_int(self, value: Union[float, int]) -> None:

def write_string(self, value: bytes) -> None:
"""Writes a string to the packet"""
assert isinstance(value, bytes)
if TYPE_CHECKING:
assert isinstance(value, bytes)
self.data.append(value)
self.size += len(value)

Expand All @@ -237,7 +238,8 @@ def _write_utf(self, s: str) -> None:
self.write_string(utfstr)

def write_character_string(self, value: bytes) -> None:
assert isinstance(value, bytes)
if TYPE_CHECKING:
assert isinstance(value, bytes)
length = len(value)
if length > 256:
raise NamePartTooLongException
Expand Down