@@ -23,6 +23,7 @@
|
23 | 23 | import itertools |
24 | 24 | import random |
25 | 25 | from collections import deque |
| 26 | +from operator import attrgetter |
26 | 27 | from typing import ( |
27 | 28 | TYPE_CHECKING, |
28 | 29 | Dict, |
|
71 | 72 | _MULTICAST_DELAY_RANDOM_INTERVAL = (20, 120) |
72 | 73 | _RESPOND_IMMEDIATE_TYPES = {_TYPE_NSEC, _TYPE_SRV, *_ADDRESS_RECORD_TYPES} |
73 | 74 | |
| 75 | +NAME_GETTER = attrgetter('name') |
| 76 | + |
74 | 77 | |
75 | 78 | class QuestionAnswers(NamedTuple): |
76 | 79 | ucast: _AnswerWithAdditionalsType |
@@ -109,13 +112,13 @@ def construct_outgoing_unicast_answers(
|
109 | 112 | |
110 | 113 | def _add_answers_additionals(out: DNSOutgoing, answers: _AnswerWithAdditionalsType) -> None: |
111 | 114 | # Find additionals and suppress any additionals that are already in answers |
112 | | -sending: Set[DNSRecord] = set(answers.keys()) |
| 115 | +sending: Set[DNSRecord] = set(answers) |
113 | 116 | # Answers are sorted to group names together to increase the chance |
114 | 117 | # that similar names will end up in the same packet and can reduce the |
115 | 118 | # overall size of the outgoing response via name compression |
116 | | -for answer, additionals in sorted(answers.items(), key=lambda kv: kv[0].name): |
| 119 | +for answer in sorted(answers, key=NAME_GETTER): |
117 | 120 | out.add_answer_at_time(answer, 0) |
118 | | -for additional in additionals: |
| 121 | +for additional in answers[answer]: |
119 | 122 | if additional not in sending: |
120 | 123 | out.add_additional_answer(additional) |
121 | 124 | sending.add(additional) |
|