From 9d92fba02ea87518582c050a82a50d0db0ceb946 Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Thu, 3 Aug 2017 23:13:59 -0400 Subject: [PATCH] add ability to control re-reflects through config --- lbrynet/conf.py | 5 +++++ lbrynet/file_manager/EncryptedFileManager.py | 18 ++++++------------ .../test_EncryptedFileManager.py | 4 ++++ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lbrynet/conf.py b/lbrynet/conf.py index 2e168d805..1c7a041da 100644 --- a/lbrynet/conf.py +++ b/lbrynet/conf.py @@ -250,7 +250,12 @@ ADJUSTABLE_SETTINGS = { 'peer_port': (int, 3333), 'pointtrader_server': (str, 'http://127.0.0.1:2424'), 'reflector_port': (int, 5566), + # if reflect_uploads is True, reflect files on publish 'reflect_uploads': (bool, True), + # if auto_re_reflect is True, attempt to re-reflect files on startup and + # at every auto_re_reflect_interval seconds, useful if initial reflect is unreliable + 'auto_re_reflect': (bool, True), + 'auto_re_reflect_interval': (int, 3600), 'reflector_servers': (list, [('reflector.lbry.io', 5566)], server_port), 'run_reflector_server': (bool, False), 'sd_download_timeout': (int, 3), diff --git a/lbrynet/file_manager/EncryptedFileManager.py b/lbrynet/file_manager/EncryptedFileManager.py index 914cfd242..b623cf88e 100644 --- a/lbrynet/file_manager/EncryptedFileManager.py +++ b/lbrynet/file_manager/EncryptedFileManager.py @@ -17,22 +17,13 @@ from lbrynet.lbry_file.StreamDescriptor import EncryptedFileStreamType from lbrynet.cryptstream.client.CryptStreamDownloader import AlreadyStoppedError from lbrynet.cryptstream.client.CryptStreamDownloader import CurrentlyStoppingError from lbrynet.core.sqlite_helpers import rerun_if_locked +from lbrynet.core.utils import safe_start_looping_call, safe_stop_looping_call from lbrynet import conf log = logging.getLogger(__name__) -def safe_start_looping_call(looping_call, seconds=3600): - if not looping_call.running: - looping_call.start(seconds) - - -def safe_stop_looping_call(looping_call): - if looping_call.running: - looping_call.stop() - - class EncryptedFileManager(object): """Keeps track of currently opened LBRY Files, their options, and their LBRY File specific metadata. @@ -40,6 +31,9 @@ class EncryptedFileManager(object): """ def __init__(self, session, stream_info_manager, sd_identifier, download_directory=None): + + self.auto_re_reflect = conf.settings['auto_re_reflect'] + self.auto_re_reflect_interval = conf.settings['auto_re_reflect_interval'] self.session = session self.stream_info_manager = stream_info_manager # TODO: why is sd_identifier part of the file manager? @@ -58,8 +52,8 @@ class EncryptedFileManager(object): yield self._open_db() yield self._add_to_sd_identifier() yield self._start_lbry_files() - if conf.settings['reflect_uploads']: - safe_start_looping_call(self.lbry_file_reflector) + if self.auto_re_reflect is True: + safe_start_looping_call(self.lbry_file_reflector, self.auto_re_reflect_interval) def get_lbry_file_status(self, lbry_file): return self._get_lbry_file_status(lbry_file.rowid) diff --git a/tests/unit/lbryfilemanager/test_EncryptedFileManager.py b/tests/unit/lbryfilemanager/test_EncryptedFileManager.py index 18a4d696d..293c23d80 100644 --- a/tests/unit/lbryfilemanager/test_EncryptedFileManager.py +++ b/tests/unit/lbryfilemanager/test_EncryptedFileManager.py @@ -1,11 +1,15 @@ from twisted.internet import defer from twisted.trial import unittest +from lbrynet import conf from lbrynet.file_manager.EncryptedFileDownloader import ManagedEncryptedFileDownloader from lbrynet.file_manager.EncryptedFileManager import EncryptedFileManager from tests.util import random_lbry_hash class TestEncryptedFileManager(unittest.TestCase): + def setUp(self): + conf.initialize_settings() + @defer.inlineCallbacks def test_database_operations(self): # test database read/write functions in EncrypteFileManager