diff --git a/lbrynet/lbry_file/client/EncryptedFileMetadataHandler.py b/lbrynet/lbry_file/client/EncryptedFileMetadataHandler.py index bd09dfdfc..116ac7080 100644 --- a/lbrynet/lbry_file/client/EncryptedFileMetadataHandler.py +++ b/lbrynet/lbry_file/client/EncryptedFileMetadataHandler.py @@ -1,5 +1,6 @@ import logging from zope.interface import implements +from twisted.internet import defer from lbrynet.cryptstream.CryptBlob import CryptBlobInfo from lbrynet.interfaces import IMetadataHandler @@ -18,10 +19,11 @@ class EncryptedFileMetadataHandler(object): ######### IMetadataHandler ######### + @defer.inlineCallbacks def get_initial_blobs(self): - d = self.stream_info_manager.get_blobs_for_stream(self.stream_hash) - d.addCallback(self._format_initial_blobs_for_download_manager) - return d + blob_infos = yield self.stream_info_manager.get_blobs_for_stream(self.stream_hash) + formatted_infos = self._format_initial_blobs_for_download_manager(blob_infos) + defer.returnValue(formatted_infos) def final_blob_num(self): return self._final_blob_num @@ -30,10 +32,12 @@ class EncryptedFileMetadataHandler(object): def _format_initial_blobs_for_download_manager(self, blob_infos): infos = [] - for blob_hash, blob_num, iv, length in blob_infos: - if blob_hash is not None: + for i, (blob_hash, blob_num, iv, length) in enumerate(blob_infos): + if blob_hash is not None and length: infos.append(CryptBlobInfo(blob_hash, blob_num, length, iv)) else: + if i != len(blob_infos) - 1: + raise Exception("Invalid stream terminator") log.debug("Setting _final_blob_num to %s", str(blob_num - 1)) self._final_blob_num = blob_num - 1 return infos