From 8a133f9749e4907c1e7a02bc88a07535f6f9166b Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Tue, 9 Jan 2018 16:55:39 -0500 Subject: [PATCH 1/2] use lists of hostname:port strings in conf file --- CHANGELOG.md | 1 + lbrynet/conf.py | 24 ++++++++++++++++++++---- lbrynet/daemon/Daemon.py | 4 ++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea22fb466..ae6ade421 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,7 @@ at anytime. * Added `wallet_unlock`, a command available during startup to unlock an encrypted wallet * Added support for wallet encryption via new commands `wallet_decrypt` and `wallet_encrypt` * Added `blob_availability` and `stream_availability` commands for debugging download issues + * Changed config file format of `known_dht_nodes`, `lbryum_servers`, and `reflector_servers` to lists of `hostname:port` strings ### Removed * Removed claim related filter arguments `name`, `claim_id`, and `outpoint` from `file_list`, `file_delete`, `file_set_status`, and `file_reflect` diff --git a/lbrynet/conf.py b/lbrynet/conf.py index eee8cf0b3..1c26b023d 100644 --- a/lbrynet/conf.py +++ b/lbrynet/conf.py @@ -59,6 +59,7 @@ settings_encoders = { # set by CLI when the user specifies an alternate config file path conf_file = None + def _win_path_to_bytes(path): """ Encode Windows paths to string. appdirs.user_data_dir() @@ -162,6 +163,10 @@ def server_port(server_and_port): return server, int(port) +def server_list(servers): + return [server_port(server) for server in servers] + + class Env(envparse.Env): """An Env parser that automatically namespaces the variables with LBRY""" @@ -188,6 +193,7 @@ class Env(envparse.Env): If you do this, the tuple/list must be of the form (cast, default) or (cast, default, subcast) """ + if isinstance(value, (tuple, list)): new_value = {'cast': value[0], 'default': value[1]} if len(value) == 3: @@ -257,7 +263,7 @@ ADJUSTABLE_SETTINGS = { 'download_timeout': (int, 180), 'is_generous_host': (bool, True), 'announce_head_blobs_only': (bool, True), - 'known_dht_nodes': (list, DEFAULT_DHT_NODES, server_port), + 'known_dht_nodes': (list, DEFAULT_DHT_NODES, server_list), 'lbryum_wallet_dir': (str, default_lbryum_dir), 'max_connections_per_stream': (int, 5), 'seek_head_blob_first': (bool, True), @@ -277,7 +283,7 @@ ADJUSTABLE_SETTINGS = { # 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, [('reflector2.lbry.io', 5566)], server_port), + 'reflector_servers': (list, [('reflector2.lbry.io', 5566)], server_list), 'run_reflector_server': (bool, False), 'sd_download_timeout': (int, 3), 'share_usage_data': (bool, True), # whether to share usage stats and diagnostic info with LBRY @@ -287,7 +293,7 @@ ADJUSTABLE_SETTINGS = { 'use_keyring': (bool, False), 'wallet': (str, LBRYUM_WALLET), 'blockchain_name': (str, 'lbrycrd_main'), - 'lbryum_servers': (list, ['lbryum8.lbry.io:50001', 'lbryum9.lbry.io:50001']) + 'lbryum_servers': (list, [('lbryum8.lbry.io', 50001), ('lbryum9.lbry.io', 50001)], server_list) } @@ -491,6 +497,16 @@ class Config(object): with open(path, 'w') as settings_file: settings_file.write(encoder(self._data[TYPE_PERSISTED])) + @staticmethod + def _convert_conf_file_lists(decoded): + converted = {} + for k, v in decoded.iteritems(): + if k in ADJUSTABLE_SETTINGS and len(ADJUSTABLE_SETTINGS[k]) == 3: + converted[k] = ADJUSTABLE_SETTINGS[k][2](v) + else: + converted[k] = v + return converted + def load_conf_file_settings(self): if conf_file: path = conf_file @@ -506,7 +522,7 @@ class Config(object): decoded = self._fix_old_conf_file_settings(decoder(data)) log.info('Loaded settings file: %s', path) self._validate_settings(decoded) - self._data[TYPE_PERSISTED].update(decoded) + self._data[TYPE_PERSISTED].update(self._convert_conf_file_lists(decoded)) except (IOError, OSError) as err: log.info('%s: Failed to update settings from %s', err, path) diff --git a/lbrynet/daemon/Daemon.py b/lbrynet/daemon/Daemon.py index c9c4528fe..ef3fa834d 100644 --- a/lbrynet/daemon/Daemon.py +++ b/lbrynet/daemon/Daemon.py @@ -546,8 +546,8 @@ class Daemon(AuthJSONRPCServer): log.info("Using lbryum wallet") - lbryum_servers = {address.split(":")[0]: {'t': str(address.split(":")[1])} - for address in conf.settings['lbryum_servers']} + lbryum_servers = {address: {'t': str(port)} + for address, port in conf.settings['lbryum_servers']} config = { 'auto_connect': True, From b6afc437e6b9a16756446d07e233c8ad04a3f4e7 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Fri, 12 Jan 2018 09:21:24 -0500 Subject: [PATCH 2/2] combine auto_re_reflect and reflect_uploads settings --- CHANGELOG.md | 1 + lbrynet/conf.py | 6 ++---- lbrynet/file_manager/EncryptedFileManager.py | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae6ade421..7eaec81c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -71,6 +71,7 @@ at anytime. * Removed unused files * Removed old and unused UI related code * Removed claim information from lbry file internals + * Removed `auto_re_reflect` setting from the conf file, use the `reflect_uploads` setting instead ## [0.18.0] - 2017-11-08 diff --git a/lbrynet/conf.py b/lbrynet/conf.py index 1c26b023d..85d86d8d1 100644 --- a/lbrynet/conf.py +++ b/lbrynet/conf.py @@ -277,11 +277,9 @@ 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 + # if reflect_uploads is True, send files to reflector (after publishing as well as a + # periodic check in the event the initial upload failed or was disconnected part way through '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, [('reflector2.lbry.io', 5566)], server_list), 'run_reflector_server': (bool, False), diff --git a/lbrynet/file_manager/EncryptedFileManager.py b/lbrynet/file_manager/EncryptedFileManager.py index 9d022c1d7..a1ffc0da3 100644 --- a/lbrynet/file_manager/EncryptedFileManager.py +++ b/lbrynet/file_manager/EncryptedFileManager.py @@ -32,7 +32,7 @@ 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 = conf.settings['reflect_uploads'] self.auto_re_reflect_interval = conf.settings['auto_re_reflect_interval'] self.session = session self.stream_info_manager = stream_info_manager