Skip to content

Commit 3c1842f

Browse files
committed
Add setter for DNSQuestion to easily make a QU question
Closes #703
1 parent f3eeecd commit 3c1842f

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

tests/test_handlers.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ def _validate_complete_response(query, out):
415415
# With QU should respond to only unicast when the answer has been recently multicast
416416
query = r.DNSOutgoing(const._FLAGS_QR_QUERY)
417417
question = r.DNSQuestion(info.type, const._TYPE_PTR, const._CLASS_IN)
418-
question.unique = True # Set the QU bit
418+
question.unicast = True # Set the QU bit
419419
assert question.unicast is True
420420
query.add_question(question)
421421

@@ -429,7 +429,7 @@ def _validate_complete_response(query, out):
429429
# With QU should respond to only multicast since the response hasn't been seen since 75% of the ttl
430430
query = r.DNSOutgoing(const._FLAGS_QR_QUERY)
431431
question = r.DNSQuestion(info.type, const._TYPE_PTR, const._CLASS_IN)
432-
question.unique = True # Set the QU bit
432+
question.unicast = True # Set the QU bit
433433
assert question.unicast is True
434434
query.add_question(question)
435435
unicast_out, multicast_out = zc.query_handler.response(
@@ -441,7 +441,7 @@ def _validate_complete_response(query, out):
441441
# With QU set and an authorative answer (probe) should respond to both unitcast and multicast since the response hasn't been seen since 75% of the ttl
442442
query = r.DNSOutgoing(const._FLAGS_QR_QUERY)
443443
question = r.DNSQuestion(info.type, const._TYPE_PTR, const._CLASS_IN)
444-
question.unique = True # Set the QU bit
444+
question.unicast = True # Set the QU bit
445445
assert question.unicast is True
446446
query.add_question(question)
447447
query.add_authorative_answer(info2.dns_pointer())
@@ -455,7 +455,7 @@ def _validate_complete_response(query, out):
455455
# With the cache repopulated; should respond to only unicast when the answer has been recently multicast
456456
query = r.DNSOutgoing(const._FLAGS_QR_QUERY)
457457
question = r.DNSQuestion(info.type, const._TYPE_PTR, const._CLASS_IN)
458-
question.unique = True # Set the QU bit
458+
question.unicast = True # Set the QU bit
459459
assert question.unicast is True
460460
query.add_question(question)
461461
unicast_out, multicast_out = zc.query_handler.response(
@@ -743,7 +743,7 @@ def test_qu_response_only_sends_additionals_if_sends_answer():
743743
# even if the additional has not been recently multicast
744744
query = r.DNSOutgoing(const._FLAGS_QR_QUERY)
745745
question = r.DNSQuestion(info.type, const._TYPE_PTR, const._CLASS_IN)
746-
question.unique = True # Set the QU bit
746+
question.unicast = True # Set the QU bit
747747
assert question.unicast is True
748748
query.add_question(question)
749749

@@ -763,7 +763,7 @@ def test_qu_response_only_sends_additionals_if_sends_answer():
763763
# even if the additional has not been recently multicast
764764
query = r.DNSOutgoing(const._FLAGS_QR_QUERY)
765765
question = r.DNSQuestion(info.type, const._TYPE_PTR, const._CLASS_IN)
766-
question.unique = True # Set the QU bit
766+
question.unicast = True # Set the QU bit
767767
assert question.unicast is True
768768
query.add_question(question)
769769

@@ -783,7 +783,7 @@ def test_qu_response_only_sends_additionals_if_sends_answer():
783783
# than 75% of its ttl remaining
784784
query = r.DNSOutgoing(const._FLAGS_QR_QUERY)
785785
question = r.DNSQuestion(info.type, const._TYPE_PTR, const._CLASS_IN)
786-
question.unique = True # Set the QU bit
786+
question.unicast = True # Set the QU bit
787787
assert question.unicast is True
788788
query.add_question(question)
789789

@@ -803,12 +803,12 @@ def test_qu_response_only_sends_additionals_if_sends_answer():
803803
# than 75% of its ttl remaining
804804
query = r.DNSOutgoing(const._FLAGS_QR_QUERY)
805805
question = r.DNSQuestion(info.type, const._TYPE_PTR, const._CLASS_IN)
806-
question.unique = True # Set the QU bit
806+
question.unicast = True # Set the QU bit
807807
assert question.unicast is True
808808
query.add_question(question)
809809

810810
question = r.DNSQuestion(info2.type, const._TYPE_PTR, const._CLASS_IN)
811-
question.unique = True # Set the QU bit
811+
question.unicast = True # Set the QU bit
812812
assert question.unicast is True
813813
query.add_question(question)
814814
zc.cache.add(info2.dns_pointer()) # Add 100% TTL for info2 to the cache

zeroconf/_dns.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ def unicast(self) -> bool:
124124
"""
125125
return self.unique
126126

127+
@unicast.setter
128+
def unicast(self, value: bool) -> None:
129+
"""Sets the QU bit (not QM)."""
130+
self.unique = value
131+
127132
def __repr__(self) -> str:
128133
"""String representation"""
129134
return "%s[question,%s,%s,%s]" % (

0 commit comments

Comments
 (0)