network
— DNS resolution utilities¶
This module uses dns
to handle DNS queries.
Changed in version 0.5.4: The module was completely rewritten in 0.5.4. The documented API stayed mostly the same though.
Configure the resolver¶
New in version 0.5.4: The whole thread-local resolver thing was added in 0.5.4. This includes the magic to re-configure the used resolver when a query fails.
The module uses a thread-local resolver instance. It can be accessed using
get_resolver()
. Re-read of the system-wide resolver configuration can be
forced by calling reconfigure_resolver()
. To configure a custom resolver
instance, use set_resolver()
.
By setting a custom resolver instance, the facilities which automatically reconfigure the resolver whenever DNS timeouts occur are disabled.
Note
Currently, there is no way to set a resolver per XMPP client. If such a way
is desired, feel free to open a bug against aioxmpp
. I cannot really
imagine such a situation, but if you encounter one, please let me know.
-
aioxmpp.network.
get_resolver
()[source]¶ Return the thread-local
dns.resolver.Resolver
instance used byaioxmpp
.
-
aioxmpp.network.
reconfigure_resolver
()[source]¶ Reset the resolver configured for this thread to a fresh instance. This essentially re-reads the system-wide resolver configuration.
If a custom resolver has been set using
set_resolver()
, the flag indicating that no automatic re-configuration shall take place is cleared.
-
aioxmpp.network.
set_resolver
(resolver)[source]¶ Replace the current thread-local resolver (which can be accessed using
get_resolver()
) with resolver.This also sets an internal flag which prohibits the automatic calling of
reconfigure_resolver()
fromrepeated_query()
. To re-allow automatic reconfiguration, callreconfigure_resolver()
.
Querying records¶
In addition to using the dns.resolver.Resolver
instance returned by
get_resolver()
, one can also use repeated_query()
. The latter takes
care of re-trying the query up to a configurable amount of times. It will also
automatically call reconfigure_resolver()
(unless a custom resolver has
been set) if a timeout occurs and switch to TCP if problems persist.
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, therandom
module is used).