forked from LBRYCommunity/lbry-sdk
allow more download attempts after having timed out
-also lower the name cache time
This commit is contained in:
parent
4dacc52ecb
commit
a23f2ca956
3 changed files with 29 additions and 11 deletions
|
@ -61,7 +61,7 @@ DEFAULT_MAX_SEARCH_RESULTS = 25
|
||||||
DEFAULT_MAX_KEY_FEE = {'USD': {'amount': 25.0, 'address': ''}}
|
DEFAULT_MAX_KEY_FEE = {'USD': {'amount': 25.0, 'address': ''}}
|
||||||
DEFAULT_SEARCH_TIMEOUT = 3.0
|
DEFAULT_SEARCH_TIMEOUT = 3.0
|
||||||
DEFAULT_SD_DOWNLOAD_TIMEOUT = 3
|
DEFAULT_SD_DOWNLOAD_TIMEOUT = 3
|
||||||
DEFAULT_CACHE_TIME = 3600
|
DEFAULT_CACHE_TIME = 150
|
||||||
DEFAULT_UI_BRANCH = "master"
|
DEFAULT_UI_BRANCH = "master"
|
||||||
|
|
||||||
SOURCE_TYPES = ['lbry_sd_hash', 'url', 'btih']
|
SOURCE_TYPES = ['lbry_sd_hash', 'url', 'btih']
|
||||||
|
|
|
@ -264,6 +264,9 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
log.info("First run after update")
|
log.info("First run after update")
|
||||||
log.info("lbrynet %s --> %s" % (self.session_settings['last_version']['lbrynet'], self.default_settings['last_version']['lbrynet']))
|
log.info("lbrynet %s --> %s" % (self.session_settings['last_version']['lbrynet'], self.default_settings['last_version']['lbrynet']))
|
||||||
log.info("lbryum %s --> %s" % (self.session_settings['last_version']['lbryum'], self.default_settings['last_version']['lbryum']))
|
log.info("lbryum %s --> %s" % (self.session_settings['last_version']['lbryum'], self.default_settings['last_version']['lbryum']))
|
||||||
|
if utils.version_is_greater_than("0.4.5", self.session_settings['last_version']['lbrynet']):
|
||||||
|
log.info("Lowering name cache time")
|
||||||
|
self.session_settings['cache_time'] = DEFAULT_CACHE_TIME
|
||||||
|
|
||||||
f = open(self.daemon_conf, "w")
|
f = open(self.daemon_conf, "w")
|
||||||
f.write(json.dumps(self.session_settings))
|
f.write(json.dumps(self.session_settings))
|
||||||
|
@ -920,6 +923,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
self.session_settings['cache_time'] = int(settings['cache_time'])
|
self.session_settings['cache_time'] = int(settings['cache_time'])
|
||||||
else:
|
else:
|
||||||
return defer.fail()
|
return defer.fail()
|
||||||
|
|
||||||
self.run_on_startup = self.session_settings['run_on_startup']
|
self.run_on_startup = self.session_settings['run_on_startup']
|
||||||
self.data_rate = self.session_settings['data_rate']
|
self.data_rate = self.session_settings['data_rate']
|
||||||
self.max_key_fee = self.session_settings['max_key_fee']
|
self.max_key_fee = self.session_settings['max_key_fee']
|
||||||
|
@ -1801,7 +1805,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
file_name=params.file_name,
|
file_name=params.file_name,
|
||||||
wait_for_write=params.wait_for_write)
|
wait_for_write=params.wait_for_write)
|
||||||
# TODO: downloading can timeout. Not sure what to do when that happens
|
# TODO: downloading can timeout. Not sure what to do when that happens
|
||||||
d.addCallback(get_output_callback(params))
|
d.addCallbacks(get_output_callback(params), lambda err: str(err))
|
||||||
d.addCallback(lambda message: self._render_response(message, OK_CODE))
|
d.addCallback(lambda message: self._render_response(message, OK_CODE))
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
@ -2588,7 +2592,6 @@ def get_darwin_lbrycrdd_path():
|
||||||
return default
|
return default
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class _DownloadNameHelper(object):
|
class _DownloadNameHelper(object):
|
||||||
def __init__(self, daemon, name, timeout=DEFAULT_TIMEOUT, download_directory=None,
|
def __init__(self, daemon, name, timeout=DEFAULT_TIMEOUT, download_directory=None,
|
||||||
file_name=None, wait_for_write=True):
|
file_name=None, wait_for_write=True):
|
||||||
|
@ -2629,15 +2632,26 @@ class _DownloadNameHelper(object):
|
||||||
d = self.daemon.add_stream(
|
d = self.daemon.add_stream(
|
||||||
self.name, self.timeout, self.download_directory, self.file_name, stream_info)
|
self.name, self.timeout, self.download_directory, self.file_name, stream_info)
|
||||||
|
|
||||||
def _raiseErrorOnTimeout(args):
|
def _handle_timeout(args):
|
||||||
was_successful, _, _ = args
|
was_successful, _, _ = args
|
||||||
if not was_successful:
|
if not was_successful:
|
||||||
raise Exception('What am I supposed to do with a timed-out downloader?')
|
log.warning("lbry://%s timed out, removing from streams", self.name)
|
||||||
d.addCallback(_raiseErrorOnTimeout)
|
del self.daemon.streams[self.name]
|
||||||
|
|
||||||
|
d.addCallback(_handle_timeout)
|
||||||
|
|
||||||
if self.wait_for_write:
|
if self.wait_for_write:
|
||||||
d.addCallback(lambda _: self._wait_for_write())
|
d.addCallback(lambda _: self._wait_for_write())
|
||||||
d.addCallback(lambda _: self.daemon.streams[self.name].downloader)
|
|
||||||
|
def _get_stream_for_return():
|
||||||
|
stream = self.daemon.streams.get(self.name, None)
|
||||||
|
if stream:
|
||||||
|
return stream.downloader
|
||||||
|
else:
|
||||||
|
self._remove_from_wait("Timed out")
|
||||||
|
return defer.fail(Exception("Timed out"))
|
||||||
|
|
||||||
|
d.addCallback(lambda _: _get_stream_for_return())
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def _wait_for_write(self):
|
def _wait_for_write(self):
|
||||||
|
@ -2647,7 +2661,11 @@ class _DownloadNameHelper(object):
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def has_downloader_wrote(self):
|
def has_downloader_wrote(self):
|
||||||
downloader = self.daemon.streams[self.name].downloader
|
stream = self.daemon.streams.get(self.name, False)
|
||||||
|
if stream:
|
||||||
|
downloader = stream.downloader
|
||||||
|
else:
|
||||||
|
downloader = False
|
||||||
if not downloader:
|
if not downloader:
|
||||||
return False
|
return False
|
||||||
return self.get_written_bytes(downloader.file_name)
|
return self.get_written_bytes(downloader.file_name)
|
||||||
|
@ -2682,7 +2700,8 @@ class _DownloadNameHelper(object):
|
||||||
return f
|
return f
|
||||||
|
|
||||||
def _remove_from_wait(self, r):
|
def _remove_from_wait(self, r):
|
||||||
del self.daemon.waiting_on[self.name]
|
if self.name in self.daemon.waiting_on:
|
||||||
|
del self.daemon.waiting_on[self.name]
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -95,8 +95,7 @@ class GetStream(object):
|
||||||
|
|
||||||
def start(self, stream_info, name):
|
def start(self, stream_info, name):
|
||||||
def _cause_timeout(err):
|
def _cause_timeout(err):
|
||||||
log.error(err)
|
log.info('Cancelling download')
|
||||||
log.debug('Forcing a timeout')
|
|
||||||
self.timeout_counter = self.timeout * 2
|
self.timeout_counter = self.timeout * 2
|
||||||
|
|
||||||
def _set_status(x, status):
|
def _set_status(x, status):
|
||||||
|
|
Loading…
Reference in a new issue