mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-01 16:58:10 +00:00
have client running, no queen to connect to yet
This commit is contained in:
parent
174a45e106
commit
a97596ab9a
0
allmydata/__init__.py
Normal file
0
allmydata/__init__.py
Normal file
@ -1,9 +1,40 @@
|
|||||||
|
|
||||||
from foolscap import Tub
|
from foolscap import Tub
|
||||||
from twisted.application import service
|
from twisted.application import service
|
||||||
|
from twisted.python import log
|
||||||
|
import os.path
|
||||||
|
|
||||||
class Client(service.MultiService):
|
class Client(service.MultiService):
|
||||||
|
CERTFILE = "client.pem"
|
||||||
|
|
||||||
def __init__(self, queen_pburl):
|
def __init__(self, queen_pburl):
|
||||||
service.MultiService.__init__(self)
|
service.MultiService.__init__(self)
|
||||||
self.queen_pburl = queen_pburl
|
self.queen_pburl = queen_pburl
|
||||||
|
if os.path.exists(self.CERTFILE):
|
||||||
|
self.tub = Tub(certData=open(self.CERTFILE, "rb").read())
|
||||||
|
else:
|
||||||
self.tub = Tub()
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user