From 88fe605762d270d2b6f0f551cdebfc4bf9fd510f Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Mon, 6 Jan 2020 18:25:51 -0600 Subject: [PATCH] finish up removing daemon queue, migrate shutdown to event system --- src/communicator/__init__.py | 11 --------- .../downloadblocks/__init__.py | 1 - src/coredb/__init__.py | 2 +- src/httpapi/apiutils/shutdown.py | 23 ++++++++++--------- src/onionrcommands/daemonlaunch.py | 7 ++++-- src/onionrplugins/onionrpluginapi.py | 1 - src/onionrsetup/dbcreator.py | 16 +++---------- 7 files changed, 21 insertions(+), 40 deletions(-) diff --git a/src/communicator/__init__.py b/src/communicator/__init__.py index 3e217e1e..e729a541 100755 --- a/src/communicator/__init__.py +++ b/src/communicator/__init__.py @@ -21,7 +21,6 @@ from communicatorutils import lookupblocks from communicatorutils import lookupadders from communicatorutils import connectnewpeers from communicatorutils import uploadblocks -from communicatorutils import daemonqueuehandler from communicatorutils import announcenode, deniableinserts from communicatorutils import cooldownpeer from communicatorutils import housekeeping @@ -32,7 +31,6 @@ from etc import humanreadabletime import onionrservices import filepaths from onionrblocks import storagecounter -from coredb import daemonqueue from coredb import dbfiles from netcontroller import NetController from . import bootstrappeers @@ -120,10 +118,6 @@ class OnionrCommunicatorDaemon: # to avoid downloading full lists all the time self.dbTimestamps = {} - # Clear the daemon queue for any dead messages - if os.path.exists(dbfiles.daemon_queue_db): - daemonqueue.clear_daemon_queue() - # Loads in and starts the enabled plugins plugins.reload() @@ -183,11 +177,6 @@ class OnionrCommunicatorDaemon: self, uploadblocks.upload_blocks_from_communicator, 5, my_args=[self], requires_peer=True, max_threads=1) - # Timer to process the daemon command queue - OnionrCommunicatorTimers( - self, daemonqueuehandler.handle_daemon_commands, - 6, my_args=[self], max_threads=3) - # Setup direct connections if config.get('general.socket_servers', False): self.services = onionrservices.OnionrServices() diff --git a/src/communicatorutils/downloadblocks/__init__.py b/src/communicatorutils/downloadblocks/__init__.py index ef8a76e9..7324c846 100755 --- a/src/communicatorutils/downloadblocks/__init__.py +++ b/src/communicatorutils/downloadblocks/__init__.py @@ -18,7 +18,6 @@ from communicator import onlinepeers from onionrutils import blockmetadata from onionrutils import validatemetadata from coredb import blockmetadb -from coredb import daemonqueue from onionrutils.localcommand import local_command import onionrcrypto import onionrstorage diff --git a/src/coredb/__init__.py b/src/coredb/__init__.py index 39c909ba..d60f2150 100644 --- a/src/coredb/__init__.py +++ b/src/coredb/__init__.py @@ -1 +1 @@ -from . import keydb, blockmetadb, daemonqueue \ No newline at end of file +from . import keydb, blockmetadb \ No newline at end of file diff --git a/src/httpapi/apiutils/shutdown.py b/src/httpapi/apiutils/shutdown.py index a42c2068..4a6db909 100644 --- a/src/httpapi/apiutils/shutdown.py +++ b/src/httpapi/apiutils/shutdown.py @@ -1,9 +1,14 @@ -''' +""" Onionr - Private P2P Communication Shutdown the node either hard or cleanly -''' -''' +""" +from flask import Blueprint, Response +from flask import g +from onionrblocks import onionrblockapi +import onionrexceptions +from onionrutils import stringvalidators +""" This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or @@ -16,12 +21,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . -''' -from flask import Blueprint, Response -from onionrblocks import onionrblockapi -import onionrexceptions -from onionrutils import stringvalidators -from coredb import daemonqueue +""" + shutdown_bp = Blueprint('shutdown', __name__) def shutdown(client_api_inst): @@ -35,5 +36,5 @@ def shutdown(client_api_inst): @shutdown_bp.route('/shutdownclean') def shutdown_clean(): # good for calling from other clients - daemonqueue.daemon_queue_add('shutdown') - return Response("bye") \ No newline at end of file + g.too_many.get_by_string("OnionrCommunicatorDaemon").shutdown = True + return Response("bye") diff --git a/src/onionrcommands/daemonlaunch.py b/src/onionrcommands/daemonlaunch.py index f5f44aef..5b286809 100755 --- a/src/onionrcommands/daemonlaunch.py +++ b/src/onionrcommands/daemonlaunch.py @@ -8,6 +8,7 @@ import platform import sqlite3 from threading import Thread from gevent import time +from gevent import spawn import toomanyobjs @@ -19,7 +20,6 @@ from onionrplugins import onionrevents as events from netcontroller import NetController from onionrutils import localcommand import filepaths -from coredb import daemonqueue from etc import onionrvalues, cleanup from onionrcrypto import getourkeypair from utils import hastor, logoheader @@ -166,7 +166,10 @@ def kill_daemon(): events.event('daemon_stop') net = NetController(config.get('client.port', 59496)) try: - daemonqueue.daemon_queue_add('shutdown') + spawn( + localcommand.local_command, + '/shutdownclean' + ).get(timeout=5) except sqlite3.OperationalError: pass diff --git a/src/onionrplugins/onionrpluginapi.py b/src/onionrplugins/onionrpluginapi.py index 0cce713c..818152d2 100755 --- a/src/onionrplugins/onionrpluginapi.py +++ b/src/onionrplugins/onionrpluginapi.py @@ -20,7 +20,6 @@ import onionrplugins, logger from onionrutils import localcommand -from coredb import daemonqueue class PluginAPI: def __init__(self, pluginapi): diff --git a/src/onionrsetup/dbcreator.py b/src/onionrsetup/dbcreator.py index 50cc4817..ed5ffdd6 100755 --- a/src/onionrsetup/dbcreator.py +++ b/src/onionrsetup/dbcreator.py @@ -150,18 +150,6 @@ def createForwardKeyDB(): conn.close() return -def createDaemonDB(): - ''' - Create the daemon queue database - ''' - if os.path.exists(dbfiles.daemon_queue_db): - raise FileExistsError("Daemon queue db already exists") - conn = sqlite3.connect(dbfiles.daemon_queue_db, timeout=10) - c = conn.cursor() - # Create table - c.execute('''CREATE TABLE commands (id integer primary key autoincrement, command text, data text, date text, responseID text)''') - conn.commit() - conn.close() def create_blacklist_db(): if os.path.exists(dbfiles.blacklist_db): @@ -180,4 +168,6 @@ def create_blacklist_db(): conn.close() -create_funcs = [createAddressDB, createPeerDB, createBlockDB, createBlockDataDB, createForwardKeyDB, createDaemonDB, create_blacklist_db] \ No newline at end of file +create_funcs = [createAddressDB, createPeerDB, + createBlockDB, createBlockDataDB, + createForwardKeyDB, create_blacklist_db] \ No newline at end of file