"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()
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)
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
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
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
# 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:
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)
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)
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
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,))
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,))
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):