]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
offloaded: oops, need more tricks to make the unit tests pass
authorBrian Warner <warner@allmydata.com>
Thu, 7 Feb 2008 00:51:11 +0000 (17:51 -0700)
committerBrian Warner <warner@allmydata.com>
Thu, 7 Feb 2008 00:51:11 +0000 (17:51 -0700)
src/allmydata/offloaded.py
src/allmydata/test/test_helper.py
src/allmydata/upload.py

index 2e2c4877807ec3903c4a7f00c2b420624b5f8e08..319e05aed723412fe3de2db94f4d97b920deb72a 100644 (file)
@@ -194,7 +194,6 @@ class CHKUploadHelper(Referenceable, upload.CHKUploader):
         (uri_extension_hash, needed_shares, total_shares, size) = res
         r = self._results
         r.uri_extension_hash = uri_extension_hash
-        r.uri_extension_data = self._encoder.get_uri_extension_data()
         f_times = self._fetcher.get_times()
         r.timings["cumulative_fetch"] = f_times["cumulative_fetch"]
         r.ciphertext_fetched = self._fetcher.get_ciphertext_fetched()
index e1e8b0c6e401eb3443d70ec2b1f24d62e93a504b..b45811a8331ad4be77be0bd61142bd142cd7e912 100644 (file)
@@ -12,6 +12,8 @@ from pycryptopp.cipher.aes import AES
 
 MiB = 1024*1024
 
+DATA = "I need help\n" * 1000
+
 class CHKUploadHelper_fake(offloaded.CHKUploadHelper):
     def start_encrypted(self, eu):
         d = eu.get_size()
@@ -19,6 +21,12 @@ class CHKUploadHelper_fake(offloaded.CHKUploadHelper):
             d2 = eu.get_all_encoding_parameters()
             def _got_parms(parms):
                 needed_shares, happy, total_shares, segsize = parms
+                ueb_data = {"needed_shares": needed_shares,
+                            "total_shares": total_shares,
+                            "segment_size": segsize,
+                            "size": size,
+                            }
+                self._results.uri_extension_data = ueb_data
                 return (hashutil.uri_extension_hash(""),
                         needed_shares, total_shares, size)
             d2.addCallback(_got_parms)
@@ -30,6 +38,18 @@ class CHKUploadHelper_already_uploaded(offloaded.CHKUploadHelper):
     def start(self):
         res = upload.UploadResults()
         res.uri_extension_hash = hashutil.uri_extension_hash("")
+
+        # we're pretending that the file they're trying to upload was already
+        # present in the grid. We return some information about the file, so
+        # the client can decide if they like the way it looks. The parameters
+        # used here are chosen to match the defaults.
+        PARAMS = FakeClient.DEFAULT_ENCODING_PARAMETERS
+        ueb_data = {"needed_shares": PARAMS["k"],
+                    "total_shares": PARAMS["n"],
+                    "segment_size": min(PARAMS["max_segment_size"], len(DATA)),
+                    "size": len(DATA),
+                    }
+        res.uri_extension_data = ueb_data
         return (res, None)
 
 class FakeClient(service.MultiService):
@@ -96,7 +116,6 @@ class AssistedUpload(unittest.TestCase):
         def _ready(res):
             assert u._helper
 
-            DATA = "I need help\n" * 1000
             return upload_data(u, DATA)
         d.addCallback(_ready)
         def _uploaded(results):
@@ -116,7 +135,6 @@ class AssistedUpload(unittest.TestCase):
     def test_previous_upload_failed(self):
         self.basedir = "helper/AssistedUpload/test_previous_upload_failed"
         self.setUpHelper(self.basedir)
-        DATA = "I need help\n" * 1000
 
         # we want to make sure that an upload which fails (leaving the
         # ciphertext in the CHK_encoding/ directory) does not prevent a later
@@ -172,7 +190,6 @@ class AssistedUpload(unittest.TestCase):
         def _ready(res):
             assert u._helper
 
-            DATA = "I need help\n" * 1000
             return upload_data(u, DATA)
         d.addCallback(_ready)
         def _uploaded(results):
index 2662f6a296101d0e13723e58e2861fa395baad80..8e43e02c2165db5d2f3c31b306c9191e8e4d6f01 100644 (file)
@@ -668,6 +668,7 @@ class CHKUploader:
         r.timings["storage_index"] = self._storage_index_elapsed
         r.timings["peer_selection"] = self._peer_selection_elapsed
         r.timings.update(self._encoder.get_times())
+        r.uri_extension_data = self._encoder.get_uri_extension_data()
         return res
 
     def _compute_uri(self, (uri_extension_hash,