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
40 changes: 15 additions & 25 deletions zeroconf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,21 +882,15 @@ class State(enum.Enum):
init = 0
finished = 1

@staticmethod
def is_type_unique(type_: int) -> bool:
return type_ == _TYPE_TXT or type_ == _TYPE_SRV or type_ == _TYPE_A or type_ == _TYPE_AAAA

def add_question(self, record: DNSQuestion) -> None:
"""Adds a question"""
self.questions.append(record)

def add_answer(self, inp: DNSIncoming, record: DNSRecord) -> None:

"""Only support for unique answers"""
if (
record.type == _TYPE_TXT
or record.type == _TYPE_SRV
or record.type == _TYPE_A
or record.type == _TYPE_AAAA
):
assert record.unique

"""Adds an answer"""
if not record.suppressed_by(inp):
self.add_answer_at_time(record, 0)
Expand All @@ -905,13 +899,7 @@ def add_answer_at_time(self, record: Optional[DNSRecord], now: Union[float, int]
"""Adds an answer if it does not expire by a certain time"""
if record is not None:

"""Only support for unique answers"""
if (
record.type == _TYPE_TXT
or record.type == _TYPE_SRV
or record.type == _TYPE_A
or record.type == _TYPE_AAAA
):
if self.is_type_unique(record.type):
assert record.unique

if now == 0 or not record.is_expired(now):
Expand Down Expand Up @@ -957,13 +945,7 @@ def add_additional_answer(self, record: DNSRecord) -> None:
o All address records (type "A" and "AAAA") named in the SRV rdata.

"""
"""Only support for unique answers"""
if (
record.type == _TYPE_TXT
or record.type == _TYPE_SRV
or record.type == _TYPE_A
or record.type == _TYPE_AAAA
):
if self.is_type_unique(record.type):
assert record.unique

self.additionals.append(record)
Expand Down Expand Up @@ -2452,8 +2434,15 @@ def handle_response(self, msg: DNSIncoming) -> None:
are held in the cache, and listeners are notified."""
now = current_time_millis()
for record in msg.answers:

updated = True

if record.unique: # https://tools.ietf.org/html/rfc6762#section-10.2
for entry in self.cache.entries():

if entry == record:
updated = False

if DNSEntry.__eq__(entry, record) and (record.created - entry.created > 1000):
self.cache.remove(entry)

Expand All @@ -2464,7 +2453,8 @@ def handle_response(self, msg: DNSIncoming) -> None:
maybe_entry.reset_ttl(record)
else:
self.cache.add(record)
self.update_record(now, record)
if updated:
self.update_record(now, record)
else:
if maybe_entry is not None:
self.update_record(now, record)
Expand Down
1 change: 1 addition & 0 deletions zeroconf/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,7 @@ def mock_incoming_msg(service_state_change: r.ServiceStateChange) -> r.DNSIncomi
service_updated_event.clear()
service_text = b'path=/~humingchun/'
zeroconf.handle_response(mock_incoming_msg(r.ServiceStateChange.Updated))
zeroconf.handle_response(mock_incoming_msg(r.ServiceStateChange.Updated))
service_updated_event.wait(1)
assert service_added is True
assert service_updated_count == 2
Expand Down