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
3 changes: 2 additions & 1 deletion src/zeroconf/_services/browser.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ from .._utils.time cimport current_time_millis, millis_to_seconds
cdef bint TYPE_CHECKING
cdef object cached_possible_types
cdef cython.uint _EXPIRE_REFRESH_TIME_PERCENT
cdef cython.uint _TYPE_PTR
cdef object SERVICE_STATE_CHANGE_ADDED, SERVICE_STATE_CHANGE_REMOVED, SERVICE_STATE_CHANGE_UPDATED

cdef class _DNSPointerOutgoingBucket:
Expand Down Expand Up @@ -58,7 +59,7 @@ cdef class _ServiceBrowserBase(RecordUpdateListener):

cpdef _enqueue_callback(self, object state_change, object type_, object name)

@cython.locals(record=DNSRecord, cache=DNSCache, service=DNSRecord)
@cython.locals(record=DNSRecord, cache=DNSCache, service=DNSRecord, pointer=DNSPointer)
cpdef async_update_records(self, object zc, cython.float now, cython.list records)

cpdef _names_matching_types(self, object types)
Expand Down
16 changes: 9 additions & 7 deletions src/zeroconf/_services/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,24 +404,26 @@ def async_update_records(self, zc: 'Zeroconf', now: float_, records: List[Record
This method will be run in the event loop.
"""
for record_update in records:
record, old_record = record_update
record = record_update[0]
old_record = record_update[1]
record_type = record.type

if record_type is _TYPE_PTR:
if TYPE_CHECKING:
record = cast(DNSPointer, record)
for type_ in self.types.intersection(cached_possible_types(record.name)):
pointer = record
for type_ in self.types.intersection(cached_possible_types(pointer.name)):
if old_record is None:
self._enqueue_callback(SERVICE_STATE_CHANGE_ADDED, type_, record.alias)
elif record.is_expired(now):
self._enqueue_callback(SERVICE_STATE_CHANGE_REMOVED, type_, record.alias)
self._enqueue_callback(SERVICE_STATE_CHANGE_ADDED, type_, pointer.alias)
elif pointer.is_expired(now):
self._enqueue_callback(SERVICE_STATE_CHANGE_REMOVED, type_, pointer.alias)
else:
expire_time = record.get_expiration_time(_EXPIRE_REFRESH_TIME_PERCENT)
expire_time = pointer.get_expiration_time(_EXPIRE_REFRESH_TIME_PERCENT)
self.reschedule_type(type_, now, expire_time)
continue

# If its expired or already exists in the cache it cannot be updated.
if old_record or record.is_expired(now):
if old_record or record.is_expired(now) is True:
continue

if record_type in _ADDRESS_RECORD_TYPES:
Expand Down