moved BLOB_SIZE in conf to MAX_BLOB_SIZE constant in blob.blob_file

This commit is contained in:
Kay Kurokawa 2017-09-25 12:12:40 -04:00
parent 51d4668763
commit 9470b318b0
5 changed files with 8 additions and 12 deletions

View file

@ -3,15 +3,14 @@ import os
from twisted.internet import defer, threads from twisted.internet import defer, threads
from twisted.web.client import FileBodyProducer from twisted.web.client import FileBodyProducer
from twisted.python.failure import Failure from twisted.python.failure import Failure
from lbrynet import conf
from lbrynet.core.Error import DownloadCanceledError, InvalidDataError, InvalidBlobHashError from lbrynet.core.Error import DownloadCanceledError, InvalidDataError, InvalidBlobHashError
from lbrynet.core.utils import is_valid_blobhash from lbrynet.core.utils import is_valid_blobhash
from lbrynet.blob.writer import HashBlobWriter from lbrynet.blob.writer import HashBlobWriter
from lbrynet.blob.reader import HashBlobReader from lbrynet.blob.reader import HashBlobReader
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
MAX_BLOB_SIZE = 2 * 2 ** 20
class BlobFile(object): class BlobFile(object):
""" """
@ -124,7 +123,7 @@ class BlobFile(object):
def set_length(self, length): def set_length(self, length):
if self.length is not None and length == self.length: if self.length is not None and length == self.length:
return True return True
if self.length is None and 0 <= length <= conf.settings['BLOB_SIZE']: if self.length is None and 0 <= length <= MAX_BLOB_SIZE:
self.length = length self.length = length
return True return True
log.warning("Got an invalid length. Previous length: %s, Invalid length: %s", log.warning("Got an invalid length. Previous length: %s, Invalid length: %s",

View file

@ -206,7 +206,6 @@ FIXED_SETTINGS = {
'API_ADDRESS': 'lbryapi', 'API_ADDRESS': 'lbryapi',
'APP_NAME': APP_NAME, 'APP_NAME': APP_NAME,
'BLOBFILES_DIR': 'blobfiles', 'BLOBFILES_DIR': 'blobfiles',
'BLOB_SIZE': 2 * MB,
'CRYPTSD_FILE_EXTENSION': '.cryptsd', 'CRYPTSD_FILE_EXTENSION': '.cryptsd',
'CURRENCIES': { 'CURRENCIES': {
'BTC': {'type': 'crypto'}, 'BTC': {'type': 'crypto'},

View file

@ -1,5 +1,4 @@
from lbrynet import conf from lbrynet.blob.blob_file import MAX_BLOB_SIZE
class ClientRequest(object): class ClientRequest(object):
def __init__(self, request_dict, response_identifier=None): def __init__(self, request_dict, response_identifier=None):
@ -17,7 +16,7 @@ class ClientBlobRequest(ClientPaidRequest):
def __init__(self, request_dict, response_identifier, write_func, finished_deferred, def __init__(self, request_dict, response_identifier, write_func, finished_deferred,
cancel_func, blob): cancel_func, blob):
if blob.length is None: if blob.length is None:
max_pay_units = conf.settings['BLOB_SIZE'] max_pay_units = MAX_BLOB_SIZE
else: else:
max_pay_units = blob.length max_pay_units = blob.length
ClientPaidRequest.__init__(self, request_dict, response_identifier, max_pay_units) ClientPaidRequest.__init__(self, request_dict, response_identifier, max_pay_units)

View file

@ -5,9 +5,8 @@ from cryptography.hazmat.primitives.ciphers import Cipher, modes
from cryptography.hazmat.primitives.ciphers.algorithms import AES from cryptography.hazmat.primitives.ciphers.algorithms import AES
from cryptography.hazmat.primitives.padding import PKCS7 from cryptography.hazmat.primitives.padding import PKCS7
from cryptography.hazmat.backends import default_backend from cryptography.hazmat.backends import default_backend
from lbrynet import conf
from lbrynet.core.BlobInfo import BlobInfo from lbrynet.core.BlobInfo import BlobInfo
from lbrynet.blob.blob_file import MAX_BLOB_SIZE
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
backend = default_backend() backend = default_backend()
@ -114,7 +113,7 @@ class CryptStreamBlobMaker(object):
max bytes are written. num_bytes_to_write is the number max bytes are written. num_bytes_to_write is the number
of bytes that will be written from data in this call of bytes that will be written from data in this call
""" """
max_bytes_to_write = conf.settings['BLOB_SIZE'] - self.length - 1 max_bytes_to_write = MAX_BLOB_SIZE - self.length - 1
done = False done = False
if max_bytes_to_write <= len(data): if max_bytes_to_write <= len(data):
num_bytes_to_write = max_bytes_to_write num_bytes_to_write = max_bytes_to_write

View file

@ -1,7 +1,7 @@
from twisted.trial import unittest from twisted.trial import unittest
from twisted.internet import defer from twisted.internet import defer
from lbrynet.cryptstream import CryptBlob from lbrynet.cryptstream import CryptBlob
from lbrynet import conf from lbrynet.blob.blob_file import MAX_BLOB_SIZE
from lbrynet.tests.mocks import mock_conf_settings from lbrynet.tests.mocks import mock_conf_settings
@ -57,7 +57,7 @@ class TestCryptBlob(unittest.TestCase):
expected_encrypted_blob_size = ((size_of_data / AES.block_size) + 1) * AES.block_size expected_encrypted_blob_size = ((size_of_data / AES.block_size) + 1) * AES.block_size
self.assertEqual(expected_encrypted_blob_size, len(blob.data)) self.assertEqual(expected_encrypted_blob_size, len(blob.data))
if size_of_data < conf.settings['BLOB_SIZE']-1: if size_of_data < MAX_BLOB_SIZE-1:
self.assertFalse(done) self.assertFalse(done)
else: else:
self.assertTrue(done) self.assertTrue(done)