From d1b7de18070a8362d0e98c58b02c276b2db30361 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Wed, 16 Aug 2017 21:08:24 -0400 Subject: [PATCH] persist dht node id --- CHANGELOG.md | 2 +- lbrynet/conf.py | 14 ++++++++++++++ lbrynet/daemon/Daemon.py | 2 +- tests/mocks.py | 1 + 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9e814d9f..bf33870c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,7 @@ at anytime. * ### Changed - * + * Persist DHT node id * ### Added diff --git a/lbrynet/conf.py b/lbrynet/conf.py index 1c7a041da..399ed83b8 100644 --- a/lbrynet/conf.py +++ b/lbrynet/conf.py @@ -273,6 +273,7 @@ class Config(object): self._installation_id = None self._session_id = base58.b58encode(utils.generate_id()) + self._node_id = None self._fixed_defaults = fixed_defaults self._adjustable_defaults = adjustable_defaults @@ -514,6 +515,18 @@ class Config(object): install_id_file.write(self._installation_id) return self._installation_id + def get_node_id(self): + node_id_filename = os.path.join(self.ensure_data_dir(), "node_id") + if not self._node_id: + if os.path.isfile(node_id_filename): + with open(node_id_filename, "r") as node_id_file: + self._node_id = base58.b58decode(node_id_file.read()) + if not self._node_id: + self._node_id = utils.generate_id() + with open(node_id_filename, "w") as node_id_file: + node_id_file.write(base58.b58encode(self._node_id)) + return self._node_id + def get_session_id(self): return self._session_id @@ -538,5 +551,6 @@ def initialize_settings(load_conf_file=True): settings = Config(FIXED_SETTINGS, ADJUSTABLE_SETTINGS, environment=get_default_env()) settings.installation_id = settings.get_installation_id() + settings.node_id = settings.get_node_id() if load_conf_file: settings.load_conf_file_settings() diff --git a/lbrynet/daemon/Daemon.py b/lbrynet/daemon/Daemon.py index 550acce05..f1d26ff9a 100644 --- a/lbrynet/daemon/Daemon.py +++ b/lbrynet/daemon/Daemon.py @@ -207,7 +207,7 @@ class Daemon(AuthJSONRPCServer): # of the daemon, but I don't want to deal with that now self.analytics_manager = analytics_manager - self.lbryid = utils.generate_id() + self.lbryid = conf.settings.node_id self.wallet_user = None self.wallet_password = None diff --git a/tests/mocks.py b/tests/mocks.py index 5ef7d7a5c..67374ad98 100644 --- a/tests/mocks.py +++ b/tests/mocks.py @@ -280,6 +280,7 @@ def mock_conf_settings(obj, settings={}): original_settings = conf.settings conf.settings = conf.Config(conf.FIXED_SETTINGS, conf.ADJUSTABLE_SETTINGS) conf.settings.installation_id = conf.settings.get_installation_id() + conf.settings.node_id = conf.settings.get_node_id() conf.settings.update(settings) def _reset_settings():