Skip to content

Commit

Permalink
fix: small internal typing cleanups (#1180)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Jun 5, 2023
1 parent dbd8018 commit f03e511
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/zeroconf/_handlers.py
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

0 comments on commit f03e511

Please sign in to comment.