From c89a464510394089672d4f937c9707d5ca5e5ca9 Mon Sep 17 00:00:00 2001
From: Brian Warner <warner@lothar.com>
Date: Tue, 31 Aug 2010 18:35:58 -0700
Subject: [PATCH] Share: drop received data after each block finishes. Quick
 fix for the #1170 spans.py complexity bug.

---
 src/allmydata/immutable/downloader/share.py | 3 +++
 src/allmydata/test/test_immutable.py        | 4 ++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/allmydata/immutable/downloader/share.py b/src/allmydata/immutable/downloader/share.py
index f7ed4e86..413f9077 100644
--- a/src/allmydata/immutable/downloader/share.py
+++ b/src/allmydata/immutable/downloader/share.py
@@ -531,6 +531,9 @@ class Share:
             for o in observers:
                 # goes to SegmentFetcher._block_request_activity
                 o.notify(state=COMPLETE, block=block)
+            # now clear our received data, to dodge the #1170 spans.py
+            # complexity bug
+            self._received = DataSpans()
         except (BadHashError, NotEnoughHashesError), e:
             # rats, we have a corrupt block. Notify our clients that they
             # need to look elsewhere, and advise the server. Unlike
diff --git a/src/allmydata/test/test_immutable.py b/src/allmydata/test/test_immutable.py
index 813c5bef..288332d0 100644
--- a/src/allmydata/test/test_immutable.py
+++ b/src/allmydata/test/test_immutable.py
@@ -52,7 +52,7 @@ class Test(common.ShareManglingMixin, common.ShouldFailMixin, unittest.TestCase)
         def _after_download(unused=None):
             after_download_reads = self._count_reads()
             #print before_download_reads, after_download_reads
-            self.failIf(after_download_reads-before_download_reads > 27,
+            self.failIf(after_download_reads-before_download_reads > 36,
                         (after_download_reads, before_download_reads))
         d.addCallback(self._download_and_check_plaintext)
         d.addCallback(_after_download)
@@ -70,7 +70,7 @@ class Test(common.ShareManglingMixin, common.ShouldFailMixin, unittest.TestCase)
         def _after_download(unused=None):
             after_download_reads = self._count_reads()
             #print before_download_reads, after_download_reads
-            self.failIf(after_download_reads-before_download_reads > 27, (after_download_reads, before_download_reads))
+            self.failIf(after_download_reads-before_download_reads > 37, (after_download_reads, before_download_reads))
         d.addCallback(self._download_and_check_plaintext)
         d.addCallback(_after_download)
         return d
-- 
2.45.2