From 61eb839843dda800f6fc9676b1ae9e79d8436093 Mon Sep 17 00:00:00 2001 From: David Stainton Date: Mon, 15 Aug 2016 16:08:23 +0000 Subject: [PATCH] Add tub_handlers arg to NativeStorageServer constructor Here we also define tub_handlers as a node attribute and pass it all the way down to the NativeStorageServer via the Client and StorageFarmBroker --- src/allmydata/client.py | 3 ++- src/allmydata/node.py | 1 + src/allmydata/storage_client.py | 10 ++++++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/allmydata/client.py b/src/allmydata/client.py index 93aff9f71..6924d8aa9 100644 --- a/src/allmydata/client.py +++ b/src/allmydata/client.py @@ -370,7 +370,8 @@ class Client(node.Node, pollmixin.PollMixin): preferred_peers = tuple([p.strip() for p in ps if p != ""]) sb = storage_client.StorageFarmBroker(permute_peers=True, preferred_peers=preferred_peers, - tub_options=self.tub_options) + tub_options=self.tub_options, + tub_handlers=self.tub_handlers) self.storage_broker = sb sb.setServiceParent(self) diff --git a/src/allmydata/node.py b/src/allmydata/node.py index 5a42df5f2..c7295b6ed 100644 --- a/src/allmydata/node.py +++ b/src/allmydata/node.py @@ -203,6 +203,7 @@ class Node(service.MultiService): def create_tub(self): certfile = os.path.join(self.basedir, "private", self.CERTFILE) self.tub = Tub(certFile=certfile) + self.tub_handlers = {} self.tub_options = { "logLocalFailures": True, "logRemoteFailures": True, diff --git a/src/allmydata/storage_client.py b/src/allmydata/storage_client.py index 2d1cf56a7..26c4e0014 100644 --- a/src/allmydata/storage_client.py +++ b/src/allmydata/storage_client.py @@ -67,12 +67,13 @@ class StorageFarmBroker(service.MultiService): I'm also responsible for subscribing to the IntroducerClient to find out about new servers as they are announced by the Introducer. """ - def __init__(self, permute_peers, preferred_peers=(), tub_options={}): + def __init__(self, permute_peers, preferred_peers=(), tub_options={}, tub_handlers={}): service.MultiService.__init__(self) assert permute_peers # False not implemented yet self.permute_peers = permute_peers self.preferred_peers = preferred_peers self._tub_options = tub_options + self._tub_handlers = tub_handlers # self.servers maps serverid -> IServer, and keeps track of all the # storage servers that we've heard about. Each descriptor manages its @@ -131,7 +132,7 @@ class StorageFarmBroker(service.MultiService): precondition(isinstance(key_s, str), key_s) precondition(key_s.startswith("v0-"), key_s) assert ann["service-name"] == "storage" - s = NativeStorageServer(key_s, ann, self._tub_options) + s = NativeStorageServer(key_s, ann, self._tub_options, self._tub_handlers) s.on_status_changed(lambda _: self._got_connection()) serverid = s.get_serverid() old = self.servers.get(serverid) @@ -243,11 +244,12 @@ class NativeStorageServer(service.MultiService): "application-version": "unknown: no get_version()", } - def __init__(self, key_s, ann, tub_options={}): + def __init__(self, key_s, ann, tub_options={}, tub_handlers={}): service.MultiService.__init__(self) self.key_s = key_s self.announcement = ann self._tub_options = tub_options + self._tub_handlers = tub_handlers assert "anonymous-storage-FURL" in ann, ann furl = str(ann["anonymous-storage-FURL"]) @@ -348,8 +350,8 @@ class NativeStorageServer(service.MultiService): self._tub = Tub() for (name, value) in self._tub_options.items(): self._tub.setOption(name, value) + # XXX todo: do stuff with the handlers self._tub.setServiceParent(self) - furl = str(self.announcement["anonymous-storage-FURL"]) self._trigger_cb = trigger_cb self._reconnector = self._tub.connectTo(furl, self._got_connection)