]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
have client running, no queen to connect to yet
authorBrian Warner <warner@lothar.com>
Thu, 30 Nov 2006 22:27:06 +0000 (15:27 -0700)
committerBrian Warner <warner@lothar.com>
Thu, 30 Nov 2006 22:27:06 +0000 (15:27 -0700)
allmydata/__init__.py [new file with mode: 0644]
allmydata/client.py

diff --git a/allmydata/__init__.py b/allmydata/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
index cadbd2897fa1c31650b3de322f16d7314e5cc9fd..ed49e96c0ce5f56544b3be8a3206cc24222636e5 100644 (file)
@@ -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