Read a DNS message from a UDP socket. *sock*, a ``dns.asyncbackend.DatagramSocket``. See :py:func:`dns.query.receive_udp()` for the documentation of the other parameters, and exceptions. Returns a ``(dns.message.Message, float, tuple)`` tuple of the received message, the recei
(
sock: dns.asyncbackend.DatagramSocket,
destination: Any | None = None,
expiration: float | None = None,
ignore_unexpected: bool = False,
one_rr_per_rrset: bool = False,
keyring: Dict[dns.name.Name, dns.tsig.Key] | None = None,
request_mac: bytes | None = b"",
ignore_trailing: bool = False,
raise_on_truncation: bool = False,
ignore_errors: bool = False,
query: dns.message.Message | None = None,
)
| 119 | |
| 120 | |
| 121 | async def receive_udp( |
| 122 | sock: dns.asyncbackend.DatagramSocket, |
| 123 | destination: Any | None = None, |
| 124 | expiration: float | None = None, |
| 125 | ignore_unexpected: bool = False, |
| 126 | one_rr_per_rrset: bool = False, |
| 127 | keyring: Dict[dns.name.Name, dns.tsig.Key] | None = None, |
| 128 | request_mac: bytes | None = b"", |
| 129 | ignore_trailing: bool = False, |
| 130 | raise_on_truncation: bool = False, |
| 131 | ignore_errors: bool = False, |
| 132 | query: dns.message.Message | None = None, |
| 133 | ) -> Any: |
| 134 | """Read a DNS message from a UDP socket. |
| 135 | |
| 136 | *sock*, a ``dns.asyncbackend.DatagramSocket``. |
| 137 | |
| 138 | See :py:func:`dns.query.receive_udp()` for the documentation of the other |
| 139 | parameters, and exceptions. |
| 140 | |
| 141 | Returns a ``(dns.message.Message, float, tuple)`` tuple of the received message, the |
| 142 | received time, and the address where the message arrived from. |
| 143 | """ |
| 144 | |
| 145 | wire = b"" |
| 146 | while True: |
| 147 | (wire, from_address) = await sock.recvfrom(65535, _timeout(expiration)) |
| 148 | if not _matches_destination( |
| 149 | sock.family, from_address, destination, ignore_unexpected |
| 150 | ): |
| 151 | continue |
| 152 | received_time = time.time() |
| 153 | try: |
| 154 | r = dns.message.from_wire( |
| 155 | wire, |
| 156 | keyring=keyring, |
| 157 | request_mac=request_mac, |
| 158 | one_rr_per_rrset=one_rr_per_rrset, |
| 159 | ignore_trailing=ignore_trailing, |
| 160 | raise_on_truncation=raise_on_truncation, |
| 161 | ) |
| 162 | except dns.message.Truncated as e: |
| 163 | # See the comment in query.py for details. |
| 164 | if ( |
| 165 | ignore_errors |
| 166 | and query is not None |
| 167 | and not query.is_response(e.message()) |
| 168 | ): |
| 169 | continue |
| 170 | else: |
| 171 | raise |
| 172 | except Exception: |
| 173 | if ignore_errors: |
| 174 | continue |
| 175 | else: |
| 176 | raise |
| 177 | if ignore_errors and query is not None and not query.is_response(r): |
| 178 | continue |
no test coverage detected
searching dependent graphs…