o b@sddgZddlmZddlmZmZddlmZmZm Z m Z ddl m Z ddl mZmZddlmZGd ddejZGd dde Zd S) SecondaryAuthoritySecondaryAuthorityService)service)defertask)clientcommondnsresolve) FileAuthority)failurelog) nativeStringc@sDeZdZdZdZdZddZeddZdd Z d d Z d d Z dS)ra: 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} N5cs"t|_fdd|D|_dS)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} csg|]}t|qS)r.0dprimaryr9/usr/lib/python3/dist-packages/twisted/names/secondary.py +sz6SecondaryAuthorityService.__init__..N)rrdomains)selfrrrrr__init__ s z"SecondaryAuthorityService.__init__cs0\}}||g}||_fdd|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}. csg|]}t|qSr)rfromServerAddressAndDomainr serverAddressrrrAs zISecondaryAuthorityService.fromServerAddressAndDomains..)_portr)clsrrrportrrrrfromServerAddressAndDomains-s  z5SecondaryAuthorityService.fromServerAddressAndDomainscCs t|jS)z_ Get a resolver for the transferred domains. @rtype: L{ResolverChain} )r ResolverChainrrrrr getAuthorityGs z&SecondaryAuthorityService.getAuthoritycCsVtj|dd|jD|_d}ddlm}|jD]}|||jd|d7}qdS)NcSsg|]}t|jqSr)r LoopingCalltransferrrrrrQsz:SecondaryAuthorityService.startService..rreactori) rService startServicercallstwisted.internetr( callLaterstart)rir(crrrr+Os    z&SecondaryAuthorityService.startServicecCs$tj||jD]}|q dSN)rr* stopServicer,stop)rr1rrrr3Zs   z%SecondaryAuthorityService.stopService) __name__ __module__ __qualname____doc__r,rr classmethodr!r$r+r3rrrrrs   c@sreZdZdZdZdZZdZdZddZ e ddZ d d Z dd d Z d dZddZddZddZddZdS)ra 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. FNrcCs&tj|t||_t||_dS)z @param domain: The domain for which this will be the secondary authority. @type domain: L{bytes} or L{str} N)r ResolverBaserrrr domainStringdomain)r primaryIPr<rrrrxs zSecondaryAuthority.__init__cCs|\}}|||}||_|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)rrr<rr secondaryrrrrs z-SecondaryAuthority.fromServerAddressAndDomaincCs^|jrdSd|_|j}|durddlm}tj|j|jfg|d}| |j  |j  |jS)z Attempt a zone transfer. @returns: A L{Deferred} that fires with L{None} when attempted zone transfer has completed. NTrr')serversr() transferring transfering_reactorr-r(rResolverrr lookupZoner< addCallback_cbZone addErrback_ebZone)rr(resolverrrrr&s   zSecondaryAuthority.transfercCs4|jr|jsttt|St |||||Sr2) soarecordsrfailr Failurer DomainErrorr _lookup)rnamertypetimeoutrrrrOs zSecondaryAuthority._lookupcCsf|\}}}i|_}|D]$}|js"|jtjkr"|jj|jf|_q ||jjg |jq dSr2) rKrJrQr SOArPlowerpayload setdefaultappend)rzoneans_rrecrrrrFs  zSecondaryAuthority._cbZonecCs$td|j|jft|dS)Nz/Updating %s from %s failed during zone transfer)r msgr<rerrrr rrrrHs  zSecondaryAuthority._ebZonecCs||j|jdSr2)r& addCallbacks_cbTransferred_ebTransferredr#rrrupdateszSecondaryAuthority.updatecCs d|_dS)NF)r@)rresultrrrras z!SecondaryAuthority._cbTransferredcCs*d|_td|j|jft|dS)NFz2Transferring %s from %s failed after zone transfer) transferredr r]r<rr^r_rrrrbs z!SecondaryAuthority._ebTransferredr2)r5r6r7r8r@rJrKrrBrr9rr&rOrFrHrcrarbrrrrr`s     N)__all__twisted.applicationrr-rr twisted.namesrrr r twisted.names.authorityr twisted.pythonr r twisted.python.compatrr*rrrrrrs   P