From 26f25f8fe42a3427ed707b0612e98f45443555b6 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Wed, 6 Mar 2019 22:58:21 -0600 Subject: [PATCH] do not save expired blocks --- onionr/netcontroller.py | 3 ++- onionr/onionr.py | 46 ++++++++++++++++++++--------------------- onionr/onionrutils.py | 1 + 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/onionr/netcontroller.py b/onionr/netcontroller.py index b4053bbe..2898256c 100755 --- a/onionr/netcontroller.py +++ b/onionr/netcontroller.py @@ -147,7 +147,8 @@ HiddenServicePort 80 ''' + self.apiServerIP + ''':''' + str(self.hsPort) torVersion = subprocess.Popen([self.torBinary, '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) for line in iter(torVersion.stdout.readline, b''): if 'Tor 0.2.' in line.decode(): - logger.warn("Running 0.2.x Tor series, no support for v3 onion peers") + logger.error('Tor 0.3+ required') + sys.exit(1) break torVersion.kill() diff --git a/onionr/onionr.py b/onionr/onionr.py index 7acd2564..1d822515 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -75,6 +75,29 @@ class Onionr: logger.error('Tor is not installed') sys.exit(1) + # If data folder does not exist + if not data_exists: + if not os.path.exists(self.dataDir + 'blocks/'): + os.mkdir(self.dataDir + 'blocks/') + + # Copy default plugins into plugins folder + if not os.path.exists(plugins.get_plugins_folder()): + if os.path.exists('static-data/default-plugins/'): + names = [f for f in os.listdir("static-data/default-plugins/")] + shutil.copytree('static-data/default-plugins/', plugins.get_plugins_folder()) + + # Enable plugins + for name in names: + if not name in plugins.get_enabled_plugins(): + plugins.enable(name, self) + + for name in plugins.get_enabled_plugins(): + if not os.path.exists(plugins.get_plugin_data_folder(name)): + try: + os.mkdir(plugins.get_plugin_data_folder(name)) + except: + plugins.disable(name, onionr = self, stop_event = False) + self.communicatorInst = None self.onionrCore = core.Core() self.onionrCore.onionrInst = self @@ -90,29 +113,6 @@ class Onionr: self.debug = False # Whole application debugging - # If data folder does not exist - if not data_exists: - if not os.path.exists(self.dataDir + 'blocks/'): - os.mkdir(self.dataDir + 'blocks/') - - # Copy default plugins into plugins folder - if not os.path.exists(plugins.get_plugins_folder()): - if os.path.exists('static-data/default-plugins/'): - names = [f for f in os.listdir("static-data/default-plugins/") if not os.path.isfile(f)] - shutil.copytree('static-data/default-plugins/', plugins.get_plugins_folder()) - - # Enable plugins - for name in names: - if not name in plugins.get_enabled_plugins(): - plugins.enable(name, self) - - for name in plugins.get_enabled_plugins(): - if not os.path.exists(plugins.get_plugin_data_folder(name)): - try: - os.mkdir(plugins.get_plugin_data_folder(name)) - except: - plugins.disable(name, onionr = self, stop_event = False) - # Get configuration if type(config.get('client.webpassword')) is type(None): config.set('client.webpassword', base64.b16encode(os.urandom(32)).decode('utf-8'), savefile=True) diff --git a/onionr/onionrutils.py b/onionr/onionrutils.py index 23d265d7..a5cfdc84 100755 --- a/onionr/onionrutils.py +++ b/onionr/onionrutils.py @@ -278,6 +278,7 @@ class OnionrUtils: break if (self.getEpoch() - metadata[i]) > maxAge: logger.warn('Block is outdated: %s' % (metadata[i],)) + break elif i == 'expire': try: assert int(metadata[i]) > self.getEpoch()