]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
more storage_broker refactoring: downloader gets a broker instead of a client,
authorBrian Warner <warner@lothar.com>
Tue, 2 Jun 2009 02:25:11 +0000 (19:25 -0700)
committerBrian Warner <warner@lothar.com>
Tue, 2 Jun 2009 02:25:11 +0000 (19:25 -0700)
use Client.get_storage_broker() accessor instead of direct attribute access.

12 files changed:
src/allmydata/client.py
src/allmydata/immutable/download.py
src/allmydata/immutable/offloaded.py
src/allmydata/immutable/upload.py
src/allmydata/mutable/publish.py
src/allmydata/mutable/servermap.py
src/allmydata/test/test_checker.py
src/allmydata/test/test_helper.py
src/allmydata/test/test_mutable.py
src/allmydata/test/test_upload.py
src/allmydata/test/test_web.py
src/allmydata/web/check_results.py

index 106b1b724531e073abc591a4c075805cf2934424..465c546a5653c0e05133deb9c492f20dfe445b54 100644 (file)
@@ -263,6 +263,9 @@ class Client(node.Node, pollmixin.PollMixin):
                            default=True, boolean=True):
             sb.use_introducer(self.introducer_client)
 
+    def get_storage_broker(self):
+        return self.storage_broker
+
     def init_stub_client(self):
         def _publish(res):
             # we publish an empty object so that the introducer can count how
index 3884102478e27b8c37b08dfb08d95d0c2aaff002..39101c4cc90be09d393df0c5df3a3f18e6bd5fd8 100644 (file)
@@ -616,21 +616,22 @@ class DownloadStatus:
         self.results = value
 
 class CiphertextDownloader(log.PrefixingLogMixin):
-    """ I download shares, check their integrity, then decode them, check the integrity of the
-    resulting ciphertext, then and write it to my target. Before I send any new request to a
-    server, I always ask the "monitor" object that was passed into my constructor whether this
-    task has been cancelled (by invoking its raise_if_cancelled() method). """
+    """ I download shares, check their integrity, then decode them, check the
+    integrity of the resulting ciphertext, then and write it to my target.
+    Before I send any new request to a server, I always ask the 'monitor'
+    object that was passed into my constructor whether this task has been
+    cancelled (by invoking its raise_if_cancelled() method)."""
     implements(IPushProducer)
     _status = None
 
-    def __init__(self, client, v, target, monitor):
+    def __init__(self, storage_broker, v, target, monitor):
 
         precondition(IVerifierURI.providedBy(v), v)
         precondition(IDownloadTarget.providedBy(target), target)
 
         prefix=base32.b2a_l(v.storage_index[:8], 60)
         log.PrefixingLogMixin.__init__(self, facility="tahoe.immutable.download", prefix=prefix)
-        self._client = client
+        self._storage_broker = storage_broker
 
         self._verifycap = v
         self._storage_index = v.storage_index
@@ -743,7 +744,7 @@ class CiphertextDownloader(log.PrefixingLogMixin):
 
     def _get_all_shareholders(self):
         dl = []
-        sb = self._client.storage_broker
+        sb = self._storage_broker
         for (peerid,ss) in sb.get_servers(self._storage_index):
             d = ss.callRemote("get_buckets", self._storage_index)
             d.addCallbacks(self._got_response, self._got_error,
@@ -1191,11 +1192,13 @@ class Downloader(service.MultiService):
             # include LIT files
             self.stats_provider.count('downloader.files_downloaded', 1)
             self.stats_provider.count('downloader.bytes_downloaded', u.get_size())
+        storage_broker = self.parent.get_storage_broker()
 
         target = DecryptingTarget(t, u.key, _log_msg_id=_log_msg_id)
         if not monitor:
             monitor=Monitor()
-        dl = CiphertextDownloader(self.parent, u.get_verify_cap(), target, monitor=monitor)
+        dl = CiphertextDownloader(storage_broker, u.get_verify_cap(), target,
+                                  monitor=monitor)
         self._all_downloads[dl] = None
         if history:
             history.add_download(dl.get_download_status())
index 01dc1ed4ad8c0d1b6f03fa79672db26337f2c834..a71bf1324b80109d00879ded6167d91cadb8d04b 100644 (file)
@@ -618,7 +618,7 @@ class Helper(Referenceable, service.MultiService):
         # see if this file is already in the grid
         lp2 = self.log("doing a quick check+UEBfetch",
                        parent=lp, level=log.NOISY)
-        sb = self.parent.storage_broker
+        sb = self.parent.get_storage_broker()
         c = CHKCheckerAndUEBFetcher(sb.get_servers, storage_index, lp2)
         d = c.check()
         def _checked(res):
index 4bf07fed5368cd22ee5a4dc6337f87a173462ad3..9a0bce97ed5fc7ce7712c66e3757576e846324c9 100644 (file)
@@ -166,7 +166,7 @@ class Tahoe2PeerSelector:
         self.use_peers = set() # PeerTrackers that have shares assigned to them
         self.preexisting_shares = {} # sharenum -> peerid holding the share
 
-        sb = client.storage_broker
+        sb = client.get_storage_broker()
         peers = list(sb.get_servers(storage_index))
         if not peers:
             raise NoServersError("client gave us zero peers")
index 8ac19ef99c5c20172ca8c2ceafcb3d31e135de8b..b833b8f4256f791f8eb093a446bbeabcc7673f3f 100644 (file)
@@ -190,7 +190,7 @@ class Publish:
         assert self._privkey
         self._encprivkey = self._node.get_encprivkey()
 
-        sb = self._node._client.storage_broker
+        sb = self._node._client.get_storage_broker()
         full_peerlist = sb.get_servers(self._storage_index)
         self.full_peerlist = full_peerlist # for use later, immutable
         self.bad_peers = set() # peerids who have errbacked/refused requests
index 565975b271b74b8fd006145f912b6d296703965a..9c59858077976fa8ab7b675d2f17593bc98bf278 100644 (file)
@@ -421,7 +421,7 @@ class ServermapUpdater:
 
         self._queries_completed = 0
 
-        sb = self._node._client.storage_broker
+        sb = self._node._client.get_storage_broker()
         full_peerlist = list(sb.get_servers(self._node._storage_index))
         self.full_peerlist = full_peerlist # for use later, immutable
         self.extra_peers = full_peerlist[:] # peers are removed as we use them
index e9d88a3303dd5683ee0185a8f279a87b3c8b0d2d..03b57530d41711470057646793f1be362bcb7629 100644 (file)
@@ -9,6 +9,8 @@ from common_web import WebRenderingMixin
 class FakeClient:
     def get_nickname_for_serverid(self, serverid):
         return self.storage_broker.get_nickname_for_serverid(serverid)
+    def get_storage_broker(self):
+        return self.storage_broker
 
 class WebResultsRendering(unittest.TestCase, WebRenderingMixin):
 
index 32b3ab86df84050ccb09a8876dccfe1cc6e68c68..38ce5eee857b182d6361eabd1c07dbb5d5f57b5e 100644 (file)
@@ -68,6 +68,8 @@ class FakeClient(service.MultiService):
         return log.msg(*args, **kwargs)
     def get_encoding_parameters(self):
         return self.DEFAULT_ENCODING_PARAMETERS
+    def get_storage_broker(self):
+        return self.storage_broker
 
 def flush_but_dont_ignore(res):
     d = flushEventualQueue()
index 1ac21f94adfccfd51258913c8056b5d3fbe971bd..942fa7628fcee13a15dbd783bd5d836614756533 100644 (file)
@@ -181,6 +181,8 @@ class FakeClient:
 
     def get_all_serverids(self):
         return self.storage_broker.get_all_serverids()
+    def get_storage_broker(self):
+        return self.storage_broker
     def debug_break_connection(self, peerid):
         self.storage_broker.servers[peerid].broken = True
     def debug_remove_connection(self, peerid):
index 52d17796c6994df0aae74dd292aa28153ffc18c5..4d0f764f835ffa7d2096ae4466b7baed776e04a7 100644 (file)
@@ -177,6 +177,8 @@ class FakeClient:
         pass
     def get_encoding_parameters(self):
         return self.DEFAULT_ENCODING_PARAMETERS
+    def get_storage_broker(self):
+        return self.storage_broker
 
     def get_renewal_secret(self):
         return ""
index 1eb92bb3e57dbceb0549ad5a1fcd42175b428db3..0570473cbcb65142d93c8ec72f9de142bfcec37a 100644 (file)
@@ -69,6 +69,8 @@ class FakeClient(service.MultiService):
         return u"John Doe"
 
     storage_broker = StorageFarmBroker()
+    def get_storage_broker(self):
+        return self.storage_broker
 
     def create_node_from_uri(self, auri):
         precondition(isinstance(auri, str), auri)
index 3228f29977331b0a35229c51d4381f5c9edca62b..cf5634a775c01057926a40a40a99248676690406 100644 (file)
@@ -137,7 +137,7 @@ class ResultsBase:
         add("Unrecoverable Versions", data["count-unrecoverable-versions"])
 
         # this table is sorted by permuted order
-        sb = c.storage_broker
+        sb = c.get_storage_broker()
         permuted_peer_ids = [peerid
                              for (peerid, rref)
                              in sb.get_servers(cr.get_storage_index())]