I have written a proxy server that uses twisted's application framework. At it's core there it uses a DHT to resolve things. The DHT client takes a few seconds to start, so i want to make sure that the proxy only accepts connections after the DHT is ready.
# there is a class like
class EntangledDHT(object):
# connects to the dht
# create the client
dht = EntangledDHT.from_config(config)
# when it can be used this deferred fires
# i want to wait for this before creating the "real" application
dht.ready
# the proxy server, it uses the dht client
port = config.getint(section, 'port')
p = CosipProxy(host=config.get(section, 'listen'),
port=port,
dht=dht,
domain=config.get(section, 'domain'))
## for twistd
application = service.Application('cosip')
serv = internet.UDPServer(port, p)
serv.setServiceParent(service.IService(application))
How do I turn the EntangledDHT
into some kind of service that Twisted will wait for before starting the CosipProxy
service? Is there any mechanism in twisted that does this for me? Or do I have to add a callback to dht.ready
that creates the rest of the application? Thanks