
    \d                         d dgZ ddlmZ ddlmZmZ ddlmZmZm	Z	m
Z
 ddlmZ ddlmZmZ ddlmZ  G d	 dej                  Z G d
 d e          ZdS )SecondaryAuthoritySecondaryAuthorityService    )service)defertask)clientcommondnsresolve)FileAuthority)failurelog)nativeStringc                   H    e Zd ZdZdZdZd Zed             Zd Z	d Z
d ZdS )	r   a:  
    A service that keeps one or more authorities up to date by doing hourly
    zone transfers from a master.

    @ivar primary: IP address of the master.
    @type primary: L{str}

    @ivar domains: An authority for each domain mirrored from the master.
    @type domains: L{list} of L{SecondaryAuthority}
    N5   c                 V    t                    | _        fd|D             | _        dS )a  
        @param primary: The IP address of the server from which to perform
        zone transfers.
        @type primary: L{str}

        @param domains: A sequence of domain names for which to perform
        zone transfers.
        @type domains: L{list} of L{bytes}
        c                 0    g | ]}t          |          S  )r   ).0dprimarys     7lib/python3.11/site-packages/twisted/names/secondary.py
<listcomp>z6SecondaryAuthorityService.__init__.<locals>.<listcomp>+   s$    HHH1*7A66HHH    N)r   r   domains)selfr   r   s    ` r   __init__z"SecondaryAuthorityService.__init__    s3     $G,,HHHHHHHr   c                 ^    \  }} | |g           }||_         fd|D             |_        |S )a  
        Construct a new L{SecondaryAuthorityService} from a tuple giving a
        server address and a C{str} giving the name of a domain for which this
        is an authority.

        @param serverAddress: A two-tuple, the first element of which is a
            C{str} giving an IP address and the second element of which is a
            C{int} giving a port number.  Together, these define where zone
            transfers will be attempted from.

        @param domains: Domain names for which to perform zone transfers.
        @type domains: sequence of L{bytes}

        @return: A new instance of L{SecondaryAuthorityService}.
        c                 F    g | ]}t                               |          S r   )r   fromServerAddressAndDomain)r   r   serverAddresss     r   r   zISecondaryAuthorityService.fromServerAddressAndDomains.<locals>.<listcomp>A   s9     
 
 
 99-KK
 
 
r   )_portr   )clsr!   r   r   portr   s    `    r   fromServerAddressAndDomainsz5SecondaryAuthorityService.fromServerAddressAndDomains-   sW    " &#gr""
 
 
 

 
 
 r   c                 4    t          j        | j                  S )z_
        Get a resolver for the transferred domains.

        @rtype: L{ResolverChain}
        )r   ResolverChainr   r   s    r   getAuthorityz&SecondaryAuthorityService.getAuthorityG   s     $T\222r   c                     t           j                            |            d | j        D             | _        d}ddlm} | j        D ]#}|                    ||j        d           |dz  }$d S )Nc                 @    g | ]}t          j        |j                  S r   )r   LoopingCalltransfer)r   r   s     r   r   z:SecondaryAuthorityService.startService.<locals>.<listcomp>Q   s%    IIIqd&qz22IIIr   r   reactori     )	r   ServicestartServicer   callstwisted.internetr/   	callLaterstart)r   ir/   cs       r   r2   z&SecondaryAuthorityService.startServiceO   s    $$T***IIDLIII
,,,,,, 	 	Aa'222FAA	 	r   c                     t           j                            |            | j        D ]}|                                 d S N)r   r1   stopServicer3   stop)r   r8   s     r   r;   z%SecondaryAuthorityService.stopServiceZ   sB    ##D))) 	 	AFFHHHH	 	r   )__name__
__module____qualname____doc__r3   r"   r   classmethodr%   r)   r2   r;   r   r   r   r   r      s        	 	 EEI I I   [23 3 3	 	 	    r   c                   n    e Zd ZdZdZdxZZdZdZd Z	e
d             Zd ZddZd	 Zd
 Zd Zd Zd ZdS )r   a  
    An Authority that keeps itself updated by performing zone transfers.

    @ivar primary: The IP address of the server from which zone transfers will
    be attempted.
    @type primary: L{str}

    @ivar _port: The port number of the server from which zone transfers will
    be attempted.
    @type _port: L{int}

    @ivar domain: The domain for which this is the secondary authority.
    @type domain: L{bytes}

    @ivar _reactor: The reactor to use to perform the zone transfers, or
    L{None} to use the global reactor.
    FNr   c                     t           j                            |            t          |          | _        t          j        |          | _        dS )z
        @param domain: The domain for which this will be the secondary
            authority.
        @type domain: L{bytes} or L{str}
        N)r	   ResolverBaser   r   r   r
   domainStringdomain)r   	primaryIPrF   s      r   r   zSecondaryAuthority.__init__x   s@     	$$T***#I..&v..r   c                 6    |\  }} | ||          }||_         |S )af  
        Construct a new L{SecondaryAuthority} from a tuple giving a server
        address and a C{bytes} giving the name of a domain for which this is an
        authority.

        @param serverAddress: A two-tuple, the first element of which is a
            C{str} giving an IP address and the second element of which is a
            C{int} giving a port number.  Together, these define where zone
            transfers will be attempted from.

        @param domain: A C{bytes} giving the domain to transfer.
        @type domain: L{bytes}

        @return: A new instance of L{SecondaryAuthority}.
        )r"   )r#   r!   rF   r   r$   	secondarys         r   r    z-SecondaryAuthority.fromServerAddressAndDomain   s+    " &C((		r   c                    | j         rdS d| _        | j        }|ddlm} t          j        | j        | j        fg|          }|	                    | j
                                      | j                                      | j                  S )z
        Attempt a zone transfer.

        @returns: A L{Deferred} that fires with L{None} when attempted zone
            transfer has completed.
        NTr   r.   )serversr/   )transferringtransfering_reactorr4   r/   r   Resolverr   r"   
lookupZonerF   addCallback_cbZone
addErrback_ebZone)r   r/   resolvers      r   r-   zSecondaryAuthority.transfer   s      	F-?000000?lDJ/0'
 
 
 ,,[&&Z%%	
r   c                     | j         r| j        s8t          j        t	          j        t          j        |                              S t          j	        | ||||          S r:   )
soarecordsr   failr   Failurer
   DomainErrorr   _lookup)r   namer#   typetimeouts        r   r\   zSecondaryAuthority._lookup   sV    x 	Ft| 	F :gocod.C.CDDEEE$T4dGDDDr   c                 P   |\  }}}i x| _         }|D ]}| j        s@|j        t          j        k    r+|j        j                                        |j        f| _        I|                    |j        j                                        g           	                    |j                   d S r:   )
rX   rW   r^   r
   SOAr]   lowerpayload
setdefaultappend)r   zoneans_rrecs         r   rR   zSecondaryAuthority._cbZone   s    	Qq 	L 	LC8 LCG 3 3HM//113;?SX]0022B77>>s{KKKK		L 	Lr   c                 x    t          j        d| j        d| j        d           t          j        |           d S )Nz	Updating  from z failed during zone transfer)r   msgrF   r   errr   r   s     r   rT   zSecondaryAuthority._ebZone   sF    {{{DLLL*	
 	
 	
 	r   c                 j    |                                                      | j        | j                   d S r:   )r-   addCallbacks_cbTransferred_ebTransferredr(   s    r   updatezSecondaryAuthority.update   s,    $$T%8$:MNNNNNr   c                     d| _         d S )NF)rL   )r   results     r   rr   z!SecondaryAuthority._cbTransferred   s    !r   c                     d| _         t          j        d| j        d| j        d           t          j        |           d S )NFzTransferring rl   z failed after zone transfer)transferredr   rm   rF   r   rn   ro   s     r   rs   z!SecondaryAuthority._ebTransferred   sN     {{{DLLL*	
 	
 	
 	r   r:   )r=   r>   r?   r@   rL   rW   rX   r"   rN   r   rA   r    r-   r\   rR   rT   rt   rr   rs   r   r   r   r   r   `   s         $ LC'EH/ / /   [*
 
 
4E E E EL L L  O O O" " "    r   N)__all__twisted.applicationr   r4   r   r   twisted.namesr   r	   r
   r   twisted.names.authorityr   twisted.pythonr   r   twisted.python.compatr   r1   r   r   r   r   r   <module>r      s    !<
= ' ' ' ' ' ' ( ( ( ( ( ( ( ( 6 6 6 6 6 6 6 6 6 6 6 6 1 1 1 1 1 1 ' ' ' ' ' ' ' ' . . . . . .M M M M M M M M`x x x x x x x x x xr   