Try to update the resolver's nameservers using Discovery of Designated Resolvers (DDR). If successful, the resolver will subsequently use DNS-over-HTTPS or DNS-over-TLS for future queries. *lifetime*, a float, is the maximum time to spend attempting DDR. The default
(self, lifetime: float = 5.0)
| 1495 | # pylint: enable=redefined-outer-name |
| 1496 | |
| 1497 | def try_ddr(self, lifetime: float = 5.0) -> None: |
| 1498 | """Try to update the resolver's nameservers using Discovery of Designated |
| 1499 | Resolvers (DDR). If successful, the resolver will subsequently use |
| 1500 | DNS-over-HTTPS or DNS-over-TLS for future queries. |
| 1501 | |
| 1502 | *lifetime*, a float, is the maximum time to spend attempting DDR. The default |
| 1503 | is 5 seconds. |
| 1504 | |
| 1505 | If the SVCB query is successful and results in a non-empty list of nameservers, |
| 1506 | then the resolver's nameservers are set to the returned servers in priority |
| 1507 | order. |
| 1508 | |
| 1509 | The current implementation does not use any address hints from the SVCB record, |
| 1510 | nor does it resolve addresses for the SCVB target name, rather it assumes that |
| 1511 | the bootstrap nameserver will always be one of the addresses and uses it. |
| 1512 | A future revision to the code may offer fuller support. The code verifies that |
| 1513 | the bootstrap nameserver is in the Subject Alternative Name field of the |
| 1514 | TLS certficate. |
| 1515 | """ |
| 1516 | try: |
| 1517 | expiration = time.time() + lifetime |
| 1518 | answer = self.resolve( |
| 1519 | dns._ddr._local_resolver_name, "SVCB", lifetime=lifetime |
| 1520 | ) |
| 1521 | timeout = dns.query._remaining(expiration) |
| 1522 | nameservers = dns._ddr._get_nameservers_sync(answer, timeout) |
| 1523 | if len(nameservers) > 0: |
| 1524 | self.nameservers = nameservers |
| 1525 | except Exception: # pragma: no cover |
| 1526 | pass |
| 1527 | |
| 1528 | |
| 1529 | #: The default resolver. |