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
8 changes: 8 additions & 0 deletions src/zeroconf/_cache.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ cdef class DNSCache:
cdef public cython.dict cache
cdef public cython.dict service_cache

cpdef async_add_records(self, object entries)

cpdef async_remove_records(self, object entries)

cpdef async_get_unique(self, DNSRecord entry)

@cython.locals(
records=cython.dict,
record=DNSRecord,
Expand All @@ -33,6 +39,8 @@ cdef class DNSCache:

cdef _async_remove(self, DNSRecord record)

cpdef async_mark_unique_records_older_than_1s_to_expire(self, object unique_types, object answers, object now)

@cython.locals(
record=DNSRecord,
)
Expand Down
16 changes: 12 additions & 4 deletions src/zeroconf/_handlers/record_manager.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,23 @@ from .._protocol.incoming cimport DNSIncoming
cdef cython.float _DNS_PTR_MIN_TTL
cdef object _ADDRESS_RECORD_TYPES
cdef object RecordUpdate
cdef object TYPE_CHECKING
cdef object _TYPE_PTR

cdef class RecordManager:

cdef object zc
cdef DNSCache cache
cdef cython.list listeners
cdef public object zc
cdef public DNSCache cache
cdef public cython.list listeners

cpdef async_updates(self, object now, object records)

cpdef async_updates_complete(self, object notify)

@cython.locals(
cache=DNSCache,
record=DNSRecord
record=DNSRecord,
maybe_entry=DNSRecord,
now_float=cython.float
)
cpdef async_updates_from_response(self, DNSIncoming msg)
12 changes: 8 additions & 4 deletions src/zeroconf/_handlers/record_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
if TYPE_CHECKING:
from .._core import Zeroconf

_float = float


class RecordManager:
"""Process records into the cache and notify listeners."""
Expand All @@ -45,7 +47,7 @@ def __init__(self, zeroconf: 'Zeroconf') -> None:
self.cache = zeroconf.cache
self.listeners: List[RecordUpdateListener] = []

def async_updates(self, now: float, records: List[RecordUpdate]) -> None:
def async_updates(self, now: _float, records: List[RecordUpdate]) -> None:
"""Used to notify listeners of new information that has updated
a record.

Expand Down Expand Up @@ -81,6 +83,7 @@ def async_updates_from_response(self, msg: DNSIncoming) -> None:
other_adds: List[DNSRecord] = []
removes: Set[DNSRecord] = set()
now = msg.now
now_float = now
unique_types: Set[Tuple[str, int, int]] = set()
cache = self.cache

Expand Down Expand Up @@ -108,11 +111,11 @@ def async_updates_from_response(self, msg: DNSIncoming) -> None:
record = cast(_UniqueRecordsType, record)

maybe_entry = cache.async_get_unique(record)
if not record.is_expired(now):
if not record.is_expired(now_float):
if maybe_entry is not None:
maybe_entry.reset_ttl(record)
else:
if record.type in _ADDRESS_RECORD_TYPES:
if record_type in _ADDRESS_RECORD_TYPES:
address_adds.append(record)
else:
other_adds.append(record)
Expand Down Expand Up @@ -146,7 +149,8 @@ def async_updates_from_response(self, msg: DNSIncoming) -> None:
new = False
if other_adds or address_adds:
new = cache.async_add_records(address_adds)
new |= cache.async_add_records(other_adds)
if cache.async_add_records(other_adds):
new = True
# Removes are processed last since
# ServiceInfo could generate an un-needed query
# because the data was not yet populated.
Expand Down