]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
immutable.Downloader: pass StorageBroker to constructor, stop being a Service
authorBrian Warner <warner@lothar.com>
Sat, 15 Aug 2009 19:25:43 +0000 (12:25 -0700)
committerBrian Warner <warner@lothar.com>
Sat, 15 Aug 2009 19:25:43 +0000 (12:25 -0700)
child of the client, access with client.downloader instead of
client.getServiceNamed("downloader"). The single "Downloader" instance is
scheduled for demolition anyways, to be replaced by individual
filenode.download calls.

src/allmydata/client.py
src/allmydata/control.py
src/allmydata/immutable/download.py
src/allmydata/test/common.py
src/allmydata/test/test_dirnode.py
src/allmydata/test/test_immutable.py
src/allmydata/test/test_system.py

index a664660ae314225dc6d42ceb460aa1e7ed714c1a..197b43864ef2209744662f3d452b8690a11e1a6f 100644 (file)
@@ -264,7 +264,7 @@ class Client(node.Node, pollmixin.PollMixin):
                                          "private", "cache", "download")
         self.download_cache_dirman = cachedir.CacheDirectoryManager(download_cachedir)
         self.download_cache_dirman.setServiceParent(self)
-        self.add_service(Downloader(self.stats_provider))
+        self.downloader = Downloader(self.storage_broker, self.stats_provider)
         self.init_stub_client()
         self.init_nodemaker()
 
@@ -323,7 +323,7 @@ class Client(node.Node, pollmixin.PollMixin):
                                    self._secret_holder,
                                    self.get_history(),
                                    self.getServiceNamed("uploader"),
-                                   self.getServiceNamed("downloader"),
+                                   self.downloader,
                                    self.download_cache_dirman,
                                    self.get_encoding_parameters(),
                                    self._key_generator)
index 060608b44ce25f86a655a8c87327fe4b7cef9626..d629c1366fce8ad7ca46a9958748bc1f751c98a6 100644 (file)
@@ -50,8 +50,7 @@ class ControlServer(Referenceable, service.Service):
         return d
 
     def remote_download_from_uri_to_file(self, uri, filename):
-        downloader = self.parent.getServiceNamed("downloader")
-        d = downloader.download_to_filename(uri, filename)
+        d = self.parent.downloader.download_to_filename(uri, filename)
         d.addCallback(lambda res: filename)
         return d
 
index 01ce4127ab953ed548147875fb62e8c75b013e29..cd185bea1da59dce6e38d312e9db34ccd732ec67 100644 (file)
@@ -2,7 +2,6 @@ import os, random, weakref, itertools, time
 from zope.interface import implements
 from twisted.internet import defer
 from twisted.internet.interfaces import IPushProducer, IConsumer
-from twisted.application import service
 from foolscap.api import DeadReferenceError, RemoteException, eventually
 
 from allmydata.util import base32, deferredutil, hashutil, log, mathutil, idlib
@@ -1185,22 +1184,19 @@ class ConsumerAdapter:
         pass
 
 
-class Downloader(service.MultiService):
+class Downloader:
     """I am a service that allows file downloading.
     """
     # TODO: in fact, this service only downloads immutable files (URI:CHK:).
     # It is scheduled to go away, to be replaced by filenode.download()
     implements(IDownloader)
-    name = "downloader"
 
-    def __init__(self, stats_provider=None):
-        service.MultiService.__init__(self)
+    def __init__(self, storage_broker, stats_provider):
+        self.storage_broker = storage_broker
         self.stats_provider = stats_provider
         self._all_downloads = weakref.WeakKeyDictionary() # for debugging
 
     def download(self, u, t, _log_msg_id=None, monitor=None, history=None):
-        assert self.parent
-        assert self.running
         u = IFileURI(u)
         t = IDownloadTarget(t)
         assert t.write
@@ -1212,12 +1208,12 @@ 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(storage_broker, u.get_verify_cap(), target,
+        dl = CiphertextDownloader(self.storage_broker,
+                                  u.get_verify_cap(), target,
                                   monitor=monitor)
         self._all_downloads[dl] = None
         if history:
index 85cf3cf47e76274cac7187ede8342834e615bde4..2b0777cce0572be56445e18de16e0296d6afc549 100644 (file)
@@ -1027,8 +1027,7 @@ class ShareManglingMixin(SystemTestMixin):
         return sum_of_write_counts
 
     def _download_and_check_plaintext(self, unused=None):
-        self.downloader = self.clients[1].getServiceNamed("downloader")
-        d = self.downloader.download_to_data(self.uri)
+        d = self.clients[1].downloader.download_to_data(self.uri)
 
         def _after_download(result):
             self.failUnlessEqual(result, TEST_DATA)
index 38fc02e284daf40da6e47c238746eeaf028bbea1..d1bf20732e46eef7d5833473acba7dd5b319f793 100644 (file)
@@ -918,7 +918,7 @@ class Deleter(GridTestMixin, unittest.TestCase):
         def _do_delete(ignored):
             nm = UCWEingNodeMaker(c0.storage_broker, c0._secret_holder,
                                   c0.get_history(), c0.getServiceNamed("uploader"),
-                                  c0.getServiceNamed("downloader"),
+                                  c0.downloader,
                                   c0.download_cache_dirman,
                                   c0.get_encoding_parameters(),
                                   c0._key_generator)
index cf46d00d0292c8210abdb3762f7425eba4c3864f..ad1843c04227254268fa6323a4a74e1cc3478448 100644 (file)
@@ -26,8 +26,7 @@ class Test(common.ShareManglingMixin, unittest.TestCase):
         d.addCallback(_then_delete_8)
 
         def _then_download(unused=None):
-            self.downloader = self.clients[1].getServiceNamed("downloader")
-            d2 = self.downloader.download_to_data(self.uri)
+            d2 = self.clients[1].downloader.download_to_data(self.uri)
 
             def _after_download_callb(result):
                 self.fail() # should have gotten an errback instead
@@ -94,8 +93,7 @@ class Test(common.ShareManglingMixin, unittest.TestCase):
 
         before_download_reads = self._count_reads()
         def _attempt_to_download(unused=None):
-            downloader = self.clients[1].getServiceNamed("downloader")
-            d2 = downloader.download_to_data(self.uri)
+            d2 = self.clients[1].downloader.download_to_data(self.uri)
 
             def _callb(res):
                 self.fail("Should have gotten an error from attempt to download, not %r" % (res,))
@@ -128,8 +126,7 @@ class Test(common.ShareManglingMixin, unittest.TestCase):
 
         before_download_reads = self._count_reads()
         def _attempt_to_download(unused=None):
-            downloader = self.clients[1].getServiceNamed("downloader")
-            d2 = downloader.download_to_data(self.uri)
+            d2 = self.clients[1].downloader.download_to_data(self.uri)
 
             def _callb(res):
                 self.fail("Should have gotten an error from attempt to download, not %r" % (res,))
index 5fa7e41ddb8f1cb27aa6521b1f4a461006b6fa02..b3126fef62af87e0bf774e4887d704d66d436163 100644 (file)
@@ -135,8 +135,7 @@ class SystemTest(SystemTestMixin, unittest.TestCase):
             log.msg("upload finished: uri is %s" % (theuri,))
             self.uri = theuri
             assert isinstance(self.uri, str), self.uri
-            dl = self.clients[1].getServiceNamed("downloader")
-            self.downloader = dl
+            self.downloader = self.clients[1].downloader
         d.addCallback(_upload_done)
 
         def _upload_again(res):