[Twisted-Python] Custom DNS server

Rudy Schockaert Rudy.Schockaert at pandora.be
Wed Jul 23 14:50:00 MDT 2003


Jp Calderone wrote:

>  This should be pretty easy.  I think the way to go about it would be to
>subclass t.names.client.Resolver and override lookupMailExchange(),
>returning the central relay address instead for the affected domains, and
>deferring (english meaning) to the parent implementation of the method for
>everyone else.
>  
>
Hi Jp,

I was trying to figure out how the twisted.names package works and I 
think I found a solution where I don't need to modify anything.

When I create a DNS server as follows:

mycache = {.........} # valid cache entries
ca, cl = [], []
ca.append(twisted.names.cache.CacheResolver(cache=mycache)) # preloaded 
cache
ca.append(twisted.names.cache.CacheResolver()) # regular empty cache
cl.append(twisted.names.client.createResolver())
f = twisted.names.server.DNSServerFactory(caches=ca, clients=cl)
p = twisted.protocols.dns.DNSDatagramProtocol(f)
app.listenUDP(53, p)
app.listenTCP(53, f)

I have two caches: one preloaded with my entries and a second one that 
is empty at the start.
When a request arrives for a record that is in my preloaded cache it is 
returned, but also added to the second cache (actually to the last cache 
passed to the DNSServerFactory)..
callLater in cacheResult will remove it later from the second cache but 
not from the first cache.
All other entries will follow the normal way, be it with one 
cache-lookup extra.

Is there somewhere an error in my reasoning? Are there other reasons why 
this is not a good approach?

Bet regards,

/Rudy





More information about the Twisted-Python mailing list