/usr/lib/python3/dist-packages/twisted/names/__pycache__
Edit: /usr/lib/python3/dist-packages/twisted/names/__pycache__/server.cpython-310.pyc (21175B)
o
bV @ sJ d Z ddlZddlmZ ddlmZmZ ddlmZ G dd dej Z
dS )a`
Async DNS server
Future plans:
- Better config file format maybe
- Make sure to differentiate between different classes
- notice truncation bit
Important: No additional processing is done on some of the record types.
This violates the most basic RFC and is just plain annoying
for resolvers to deal with. Fix it.
@author: Jp Calderone
N)protocol)dnsresolve)logc @ s e Zd ZdZejZdZejZ d$ddZ
dd Zdd Zd
d Z
dd
Zdd ZejdddfddZdd Zdd Zdd Zdd Zdd Zdd Zdd Zd%d d!Zd"d# ZdS )&DNSServerFactorya
Server factory and tracker for L{DNSProtocol} connections. This class also
provides records for responses to DNS queries.
@ivar cache: A L{Cache
} instance whose
C{cacheResult} method is called when a response is received from one of
C{clients}. Defaults to L{None} if no caches are specified. See
C{caches} of L{__init__} for more details.
@type cache: L{Cache} or L{None}
@ivar canRecurse: A flag indicating whether this server is capable of
performing recursive DNS resolution.
@type canRecurse: L{bool}
@ivar resolver: A L{resolve.ResolverChain} containing an ordered list of
C{authorities}, C{caches} and C{clients} to which queries will be
dispatched.
@type resolver: L{resolve.ResolverChain}
@ivar verbose: See L{__init__}
@ivar connections: A list of all the connected L{DNSProtocol} instances
using this object as their controller.
@type connections: C{list} of L{DNSProtocol} instances
@ivar protocol: A callable used for building a DNS stream protocol. Called
by L{DNSServerFactory.buildProtocol} and passed the L{DNSServerFactory}
instance as the one and only positional argument. Defaults to
L{dns.DNSProtocol}.
@type protocol: L{IProtocolFactory} constructor
@ivar _messageFactory: A response message constructor with an initializer
signature matching L{dns.Message.__init__}.
@type _messageFactory: C{callable}
Nr c C sn g }|dur| | |dur| | |dur| | | | _t|| _|| _|r2|d | _g | _dS )a
@param authorities: Resolvers which provide authoritative answers.
@type authorities: L{list} of L{IResolver} providers
@param caches: Resolvers which provide cached non-authoritative
answers. The first cache instance is assigned to
C{DNSServerFactory.cache} and its C{cacheResult} method will be
called when a response is received from one of C{clients}.
@type caches: L{list} of L{Cache} instances
@param clients: Resolvers which are capable of performing recursive DNS
lookups.
@type clients: L{list} of L{IResolver} providers
@param verbose: An integer controlling the verbosity of logging of
queries and responses. Default is C{0} which means no logging. Set
to C{2} to enable logging of full query and response messages.
@type verbose: L{int}
N)extend
canRecurser
ResolverChainresolververbosecacheconnections)selfauthoritiescachesclientsr resolvers r 6/usr/lib/python3/dist-packages/twisted/names/server.py__init__E s
zDNSServerFactory.__init__c O s" | j dkrtj|i | dS dS )z
Log a message only if verbose logging is enabled.
@param args: Positional arguments which will be passed to C{log.msg}
@param kwargs: Keyword arguments which will be passed to C{log.msg}
r N)r r msg)r argskwargsr r r _verboseLogh s
zDNSServerFactory._verboseLogc C s | | }| |_|S N)r factory)r addrpr r r
buildProtocolr s
zDNSServerFactory.buildProtocolc C | j | dS )z
Track a newly connected L{DNSProtocol}.
@param protocol: The protocol instance to be tracked.
@type protocol: L{dns.DNSProtocol}
N)r appendr r r r r connectionMadew s zDNSServerFactory.connectionMadec C r )z
Stop tracking a no-longer connected L{DNSProtocol}.
@param protocol: The tracked protocol instance to be which has been
lost.
@type protocol: L{dns.DNSProtocol}
N)r remover" r r r connectionLost s zDNSServerFactory.connectionLostc C s | j dkrCddd |jD }ddd |jD }ddd |jD }|s.td ntd| td | td
| |du rM|| n||| | dt |j
dS )
a]
Send a response C{message} to a given C{address} via the supplied
C{protocol}.
Message payload will be logged if C{DNSServerFactory.verbose} is C{>1}.
@param protocol: The DNS protocol instance to which to send the message.
@type protocol: L{dns.DNSDatagramProtocol} or L{dns.DNSProtocol}
@param message: The DNS message to be sent.
@type message: L{dns.Message}
@param address: The address to which the message will be sent or L{None}
if C{protocol} is a stream protocol.
@type address: L{tuple} or L{None}
c S g | ]}t |jqS r strpayload.0ar r r