Skip to content
Merged
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
13 changes: 10 additions & 3 deletions src/zeroconf/_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,19 @@ def _has_mcast_within_one_quarter_ttl(self, record: DNSRecord) -> bool:
SHOULD instead multicast the response so as to keep all the peer
caches up to date
"""
maybe_entry = self._cache.async_get_unique(cast(_UniqueRecordsType, record))
if TYPE_CHECKING:
record = cast(_UniqueRecordsType, record)
maybe_entry = self._cache.async_get_unique(record)
return bool(maybe_entry and maybe_entry.is_recent(self._now))

def _has_mcast_record_in_last_second(self, record: DNSRecord) -> bool:
"""Check if an answer was seen in the last second.
Protect the network against excessive packet flooding
https://datatracker.ietf.org/doc/html/rfc6762#section-14
"""
maybe_entry = self._cache.async_get_unique(cast(_UniqueRecordsType, record))
if TYPE_CHECKING:
record = cast(_UniqueRecordsType, record)
maybe_entry = self._cache.async_get_unique(record)
return bool(maybe_entry and self._now - maybe_entry.created < _ONE_SECOND)


Expand Down Expand Up @@ -403,7 +407,10 @@ def async_updates_from_response(self, msg: DNSIncoming) -> None:
if record.unique: # https://tools.ietf.org/html/rfc6762#section-10.2
unique_types.add((record.name, record.type, record.class_))

maybe_entry = self.cache.async_get_unique(cast(_UniqueRecordsType, record))
if TYPE_CHECKING:
record = cast(_UniqueRecordsType, record)

maybe_entry = self.cache.async_get_unique(record)
if not record.is_expired(now):
if maybe_entry is not None:
maybe_entry.reset_ttl(record)
Expand Down