我编写了一个使用twisted 应用程序框架的代理服务器。它的核心是使用 DHT 来解决问题。DHT 客户端需要几秒钟才能启动,所以我想确保代理只在 DHT 准备好后接受连接。
# 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))
如何将EntangledDHT
Twisted 转换为某种服务,然后再启动CosipProxy
服务?扭曲中是否有任何机制可以为我做到这一点?还是我必须添加一个回调来dht.ready
创建应用程序的其余部分?谢谢