forked from LBRYCommunity/lbry-sdk
Remove upload_allowed attribute
This is unused and largely pulluting the argument list of too many functions.
This commit is contained in:
parent
9f4ccfe7c3
commit
a38e5c855e
11 changed files with 47 additions and 64 deletions
|
@ -24,13 +24,13 @@ class BlobManager(DHTHashSupplier):
|
|||
def setup(self):
|
||||
pass
|
||||
|
||||
def get_blob(self, blob_hash, upload_allowed, length):
|
||||
def get_blob(self, blob_hash, length=None):
|
||||
pass
|
||||
|
||||
def get_blob_creator(self):
|
||||
pass
|
||||
|
||||
def _make_new_blob(self, blob_hash, upload_allowed, length):
|
||||
def _make_new_blob(self, blob_hash, length):
|
||||
pass
|
||||
|
||||
def blob_completed(self, blob, next_announce_time=None):
|
||||
|
@ -107,22 +107,20 @@ class DiskBlobManager(BlobManager):
|
|||
self.db_conn = None
|
||||
return defer.succeed(True)
|
||||
|
||||
def get_blob(self, blob_hash, upload_allowed, length=None):
|
||||
def get_blob(self, blob_hash, length=None):
|
||||
"""Return a blob identified by blob_hash, which may be a new blob or a
|
||||
blob that is already on the hard disk
|
||||
"""
|
||||
# TODO: if blob.upload_allowed and upload_allowed is False,
|
||||
# change upload_allowed in blob and on disk
|
||||
if blob_hash in self.blobs:
|
||||
return defer.succeed(self.blobs[blob_hash])
|
||||
return self._make_new_blob(blob_hash, upload_allowed, length)
|
||||
return self._make_new_blob(blob_hash, length)
|
||||
|
||||
def get_blob_creator(self):
|
||||
return self.blob_creator_type(self, self.blob_dir)
|
||||
|
||||
def _make_new_blob(self, blob_hash, upload_allowed, length=None):
|
||||
def _make_new_blob(self, blob_hash, length=None):
|
||||
log.debug('Making a new blob for %s', blob_hash)
|
||||
blob = self.blob_type(self.blob_dir, blob_hash, upload_allowed, length)
|
||||
blob = self.blob_type(self.blob_dir, blob_hash, length)
|
||||
self.blobs[blob_hash] = blob
|
||||
return defer.succeed(blob)
|
||||
|
||||
|
@ -144,7 +142,7 @@ class DiskBlobManager(BlobManager):
|
|||
assert blob_creator.blob_hash is not None
|
||||
assert blob_creator.blob_hash not in self.blobs
|
||||
assert blob_creator.length is not None
|
||||
new_blob = self.blob_type(self.blob_dir, blob_creator.blob_hash, True, blob_creator.length)
|
||||
new_blob = self.blob_type(self.blob_dir, blob_creator.blob_hash, blob_creator.length)
|
||||
self.blobs[blob_creator.blob_hash] = new_blob
|
||||
self._immediate_announce([blob_creator.blob_hash])
|
||||
next_announce_time = self.get_next_announce_time()
|
||||
|
@ -364,16 +362,16 @@ class TempBlobManager(BlobManager):
|
|||
self._next_manage_call.cancel()
|
||||
self._next_manage_call = None
|
||||
|
||||
def get_blob(self, blob_hash, upload_allowed, length=None):
|
||||
def get_blob(self, blob_hash, length=None):
|
||||
if blob_hash in self.blobs:
|
||||
return defer.succeed(self.blobs[blob_hash])
|
||||
return self._make_new_blob(blob_hash, upload_allowed, length)
|
||||
return self._make_new_blob(blob_hash, length)
|
||||
|
||||
def get_blob_creator(self):
|
||||
return self.blob_creator_type(self)
|
||||
|
||||
def _make_new_blob(self, blob_hash, upload_allowed, length=None):
|
||||
blob = self.blob_type(blob_hash, upload_allowed, length)
|
||||
def _make_new_blob(self, blob_hash, length=None):
|
||||
blob = self.blob_type(blob_hash, length)
|
||||
self.blobs[blob_hash] = blob
|
||||
return defer.succeed(blob)
|
||||
|
||||
|
@ -409,7 +407,7 @@ class TempBlobManager(BlobManager):
|
|||
assert blob_creator.blob_hash is not None
|
||||
assert blob_creator.blob_hash not in self.blobs
|
||||
assert blob_creator.length is not None
|
||||
new_blob = self.blob_type(blob_creator.blob_hash, True, blob_creator.length)
|
||||
new_blob = self.blob_type(blob_creator.blob_hash, blob_creator.length)
|
||||
# TODO: change this; its breaks the encapsulation of the
|
||||
# blob. Maybe better would be to have the blob_creator
|
||||
# produce a blob.
|
||||
|
|
|
@ -82,14 +82,13 @@ class HashBlobWriter(object):
|
|||
class HashBlob(object):
|
||||
"""A chunk of data available on the network which is specified by a hashsum"""
|
||||
|
||||
def __init__(self, blob_hash, upload_allowed, length=None):
|
||||
def __init__(self, blob_hash, length=None):
|
||||
assert is_valid_blobhash(blob_hash)
|
||||
self.blob_hash = blob_hash
|
||||
self.length = length
|
||||
self.writers = {} # {Peer: writer, finished_deferred}
|
||||
self.finished_deferred = None
|
||||
self._verified = False
|
||||
self.upload_allowed = upload_allowed
|
||||
self.readers = 0
|
||||
|
||||
@property
|
||||
|
|
|
@ -11,9 +11,8 @@ log = logging.getLogger(__name__)
|
|||
class DownloadManager(object):
|
||||
implements(interfaces.IDownloadManager)
|
||||
|
||||
def __init__(self, blob_manager, upload_allowed):
|
||||
def __init__(self, blob_manager):
|
||||
self.blob_manager = blob_manager
|
||||
self.upload_allowed = upload_allowed
|
||||
self.blob_info_finder = None
|
||||
self.progress_manager = None
|
||||
self.blob_handler = None
|
||||
|
@ -82,8 +81,7 @@ class DownloadManager(object):
|
|||
self.blob_infos[blob_info.blob_num] = blob_info
|
||||
log.debug(
|
||||
"Trying to get the blob associated with blob hash %s", blob_info.blob_hash)
|
||||
d = self.blob_manager.get_blob(
|
||||
blob_info.blob_hash, self.upload_allowed, blob_info.length)
|
||||
d = self.blob_manager.get_blob(blob_info.blob_hash, blob_info.length)
|
||||
d.addCallback(add_blob_to_list, blob_info.blob_num)
|
||||
d.addErrback(error_during_add)
|
||||
ds.append(d)
|
||||
|
|
|
@ -112,7 +112,7 @@ class StandaloneBlobDownloader(object):
|
|||
self.stop()
|
||||
|
||||
self.finished_deferred = defer.Deferred(canceller=cancel_download)
|
||||
self.download_manager = DownloadManager(self.blob_manager, True)
|
||||
self.download_manager = DownloadManager(self.blob_manager)
|
||||
self.download_manager.blob_requester = BlobRequester(self.blob_manager, self.peer_finder,
|
||||
self.payment_rate_manager, self.wallet,
|
||||
self.download_manager)
|
||||
|
|
|
@ -38,7 +38,7 @@ class CryptStreamDownloader(object):
|
|||
implements(IStreamDownloader)
|
||||
|
||||
def __init__(self, peer_finder, rate_limiter, blob_manager,
|
||||
payment_rate_manager, wallet, upload_allowed):
|
||||
payment_rate_manager, wallet):
|
||||
"""Initialize a CryptStreamDownloader
|
||||
|
||||
@param peer_finder: An object which implements the IPeerFinder
|
||||
|
@ -61,7 +61,6 @@ class CryptStreamDownloader(object):
|
|||
self.blob_manager = blob_manager
|
||||
self.payment_rate_manager = payment_rate_manager
|
||||
self.wallet = wallet
|
||||
self.upload_allowed = upload_allowed
|
||||
self.key = None
|
||||
self.stream_name = None
|
||||
self.completed = False
|
||||
|
@ -146,7 +145,7 @@ class CryptStreamDownloader(object):
|
|||
|
||||
def _get_download_manager(self):
|
||||
assert self.blob_requester is None
|
||||
download_manager = DownloadManager(self.blob_manager, self.upload_allowed)
|
||||
download_manager = DownloadManager(self.blob_manager)
|
||||
# TODO: can we get rid of these circular references. I'm not
|
||||
# smart enough to handle thinking about the interactions
|
||||
# between them and have hope that there is a simpler way
|
||||
|
|
|
@ -23,9 +23,9 @@ class EncryptedFileDownloader(CryptStreamDownloader):
|
|||
"""Classes which inherit from this class download LBRY files"""
|
||||
|
||||
def __init__(self, stream_hash, peer_finder, rate_limiter, blob_manager,
|
||||
stream_info_manager, payment_rate_manager, wallet, upload_allowed):
|
||||
stream_info_manager, payment_rate_manager, wallet):
|
||||
CryptStreamDownloader.__init__(self, peer_finder, rate_limiter, blob_manager,
|
||||
payment_rate_manager, wallet, upload_allowed)
|
||||
payment_rate_manager, wallet)
|
||||
self.stream_hash = stream_hash
|
||||
self.stream_info_manager = stream_info_manager
|
||||
self.suggested_file_name = None
|
||||
|
@ -141,7 +141,6 @@ class EncryptedFileDownloaderFactory(object):
|
|||
|
||||
def make_downloader(self, metadata, options, payment_rate_manager, **kwargs):
|
||||
payment_rate_manager.min_blob_data_payment_rate = options[0]
|
||||
upload_allowed = options[1]
|
||||
|
||||
def save_source_if_blob(stream_hash):
|
||||
if metadata.metadata_source == StreamMetadata.FROM_BLOB:
|
||||
|
@ -154,7 +153,7 @@ class EncryptedFileDownloaderFactory(object):
|
|||
|
||||
def create_downloader(stream_hash):
|
||||
downloader = self._make_downloader(stream_hash, payment_rate_manager,
|
||||
metadata.validator.raw_info, upload_allowed)
|
||||
metadata.validator.raw_info)
|
||||
d = downloader.set_stream_info()
|
||||
d.addCallback(lambda _: downloader)
|
||||
return d
|
||||
|
@ -164,18 +163,17 @@ class EncryptedFileDownloaderFactory(object):
|
|||
d.addCallback(create_downloader)
|
||||
return d
|
||||
|
||||
def _make_downloader(self, stream_hash, payment_rate_manager, stream_info, upload_allowed):
|
||||
def _make_downloader(self, stream_hash, payment_rate_manager, stream_info):
|
||||
pass
|
||||
|
||||
|
||||
class EncryptedFileSaver(EncryptedFileDownloader):
|
||||
def __init__(self, stream_hash, peer_finder, rate_limiter, blob_manager, stream_info_manager,
|
||||
payment_rate_manager, wallet, download_directory, upload_allowed, file_name=None):
|
||||
payment_rate_manager, wallet, download_directory, file_name=None):
|
||||
EncryptedFileDownloader.__init__(self, stream_hash,
|
||||
peer_finder, rate_limiter,
|
||||
blob_manager, stream_info_manager,
|
||||
payment_rate_manager, wallet,
|
||||
upload_allowed)
|
||||
payment_rate_manager, wallet)
|
||||
self.download_directory = download_directory
|
||||
self.file_name = file_name
|
||||
self.file_written_to = None
|
||||
|
@ -208,9 +206,7 @@ class EncryptedFileSaver(EncryptedFileDownloader):
|
|||
def _get_progress_manager(self, download_manager):
|
||||
return FullStreamProgressManager(self._finished_downloading,
|
||||
self.blob_manager,
|
||||
download_manager,
|
||||
delete_blob_after_finished=not
|
||||
self.upload_allowed)
|
||||
download_manager)
|
||||
|
||||
def _setup_output(self):
|
||||
def open_file():
|
||||
|
@ -274,12 +270,12 @@ class EncryptedFileSaverFactory(EncryptedFileDownloaderFactory):
|
|||
stream_info_manager, wallet)
|
||||
self.download_directory = download_directory
|
||||
|
||||
def _make_downloader(self, stream_hash, payment_rate_manager, stream_info, upload_allowed):
|
||||
def _make_downloader(self, stream_hash, payment_rate_manager, stream_info):
|
||||
return EncryptedFileSaver(stream_hash, self.peer_finder,
|
||||
self.rate_limiter, self.blob_manager,
|
||||
self.stream_info_manager,
|
||||
payment_rate_manager, self.wallet,
|
||||
self.download_directory, upload_allowed)
|
||||
self.download_directory)
|
||||
|
||||
@staticmethod
|
||||
def get_description():
|
||||
|
@ -288,12 +284,12 @@ class EncryptedFileSaverFactory(EncryptedFileDownloaderFactory):
|
|||
|
||||
class EncryptedFileOpener(EncryptedFileDownloader):
|
||||
def __init__(self, stream_hash, peer_finder, rate_limiter, blob_manager, stream_info_manager,
|
||||
payment_rate_manager, wallet, upload_allowed):
|
||||
payment_rate_manager, wallet):
|
||||
EncryptedFileDownloader.__init__(self, stream_hash,
|
||||
peer_finder, rate_limiter,
|
||||
blob_manager, stream_info_manager,
|
||||
payment_rate_manager, wallet,
|
||||
upload_allowed)
|
||||
)
|
||||
self.process = None
|
||||
self.process_log = None
|
||||
|
||||
|
@ -305,9 +301,7 @@ class EncryptedFileOpener(EncryptedFileDownloader):
|
|||
def _get_progress_manager(self, download_manager):
|
||||
return FullStreamProgressManager(self._finished_downloading,
|
||||
self.blob_manager,
|
||||
download_manager,
|
||||
delete_blob_after_finished=not
|
||||
self.upload_allowed)
|
||||
download_manager)
|
||||
|
||||
def _setup_output(self):
|
||||
def start_process():
|
||||
|
@ -363,12 +357,12 @@ class EncryptedFileOpenerFactory(EncryptedFileDownloaderFactory):
|
|||
return True
|
||||
return False
|
||||
|
||||
def _make_downloader(self, stream_hash, payment_rate_manager, stream_info, upload_allowed):
|
||||
def _make_downloader(self, stream_hash, payment_rate_manager, stream_info):
|
||||
return EncryptedFileOpener(stream_hash, self.peer_finder,
|
||||
self.rate_limiter, self.blob_manager,
|
||||
self.stream_info_manager,
|
||||
payment_rate_manager, self.wallet,
|
||||
upload_allowed)
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_description():
|
||||
|
|
|
@ -25,13 +25,13 @@ class ManagedEncryptedFileDownloader(EncryptedFileSaver):
|
|||
def __init__(self, rowid, stream_hash, peer_finder, rate_limiter,
|
||||
blob_manager, stream_info_manager, lbry_file_manager,
|
||||
payment_rate_manager, wallet, download_directory,
|
||||
upload_allowed, file_name=None):
|
||||
file_name=None):
|
||||
EncryptedFileSaver.__init__(self, stream_hash, peer_finder,
|
||||
rate_limiter, blob_manager,
|
||||
stream_info_manager,
|
||||
payment_rate_manager, wallet,
|
||||
download_directory,
|
||||
upload_allowed, file_name)
|
||||
file_name)
|
||||
self.sd_hash = None
|
||||
self.txid = None
|
||||
self.nout = None
|
||||
|
@ -151,15 +151,15 @@ class ManagedEncryptedFileDownloaderFactory(object):
|
|||
@defer.inlineCallbacks
|
||||
def make_downloader(self, metadata, options, payment_rate_manager, download_directory=None,
|
||||
file_name=None):
|
||||
# TODO: change options argument to only be data_rate
|
||||
data_rate = options[0]
|
||||
upload_allowed = options[1]
|
||||
stream_hash = yield save_sd_info(self.lbry_file_manager.stream_info_manager,
|
||||
metadata.validator.raw_info)
|
||||
if metadata.metadata_source == StreamMetadata.FROM_BLOB:
|
||||
yield self.lbry_file_manager.save_sd_blob_hash_to_stream(stream_hash,
|
||||
metadata.source_blob_hash)
|
||||
lbry_file = yield self.lbry_file_manager.add_lbry_file(stream_hash, payment_rate_manager,
|
||||
data_rate, upload_allowed,
|
||||
data_rate,
|
||||
download_directory, file_name)
|
||||
defer.returnValue(lbry_file)
|
||||
|
||||
|
|
|
@ -137,7 +137,7 @@ class EncryptedFileManager(object):
|
|||
|
||||
@defer.inlineCallbacks
|
||||
def start_lbry_file(self, rowid, stream_hash,
|
||||
payment_rate_manager, blob_data_rate=None, upload_allowed=True,
|
||||
payment_rate_manager, blob_data_rate=None,
|
||||
download_directory=None, file_name=None):
|
||||
if not download_directory:
|
||||
download_directory = self.download_directory
|
||||
|
@ -153,7 +153,6 @@ class EncryptedFileManager(object):
|
|||
payment_rate_manager,
|
||||
self.session.wallet,
|
||||
download_directory,
|
||||
upload_allowed,
|
||||
file_name=file_name
|
||||
)
|
||||
yield lbry_file_downloader.set_stream_info()
|
||||
|
@ -183,10 +182,10 @@ class EncryptedFileManager(object):
|
|||
|
||||
@defer.inlineCallbacks
|
||||
def add_lbry_file(self, stream_hash, payment_rate_manager, blob_data_rate=None,
|
||||
upload_allowed=True, download_directory=None, file_name=None):
|
||||
download_directory=None, file_name=None):
|
||||
rowid = yield self._save_lbry_file(stream_hash, blob_data_rate)
|
||||
lbry_file = yield self.start_lbry_file(rowid, stream_hash, payment_rate_manager,
|
||||
blob_data_rate, upload_allowed, download_directory,
|
||||
blob_data_rate, download_directory,
|
||||
file_name)
|
||||
defer.returnValue(lbry_file)
|
||||
|
||||
|
|
|
@ -16,9 +16,9 @@ from lbrynet.lbrylive.StreamDescriptor import LiveStreamType
|
|||
class _LiveStreamDownloader(CryptStreamDownloader):
|
||||
|
||||
def __init__(self, stream_hash, peer_finder, rate_limiter, blob_manager, stream_info_manager,
|
||||
payment_rate_manager, wallet, upload_allowed):
|
||||
payment_rate_manager, wallet):
|
||||
CryptStreamDownloader.__init__(self, peer_finder, rate_limiter, blob_manager,
|
||||
payment_rate_manager, wallet, upload_allowed)
|
||||
payment_rate_manager, wallet)
|
||||
self.stream_hash = stream_hash
|
||||
self.stream_info_manager = stream_info_manager
|
||||
self.public_key = None
|
||||
|
@ -42,9 +42,9 @@ class _LiveStreamDownloader(CryptStreamDownloader):
|
|||
|
||||
class LiveStreamDownloader(_LiveStreamDownloader):
|
||||
def __init__(self, stream_hash, peer_finder, rate_limiter, blob_manager, stream_info_manager,
|
||||
payment_rate_manager, wallet, upload_allowed):
|
||||
payment_rate_manager, wallet):
|
||||
_LiveStreamDownloader.__init__(self, stream_hash, peer_finder, rate_limiter, blob_manager,
|
||||
stream_info_manager, payment_rate_manager, wallet, upload_allowed)
|
||||
stream_info_manager, payment_rate_manager, wallet)
|
||||
|
||||
|
||||
def _get_metadata_handler(self, download_manager):
|
||||
|
@ -66,10 +66,10 @@ class LiveStreamDownloader(_LiveStreamDownloader):
|
|||
|
||||
class FullLiveStreamDownloader(_LiveStreamDownloader):
|
||||
def __init__(self, stream_hash, peer_finder, rate_limiter, blob_manager, stream_info_manager,
|
||||
payment_rate_manager, wallet, upload_allowed):
|
||||
payment_rate_manager, wallet):
|
||||
_LiveStreamDownloader.__init__(self, stream_hash, peer_finder, rate_limiter,
|
||||
blob_manager, stream_info_manager, payment_rate_manager,
|
||||
wallet, upload_allowed)
|
||||
wallet)
|
||||
self.file_handle = None
|
||||
self.file_name = None
|
||||
|
||||
|
@ -161,7 +161,6 @@ class FullLiveStreamDownloaderFactory(object):
|
|||
stream_downloader = FullLiveStreamDownloader(stream_hash, self.peer_finder, self.rate_limiter,
|
||||
self.blob_manager, self.stream_info_manager,
|
||||
prm, self.wallet, True)
|
||||
# TODO: change upload_allowed=True above to something better
|
||||
d = stream_downloader.set_stream_info()
|
||||
d.addCallback(lambda _: stream_downloader)
|
||||
return d
|
||||
|
|
|
@ -1357,7 +1357,6 @@ class Daemon(AuthJSONRPCServer):
|
|||
'stream_hash': base 58 string
|
||||
'stream_name': string
|
||||
'suggested_file_name': string
|
||||
'upload_allowed': bool
|
||||
'sd_hash': string
|
||||
"""
|
||||
|
||||
|
@ -1389,7 +1388,6 @@ class Daemon(AuthJSONRPCServer):
|
|||
'stream_hash': base 58 string
|
||||
'stream_name': string
|
||||
'suggested_file_name': string
|
||||
'upload_allowed': bool
|
||||
'sd_hash': string
|
||||
"""
|
||||
d = self._get_deferred_for_lbry_file(kwargs)
|
||||
|
@ -2583,7 +2581,6 @@ class _GetFileHelper(object):
|
|||
'stream_hash': lbry_file.stream_hash,
|
||||
'stream_name': lbry_file.stream_name,
|
||||
'suggested_file_name': lbry_file.suggested_file_name,
|
||||
'upload_allowed': lbry_file.upload_allowed,
|
||||
'sd_hash': lbry_file.sd_hash,
|
||||
'lbry_uri': lbry_file.uri,
|
||||
'txid': lbry_file.txid,
|
||||
|
|
|
@ -295,10 +295,10 @@ class ReflectorServer(Protocol):
|
|||
|
||||
if self.blob_write is None:
|
||||
log.debug('Received info for blob: %s', blob_hash[:16])
|
||||
d = self.blob_manager.get_blob(blob_hash, True, blob_size)
|
||||
d = self.blob_manager.get_blob(blob_hash, blob_size)
|
||||
d.addCallback(self.get_blob_response)
|
||||
d.addCallback(self.send_response)
|
||||
else:
|
||||
else:
|
||||
log.debug('blob is already open')
|
||||
self.receiving_blob = True
|
||||
d = self.blob_finished_d
|
||||
|
|
Loading…
Reference in a new issue