network — DNS resolution utilities

This module uses DNSPython to resolve SRV records.

Querying SRV records

coroutine aioxmpp.network.find_xmpp_host_addr(loop, domain, attempts=3)[source]
aioxmpp.network.lookup_srv(domain, service, transport=b'tcp', **kwargs)[source]

Look up and format the SRV records for the given service over transport at the given domain.

Keyword arguments are passed to repeated_query().

Returns a list of tuples (prio, weight, (hostname, port)), where hostname is a IDNA-encoded bytes object containing the hostname obtained from the SRV record. The other fields are also those obtained from the SRV record.

If the query returns an empty result, None is returned.

If any of the SRV records indicates the . host name (the root name), the domain indicates that the service is not available and ValueError is raised.

aioxmpp.network.repeated_query(qname, rdtype, nattempts=3, resolver=None, require_ad=False)[source]

Repeatedly fire a DNS query until either the number of allowed attempts (nattempts) is excedeed or a result is found.

qname must be the (IDNA encoded, as bytes) name to query, rdtype the record type to query for. If resolver is not None, it must be a DNSPython dns.resolver.Resolver instance; if it is None, the current default resolver is used.

If require_ad is True, the peer resolver is asked to do DNSSEC validation and if the AD flag is missing in the response, ValueError is raised.

The resolution automatically starts using the TCP transport after the first attempt.

If no result is received before the number of allowed attempts is exceeded, TimeoutError is raised.

Return the result set or None if the domain does not exist.

Ordering SRV records

aioxmpp.network.group_and_order_srv_records(all_records, rng=None)[source]

Order a list of SRV record information (as returned by lookup_srv()) and group and order them as specified by the RFC.

Return an iterable, yielding each (hostname, port) tuple inside the SRV records in the order specified by the RFC. For hosts with the same priority, the given rng implementation is used (if none is given, the random module is used).