§
    Ètºfˆ0  ã                   óž   — d Z ddlmZ ddlmZmZmZ ddlmZ  G d„ d¦  «        Z	 G d„ dej
        ¦  «        Zd	„ Z G d
„ d¦  «        Zdd„ZdS )zÁ
Resolver implementation for querying successive authoritative servers to
lookup a record, starting from the root nameservers.

@author: Jp Calderone

todo::
    robustify it
    documentation
é    )Údefer)ÚcommonÚdnsÚerror)ÚFailurec                   ó   — e Zd ZdZd„ ZdS )Ú_DummyControllerz²
    A do-nothing DNS controller.  This is useful when all messages received
    will be responses to previously issued queries.  Anything else received
    will be ignored.
    c                 ó   — d S ©N© )ÚselfÚargss     úQ/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/names/root.pyÚmessageReceivedz _DummyController.messageReceived   s   € Øˆó    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r	   r	      s-   € € € € € ðð ðð ð ð ð r   r	   c                   ó8   — e Zd ZdZd
d„Zd„ Zd„ Zd„ Zd„ Zd	„ Z	dS )ÚResolverao  
    L{Resolver} implements recursive lookup starting from a specified list of
    root servers.

    @ivar hints: See C{hints} parameter of L{__init__}
    @ivar _maximumQueries: See C{maximumQueries} parameter of L{__init__}
    @ivar _reactor: See C{reactor} parameter of L{__init__}
    @ivar _resolverFactory: See C{resolverFactory} parameter of L{__init__}
    é
   Nc                 óŒ   — t           j                             | ¦  «         || _        || _        || _        |€ddlm} || _        dS )a‡  
        @param hints: A L{list} of L{str} giving the dotted quad
            representation of IP addresses of root servers at which to
            begin resolving names.
        @type hints: L{list} of L{str}

        @param maximumQueries: An optional L{int} giving the maximum
             number of queries which will be attempted to resolve a
             single name.
        @type maximumQueries: L{int}

        @param reactor: An optional L{IReactorTime} and L{IReactorUDP}
             provider to use to bind UDP ports and manage timeouts.
        @type reactor: L{IReactorTime} and L{IReactorUDP} provider

        @param resolverFactory: An optional callable which accepts C{reactor}
             and C{servers} arguments and returns an instance that provides a
             C{queryUDP} method. Defaults to L{twisted.names.client.Resolver}.
        @type resolverFactory: callable
        Nr   ©r   )	r   ÚResolverBaseÚ__init__ÚhintsÚ_maximumQueriesÚ_reactorÚtwisted.names.clientr   Ú_resolverFactory)r   r   ÚmaximumQueriesÚreactorÚresolverFactorys        r   r   zResolver.__init__+   sW   € õ* 	Ô×$Ò$ TÑ*Ô*Ð*ØˆŒ
Ø-ˆÔØˆŒØÐ"ØHÐHÐHÐHÐHÐHØ /ˆÔÐÐr   c                 ó$   — d„ | j         D ¦   «         S )z‚
        Return a list of two-tuples representing the addresses of the root
        servers, as defined by C{self.hints}.
        c                 ó*   — g | ]}|t           j        f‘ŒS r   )r   ÚPORT)Ú.0Úips     r   ú
<listcomp>z#Resolver._roots.<locals>.<listcomp>M   s   € Ð4Ð4Ð4 2�•S”X�Ð4Ð4Ð4r   )r   )r   s    r   Ú_rootszResolver._rootsH   s   € ð
 5Ð4¨¬Ð4Ñ4Ô4Ð4r   c                 ó¤   — |                       || j        ¬¦  «        }|                     |g|¦  «        }|r|                     |j        ¦  «         |S )a­  
        Issue one query and return a L{Deferred} which fires with its response.

        @param query: The query to issue.
        @type query: L{dns.Query}

        @param servers: The servers which might have an answer for this
            query.
        @type servers: L{list} of L{tuple} of L{str} and L{int}

        @param timeout: A timeout on how long to wait for the response.
        @type timeout: L{tuple} of L{int}

        @param filter: A flag indicating whether to filter the results.  If
            C{True}, the returned L{Deferred} will fire with a three-tuple of
            lists of L{twisted.names.dns.RRHeader} (like the return value of
            the I{lookup*} methods of L{IResolver}.  IF C{False}, the result
            will be a L{Message} instance.
        @type filter: L{bool}

        @return: A L{Deferred} which fires with the response or a timeout
            error.
        @rtype: L{Deferred}
        )Úserversr#   )r!   r   ÚqueryUDPÚaddCallbackÚfilterAnswers)r   Úqueryr-   ÚtimeoutÚfilterÚrÚds          r   Ú_queryzResolver._queryO   sT   € ð2 ×!Ò!¨'¸4¼=Ð!ÑIÔIˆØ�JŠJ˜�w Ñ(Ô(ˆØð 	+Ø�MŠM˜!œ/Ñ*Ô*Ð*Øˆr   c                 ó�   — |€d}|                       t          j        |||¦  «        |                      ¦   «         || j        ¦  «        S )z½
        Implement name lookup by recursively discovering the authoritative
        server for the name and then asking it, starting at one of the servers
        in C{self.hints}.
        N)é   é   é   é-   )Ú_discoverAuthorityr   ÚQueryr+   r   )r   ÚnameÚclsÚtyper2   s        r   Ú_lookupzResolver._lookupn   sJ   € ð ˆ?ð %ˆGØ×&Ò&ÝŒI�d˜D #Ñ&Ô&¨¯ª©¬°wÀÔ@Tñ
ô 
ð 	
r   c                 óÄ   — |dk    r!t          t          j        d¦  «        ¦  «        S |                      |||d¦  «        }|                     | j        |||dz
  ¦  «         |S )a#  
        Issue a query to a server and follow a delegation if necessary.

        @param query: The query to issue.
        @type query: L{dns.Query}

        @param servers: The servers which might have an answer for this
            query.
        @type servers: L{list} of L{tuple} of L{str} and L{int}

        @param timeout: A C{tuple} of C{int} giving the timeout to use for this
            query.

        @param queriesLeft: A C{int} giving the number of queries which may
            yet be attempted to answer this query before the attempt will be
            abandoned.

        @return: A L{Deferred} which fires with a three-tuple of lists of
            L{twisted.names.dns.RRHeader} giving the response, or with a
            L{Failure} if there is a timeout or response error.
        r   z"Query limit reached without resultFr8   )r   r   ÚResolverErrorr6   r/   Ú_discoveredAuthority)r   r1   r-   r2   ÚqueriesLeftr5   s         r   r<   zResolver._discoverAuthority|   sd   € ð. ˜!ÒÐÝ�5Ô.Ð/SÑTÔTÑUÔUÐUà�KŠK˜˜w¨°Ñ7Ô7ˆØ	�Š�dÔ/°¸ÀÈqÁÑQÔQÐQØˆr   c                 óÜ  ‡ ‡‡‡‡‡— |j         t          j        k    r0t           ‰                      |j         ¦  «        |¦  «        ¦  «        S i Š|j        D ]0}‰                     |j        g ¦  «                             |¦  «         Œ1ˆfd„}t          ¦   «         }‰j        }d}		 | 
                    |¦  «         |	Š ||‰j        ‰j        ¦  «        }	|	€}|‰j        k    rnÅ‰                      t          j        t          |¦  «        ‰j        ‰j        ¦  «        ‰                      ¦   «         ‰‰¦  «        }
ˆfd„}|
                     |¦  «         |
S |	j        ‰j        k    r|j        |j        |j        fS |	j        j        |v rt+          j        d¦  «        ‚|	j        j        }�Œi }|j        D ]=}|j        t          j        k    r&|j                             ¦   «         ||j        j        <   Œ>g }g }|j        D ]i}|j        t          j        k    rR|j        j        j        }||v r(|                     ||         t          j        f¦  «         ŒT|                     |¦  «         Œj|r‰                      ‰|‰‰¦  «        S |rQ‰                      |d         ‰¦  «        }
d„ }|
                     |¦  «         |
                     ˆˆˆ ˆfd„¦  «         |
S t          t+          j        d	¦  «        ¦  «        S )
as  
        Interpret the response to a query, checking for error codes and
        following delegations if necessary.

        @param response: The L{Message} received in response to issuing C{query}.
        @type response: L{Message}

        @param query: The L{dns.Query} which was issued.
        @type query: L{dns.Query}.

        @param timeout: The timeout to use if another query is indicated by
            this response.
        @type timeout: L{tuple} of L{int}

        @param queriesLeft: A C{int} giving the number of queries which may
            yet be attempted to answer this query before the attempt will be
            abandoned.

        @return: A L{Failure} indicating a response error, a three-tuple of
            lists of L{twisted.names.dns.RRHeader} giving the response to
            C{query} or a L{Deferred} which will fire with one of those.
        c                 ó    •— d }‰                      | g ¦  «        D ]3}|j        |k    r&|j        |k    r|c S |j        t          j        k    r|}Œ4|S r   )Úgetr?   r@   r   ÚCNAME)r>   r@   r?   ÚcnameÚrecordÚrecordss        €r   ÚfindAnswerOrCNamez8Resolver._discoveredAuthority.<locals>.findAnswerOrCName¹   sd   ø€ ØˆEØ!Ÿ+š+ d¨BÑ/Ô/ð 'ð '�Ø”: Ò$Ð$Ø”{ dÒ*Ð*Ø%˜˜˜Øœ­¬	Ò1Ð1Ø &˜øð ˆLr   NTc                 óF   •— | \  }}}|                      d‰¦  «         |||fS ©Nr   )Úinsert)ÚresultsÚanswersÚ	authorityÚ
additionalÚpreviouss       €r   Ú
cbResolvedz1Resolver._discoveredAuthority.<locals>.cbResolvedÜ   s0   ø€ Ø9@Ñ6˜ ¨JØŸš q¨(Ñ3Ô3Ð3Ø '¨°JÐ?Ð?r   zCycle in CNAME processingr   c                 óL   — | \  }}}|d         j                              ¦   «         S rO   )ÚpayloadÚ
dottedQuad)rQ   rR   rS   rT   s       r   ÚgetOneAddressz4Resolver._discoveredAuthority.<locals>.getOneAddress   s'   € Ø18Ñ.�˜ JØ˜q”zÔ)×4Ò4Ñ6Ô6Ð6r   c                 óT   •— ‰                      ‰| t          j        fg‰‰dz
  ¦  «        S )Nr8   )r<   r   r'   )ÚhintrE   r1   r   r2   s    €€€€r   ú<lambda>z/Resolver._discoveredAuthority.<locals>.<lambda>  s.   ø€ ˜T×4Ò4Ø˜T¥3¤8Ð,Ð-¨w¸Àa¹ñô € r   z/Stuck at response without answers or delegation)ÚrCoder   ÚOKr   ÚexceptionForCoderR   Ú
setdefaultr>   ÚappendÚsetÚaddr@   r?   r<   r=   Ústrr+   r/   rS   rT   rX   r   rC   ÚArY   ÚNSr'   ÚlookupAddress)r   Úresponser1   r2   rE   ÚanswerrM   Úseenr>   rK   r5   rV   Ú	addressesÚrrr   ÚtrapsÚnsrZ   rU   rL   s   ` ```             @@r   rD   zResolver._discoveredAuthorityš   sQ  øøøøøø€ ð. Œ>�SœVÒ#Ð#ÝÐ@˜4×0Ò0°´Ñ@Ô@ÀÑJÔJÑKÔKÐKð ˆØÔ&ð 	?ð 	?ˆFØ×Ò˜vœ{¨BÑ/Ô/×6Ò6°vÑ>Ô>Ð>Ð>ð
	ð 
	ð 
	ð 
	ð 
	õ ‰uŒuˆØŒzˆØˆð"	+Ø�HŠH�T‰NŒNˆNØˆHØ&Ð& t¨U¬Z¸¼ÑCÔCˆFØˆ~Ø˜5œ:Ò%Ð%ð ð ×/Ò/Ýœ	¥# d¡)¤)¨U¬Z¸¼ÑCÔCØŸš™œØØ#ñ	ô �Að@ð @ð @ð @ð @ð
 —M’M *Ñ-Ô-Ð-Ø�HØ” ¤
Ò*Ð*Ø Ô(¨(Ô*<¸hÔ>QÐRÐRð ”>Ô&¨$Ð.Ð.ÝÔ-Ð.IÑJÔJÐJØ”~Ô*�ñE"	+ðJ ˆ	ØÔ%ð 	Bð 	BˆBØŒw�#œ%ÒÐØ*,¬*×*?Ò*?Ñ*AÔ*A�	˜"œ'œ,Ñ'øàˆØˆØÔ$ð 	%ð 	%ˆBØŒw�#œ&Ò Ð Ø”Z”_Ô)�Ø˜�?�?Ø—L’L )¨B¤-µ´Ð!:Ñ;Ô;Ð;Ð;à—L’L Ñ$Ô$Ð$øØð 	Ø×*Ò*¨5°%¸À+ÑNÔNÐNØð 	Ø×"Ò" 5¨¤8¨WÑ5Ô5ˆAð7ð 7ð 7ð �MŠM˜-Ñ(Ô(Ð(Ø�MŠMðð ð ð ð ð ð ñô ð ð
 ˆHåÝÔ#Ð$UÑVÔVñô ð r   )r   NN)
r   r   r   r   r   r+   r6   rA   r<   rD   r   r   r   r   r       s‚   € € € € € ðð ð0ð 0ð 0ð 0ð:5ð 5ð 5ðð ð ð>
ð 
ð 
ðð ð ð<tð tð tð tð tr   r   c                 ó   ‡ ‡— ˆ ˆfd„}|S )Nc                  ó@   •‡ ‡— ‰                      ˆ ˆˆfd„¦  «         ‰S )Nc                 ó0   •—  t          | ‰¦  «        ‰i ‰¤ŽS r   )Úgetattr)r4   r   Úkwr>   s    €€€r   r]   z6makePlaceholder.<locals>.placeholder.<locals>.<lambda>  s!   ø€ Ð'7¥w¨q°$Ñ'7Ô'7¸Ð'DÀÐ'DÐ'D€ r   )r/   )r   rt   Údeferredr>   s   ``€€r   Úplaceholderz$makePlaceholder.<locals>.placeholder  s.   øøø€ Ø×ÒÐDÐDÐDÐDÐDÐDÑEÔEÐEØˆr   r   )ru   r>   rv   s   `` r   ÚmakePlaceholderrw     s*   øø€ ðð ð ð ð ð ð Ðr   c                   ó    — e Zd Zd„ Zd„ Zd„ ZdS )ÚDeferredResolverc                 óH   — g | _         |                     | j        ¦  «         d S r   )Úwaitingr/   ÚgotRealResolver)r   ÚresolverDeferreds     r   r   zDeferredResolver.__init__  s&   € ØˆŒØ×$Ò$ TÔ%9Ñ:Ô:Ð:Ð:Ð:r   c                 óx   — | j         }|j        | _        |j        | _        |D ]}|                     |¦  «         Œd S r   )r{   Ú__dict__Ú	__class__Úcallback)r   ÚresolverÚwr5   s       r   r|   z DeferredResolver.gotRealResolver  sK   € ØŒLˆØ Ô)ˆŒØ!Ô+ˆŒØð 	!ð 	!ˆAØ�JŠJ�xÑ Ô Ð Ð ð	!ð 	!r   c                 óÞ   — |                      d¦  «        s|dv rF| j                             t          j        ¦   «         ¦  «         t          | j        d         |¦  «        S t          |¦  «        ‚)NÚlookup)ÚgetHostByNamer1   éÿÿÿÿ)Ú
startswithr{   rb   r   ÚDeferredrw   ÚAttributeError)r   r>   s     r   Ú__getattr__zDeferredResolver.__getattr__%  sd   € Ø�?Š?˜8Ñ$Ô$ð 	;¨Ð0JÐ(JÐ(JØŒL×Ò¥¤Ñ 0Ô 0Ñ1Ô1Ð1Ý" 4¤<°Ô#3°TÑ:Ô:Ð:Ý˜TÑ"Ô"Ð"r   N)r   r   r   r   r|   r‹   r   r   r   ry   ry     sA   € € € € € ð;ð ;ð ;ð!ð !ð !ð#ð #ð #ð #ð #r   ry   Nc                 óÒ   ‡ ‡— d„ t          d¦  «        D ¦   «         }ˆ fd„|D ¦   «         }t          j        |d¬¦  «        }ˆfd„}|                     |¦  «         t	          |¦  «        S )aÿ  
    Lookup the root nameserver addresses using the given resolver

    Return a Resolver which will eventually become a C{root.Resolver}
    instance that has references to all the root servers that we were able
    to look up.

    @param resolver: The resolver instance which will be used to
        lookup the root nameserver addresses.
    @type resolver: L{twisted.internet.interfaces.IResolverSimple}

    @param resolverFactory: An optional callable which returns a
        resolver instance. It will passed as the C{resolverFactory}
        argument to L{Resolver.__init__}.
    @type resolverFactory: callable

    @return: A L{DeferredResolver} which will be dynamically replaced
        with L{Resolver} when the root nameservers have been looked up.
    c                 óL   — g | ]!}t          t          d ¦  «        |z   ¦  «        ‘Œ"S )Úa)ÚchrÚord)r(   Úis     r   r*   zbootstrap.<locals>.<listcomp>@  s*   € Ð4Ð4Ð4 Q�s•3�s‘8”8˜a‘<Ñ Ô Ð4Ð4Ð4r   é   c                 ó@   •— g | ]}‰                      d |z  ¦  «        ‘ŒS )z%s.root-servers.net)r†   )r(   r5   r‚   s     €r   r*   zbootstrap.<locals>.<listcomp>A  s-   ø€ ÐLÐLÐL¸qˆ×	Ò	Ð 5¸Ñ 9Ñ	:Ô	:ÐLÐLÐLr   T)ÚconsumeErrorsc                 ó:   •— t          d„ | D ¦   «         ‰¬¦  «        S )Nc                 ó.   — g | ]}|d          ¯
|d         ‘ŒS )r   r8   r   )r(   Úes     r   r*   z4bootstrap.<locals>.buildResolver.<locals>.<listcomp>F  s%   € Ð-Ð-Ð-˜A¨¨!¬Ð-�1�Q”4Ð-Ð-Ð-r   )r   r$   r   )Úresr$   s    €r   ÚbuildResolverz bootstrap.<locals>.buildResolverD  s-   ø€ ÝØ-Ð- Ð-Ñ-Ô-¸ð
ñ 
ô 
ð 	
r   )Úranger   ÚDeferredListr/   ry   )r‚   r$   ÚdomainsÚLr5   r™   s   ``    r   Ú	bootstraprž   ,  sˆ   øø€ ð( 5Ð4­%°©)¬)Ð4Ñ4Ô4€GØLÐLÐLÐLÀGÐLÑLÔL€AÝÔ˜1¨DÐ1Ñ1Ô1€Að
ð 
ð 
ð 
ð 
ð
 ‡M‚M�-Ñ Ô Ð å˜AÑÔÐr   r   )r   Útwisted.internetr   Útwisted.namesr   r   r   Útwisted.python.failurer   r	   r   r   rw   ry   rž   r   r   r   ú<module>r¢      s  ðð
	ð 	ð #Ð "Ð "Ð "Ð "Ð "Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø *Ð *Ð *Ð *Ð *Ð *ðð ð ð ð ñ ô ð ðnð nð nð nð nˆvÔ"ñ nô nð nðbð ð ð#ð #ð #ð #ð #ñ #ô #ð #ð&ð ð ð ð ð r   