]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blobdiff - src/allmydata/immutable/downloader/segmentation.py
move DownloadStopped from download.common to interfaces
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / immutable / downloader / segmentation.py
index 4890195c6cf39c66ae395bb57fb5e8a956792395..07307c36705db0c353a445d1d775929d751b4135 100644 (file)
@@ -7,8 +7,9 @@ from twisted.internet.interfaces import IPushProducer
 from foolscap.api import eventually
 from allmydata.util import log
 from allmydata.util.spans import overlap
+from allmydata.interfaces import DownloadStopped
 
-from common import BadSegmentNumberError, WrongSegmentError, DownloadStopped
+from common import BadSegmentNumberError, WrongSegmentError
 
 class Segmentation:
     """I am responsible for a single offset+size read of the file. I handle
@@ -36,10 +37,15 @@ class Segmentation:
     def start(self):
         self._alive = True
         self._deferred = defer.Deferred()
+        self._deferred.addBoth(self._done)
         self._consumer.registerProducer(self, True)
         self._maybe_fetch_next()
         return self._deferred
 
+    def _done(self, res):
+        self._consumer.unregisterProducer()
+        return res
+
     def _maybe_fetch_next(self):
         if not self._alive or not self._hungry:
             return
@@ -52,7 +58,6 @@ class Segmentation:
             # done!
             self._alive = False
             self._hungry = False
-            self._consumer.unregisterProducer()
             self._deferred.callback(self._consumer)
             return
         n = self._node
@@ -119,6 +124,8 @@ class Segmentation:
         # the consumer might call our .pauseProducing() inside that write()
         # call, setting self._hungry=False
         self._read_ev.update(len(desired_data), 0, 0)
+        # note: filenode.DecryptingConsumer is responsible for calling
+        # _read_ev.update with how much decrypt_time was consumed
         self._maybe_fetch_next()
 
     def _retry_bad_segment(self, f):
@@ -135,10 +142,11 @@ class Segmentation:
                 level=log.WEIRD, parent=self._lp, umid="EYlXBg")
         self._alive = False
         self._hungry = False
-        self._consumer.unregisterProducer()
         self._deferred.errback(f)
 
     def stopProducing(self):
+        log.msg("asked to stopProducing",
+                level=log.NOISY, parent=self._lp, umid="XIyL9w")
         self._hungry = False
         self._alive = False
         # cancel any outstanding segment request