From 574660cc2084c96806cc6af4c19d6115abe71508 Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Thu, 12 Oct 2017 11:14:03 -0400 Subject: [PATCH 1/4] add test to count the number of blobs created by EncryptedFileCreator --- .../test_EncryptedFileCreator.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lbrynet/tests/unit/lbryfilemanager/test_EncryptedFileCreator.py b/lbrynet/tests/unit/lbryfilemanager/test_EncryptedFileCreator.py index 1e0601455..3070b93e6 100644 --- a/lbrynet/tests/unit/lbryfilemanager/test_EncryptedFileCreator.py +++ b/lbrynet/tests/unit/lbryfilemanager/test_EncryptedFileCreator.py @@ -46,18 +46,23 @@ class CreateEncryptedFileTest(unittest.TestCase): session, manager, filename, handle, key, iv_generator()) defer.returnValue(out) + @defer.inlineCallbacks def test_can_create_file(self): expected_stream_hash = ('41e6b247d923d191b154fb6f1b8529d6ddd6a73d65c357b1acb7' '42dd83151fb66393a7709e9f346260a4f4db6de10c25') filename = 'test.file' - d = self.create_file(filename) - d.addCallback(self.assertEqual, expected_stream_hash) - return d + stream_hash = yield self.create_file(filename) + self.assertEqual(expected_stream_hash, stream_hash) + blobs = yield self.blob_manager.get_all_verified_blobs() + self.assertEqual(2, len(blobs)) + num_should_announce_blobs = yield self.blob_manager.count_should_announce_blobs() + self.assertEqual(1, num_should_announce_blobs) + + @defer.inlineCallbacks def test_can_create_file_with_unicode_filename(self): expected_stream_hash = ('d1da4258f3ce12edb91d7e8e160d091d3ab1432c2e55a6352dce0' '2fd5adb86fe144e93e110075b5865fff8617776c6c0') filename = u'☃.file' - d = self.create_file(filename) - d.addCallback(self.assertEqual, expected_stream_hash) - return d + stream_hash = yield self.create_file(filename) + self.assertEqual(expected_stream_hash, stream_hash) From 551eab9a426f9c80cc97cd1aee85df9c3312d813 Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Thu, 12 Oct 2017 11:25:52 -0400 Subject: [PATCH 2/4] fix bug where last blob in a stream was not saved to blob manager --- lbrynet/cryptstream/CryptStreamCreator.py | 27 ++++++++++++----------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lbrynet/cryptstream/CryptStreamCreator.py b/lbrynet/cryptstream/CryptStreamCreator.py index 9c94ad476..019b1f4d6 100644 --- a/lbrynet/cryptstream/CryptStreamCreator.py +++ b/lbrynet/cryptstream/CryptStreamCreator.py @@ -69,17 +69,23 @@ class CryptStreamCreator(object): self.stopped = True self.producer = None + def _close_current_blob(self): + # close the blob that was being written to + # and save it to blob manager + should_announce = self.blob_count == 0 + d = self.current_blob.close() + d.addCallback(self._blob_finished) + d.addCallback(lambda blob_info: self.blob_manager.creator_finished(blob_info, + should_announce)) + self.finished_deferreds.append(d) + self.current_blob = None + def stop(self): """Stop creating the stream. Create the terminating zero-length blob.""" log.debug("stop has been called for StreamCreator") self.stopped = True if self.current_blob is not None: - current_blob = self.current_blob - d = current_blob.close() - d.addCallback(self._blob_finished) - d.addErrback(self._error) - self.finished_deferreds.append(d) - self.current_blob = None + self._close_current_blob() self._finalize() dl = defer.DeferredList(self.finished_deferreds) dl.addCallback(lambda _: self._finished()) @@ -123,6 +129,7 @@ class CryptStreamCreator(object): d.addCallback(self._blob_finished) self.finished_deferreds.append(d) + def _write(self, data): while len(data) > 0: if self.current_blob is None: @@ -133,13 +140,7 @@ class CryptStreamCreator(object): done, num_bytes_written = self.current_blob.write(data) data = data[num_bytes_written:] if done is True: - should_announce = self.blob_count == 0 - d = self.current_blob.close() - d.addCallback(self._blob_finished) - d.addCallback(lambda blob_info: self.blob_manager.creator_finished(blob_info, - should_announce)) - self.finished_deferreds.append(d) - self.current_blob = None + self._close_current_blob() def _get_blob_maker(self, iv, blob_creator): return CryptStreamBlobMaker(self.key, iv, self.blob_count, blob_creator) From 42990b582f1bf80845458d1f29c5fd45d7665008 Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Thu, 12 Oct 2017 11:26:44 -0400 Subject: [PATCH 3/4] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 609400329..975daf377 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ at anytime. * Fixed hanging delayedCall in dht node class * Fixed logging error in dht when calling or receiving methods with no arguments * Fixed IndexError in routingTable.findCloseNodes which would cause an empty list to be returned + * Fixed bug where last blob in a stream was not saved to blob manager ### Deprecated * Deprecated `blob_announce_all` JSONRPC command. Use `blob_announce` instead. From 8b2b5b991ba41e65e4099ba8fdabf4182aa57df5 Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Thu, 12 Oct 2017 12:17:04 -0400 Subject: [PATCH 4/4] remove unneeded _error function from CryptStreamCreator --- lbrynet/cryptstream/CryptStreamCreator.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lbrynet/cryptstream/CryptStreamCreator.py b/lbrynet/cryptstream/CryptStreamCreator.py index 019b1f4d6..b0a2db2d2 100644 --- a/lbrynet/cryptstream/CryptStreamCreator.py +++ b/lbrynet/cryptstream/CryptStreamCreator.py @@ -89,7 +89,6 @@ class CryptStreamCreator(object): self._finalize() dl = defer.DeferredList(self.finished_deferreds) dl.addCallback(lambda _: self._finished()) - dl.addErrback(self._error) return dl # TODO: move the stream creation process to its own thread and @@ -145,9 +144,6 @@ class CryptStreamCreator(object): def _get_blob_maker(self, iv, blob_creator): return CryptStreamBlobMaker(self.key, iv, self.blob_count, blob_creator) - def _error(self, error): - log.error(error) - def _finished(self): raise NotImplementedError()