
    Ϫf                         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y)SecondaryAuthoritySecondaryAuthorityService    )service)defertask)clientcommondnsresolve)FileAuthority)failurelog)nativeStringc                   @    e Zd ZdZdZdZd Zed        Zd Z	d Z
d Zy)	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                 l    t        |      | _        |D cg c]  }t        ||       c}| _        yc c}w )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}
        N)r   primaryr   domains)selfr   r   ds       9/usr/lib/python3/dist-packages/twisted/names/secondary.py__init__z"SecondaryAuthorityService.__init__    s-     $G,@GH1*7A6HHs   1c                     |\  }} | |g       }||_         |D cg c]  }t        j                  ||       c}|_        |S c c}w )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}.
        )_portr   fromServerAddressAndDomainr   )clsserverAddressr   r   portr   r   s          r   fromServerAddressAndDomainsz5SecondaryAuthorityService.fromServerAddressAndDomains-   sU    " &gr" 
 99-K
 	
s   Ac                 @    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    c                 :   t         j                  j                  |        | j                  D cg c]!  }t	        j
                  |j                        # c}| _        d}ddlm	} | j                  D ]$  }|j                  ||j                  d       |dz  }& y c c}w )Nr   reactori     )r   ServicestartServicer   r   LoopingCalltransfercallstwisted.internetr'   	callLaterstart)r   r   ir'   cs        r   r*   z&SecondaryAuthorityService.startServiceO   sy    $$T*<@LLIqd&&qzz2I
, 	Aa'2FA		 Js   &Bc                     t         j                  j                  |        | j                  D ]  }|j	                           y N)r   r)   stopServicer-   stop)r   r2   s     r   r5   z%SecondaryAuthorityService.stopServiceZ   s0    ##D) 	AFFH	r$   )__name__
__module____qualname____doc__r-   r   r   classmethodr   r#   r*   r5    r$   r   r   r      s<    	 EEI  23	r$   c                   f    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y)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                  j                  |        t        |      | _        t        j                  |      | _        y)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   	primaryIPrA   s      r   r   zSecondaryAuthority.__init__x   s6     	$$T*#I.&&v.r$   c                 0    |\  }} | ||      }||_         |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   rA   r   r   	secondarys         r   r   z-SecondaryAuthority.fromServerAddressAndDomain   s&    " &(		r$   c                 H   | j                   ryd| _        | j                  }|ddlm} t        j                  | j                  | j                  fg|      }|j                  | j                        j                  | 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_reactorr.   r'   r   Resolverr   r   
lookupZonerA   addCallback_cbZone
addErrback_ebZone)r   r'   resolvers      r   r,   zSecondaryAuthority.transfer   s     --?0??llDJJ/0'
 ,[&Z%	
r$   c                     | j                   r| j                  s;t        j                  t	        j
                  t        j                  |                  S t        j                  | ||||      S r4   )
soarecordsr   failr   Failurer
   DomainErrorr   _lookup)r   namer   typetimeouts        r   rW   zSecondaryAuthority._lookup   sK    xxt|| ::goocood.CDEE$$T4dGDDr$   c                    |\  }}}i x| _         }|D ]  }| j                  sS|j                  t        j                  k(  r6|j
                  j
                  j                         |j                  f| _        b|j                  |j
                  j
                  j                         g       j                  |j                          y r4   )
rS   rR   rY   r
   SOArX   lowerpayload
setdefaultappend)r   zoneans_rrecs         r   rM   zSecondaryAuthority._cbZone   s    	Qq 	LC88CGG 3HHMM//13;;?SXX]]002B7>>s{{K		Lr$   c                     t        j                  d| j                  d| j                  d       t        j                  |       y )Nz	Updating  from z failed during zone transfer)r   msgrA   r   errr   r   s     r   rO   zSecondaryAuthority._ebZone   s.    {{DLL*	
 	r$   c                 l    | j                         j                  | j                  | j                         y r4   )r,   addCallbacks_cbTransferred_ebTransferredr"   s    r   updatezSecondaryAuthority.update   s$    $$T%8%8$:M:MNr$   c                     d| _         y )NF)rG   )r   results     r   rm   z!SecondaryAuthority._cbTransferred   s
    !r$   c                     d| _         t        j                  d| j                  d| j                  d       t        j
                  |       y )NFzTransferring rg   z failed after zone transfer)transferredr   rh   rA   r   ri   rj   s     r   rn   z!SecondaryAuthority._ebTransferred   s6     {{DLL*	
 	r$   r4   )r7   r8   r9   r:   rG   rR   rS   r   rI   r   r;   r   r,   rW   rM   rO   ro   rm   rn   r<   r$   r   r   r   `   sa    $ LC'EH/  *
4ELO"r$   N)__all__twisted.applicationr   r.   r   r   twisted.namesr   r	   r
   r   twisted.names.authorityr   twisted.pythonr   r   twisted.python.compatr   r)   r   r   r<   r$   r   <module>rz      sH     !<
= ' ( 6 6 1 ' .M M`x xr$   