From: Brian Warner Date: Thu, 30 Nov 2006 22:27:06 +0000 (-0700) Subject: have client running, no queen to connect to yet X-Git-Tag: tahoe_v0.1.0-0-UNSTABLE~545 X-Git-Url: https://git.rkrishnan.org/webform_css?a=commitdiff_plain;h=a97596ab9ae9fae0f50c985b2c7f5bf2a9e5fab8;p=tahoe-lafs%2Ftahoe-lafs.git have client running, no queen to connect to yet --- diff --git a/allmydata/__init__.py b/allmydata/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/allmydata/client.py b/allmydata/client.py index cadbd289..ed49e96c 100644 --- a/allmydata/client.py +++ b/allmydata/client.py @@ -1,9 +1,40 @@ from foolscap import Tub from twisted.application import service +from twisted.python import log +import os.path class Client(service.MultiService): + CERTFILE = "client.pem" + def __init__(self, queen_pburl): service.MultiService.__init__(self) self.queen_pburl = queen_pburl - self.tub = Tub() + if os.path.exists(self.CERTFILE): + self.tub = Tub(certData=open(self.CERTFILE, "rb").read()) + else: + self.tub = Tub() + f = open(self.CERTFILE, "wb") + f.write(self.tub.getCertData()) + f.close() + self.queen = None # self.queen is either None or a RemoteReference + + def startService(self): + service.MultiService.startService(self) + if self.queen_pburl: + self.connector = self.tub.connectTo(self.queen_pburl, + self._got_queen) + else: + log.msg("no queen_pburl, cannot connect") + + def stopService(self): + self.connector.stopConnecting() + + def _got_queen(self, queen): + log.msg("connected to queen") + self.queen = queen + queen.notifyOnDisconnect(self._lost_queen) + + def _lost_queen(self): + log.msg("lost connection to queen") + self.queen = None