finish up removing daemon queue, migrate shutdown to event system

master
Kevin Froman 2020-01-06 18:25:51 -06:00
parent a801960179
commit 88fe605762
7 changed files with 21 additions and 40 deletions

View File

@ -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()

View File

@ -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

View File

@ -1 +1 @@
from . import keydb, blockmetadb, daemonqueue
from . import keydb, blockmetadb

View File

@ -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 <https://www.gnu.org/licenses/>.
'''
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')
g.too_many.get_by_string("OnionrCommunicatorDaemon").shutdown = True
return Response("bye")

View File

@ -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

View File

@ -20,7 +20,6 @@
import onionrplugins, logger
from onionrutils import localcommand
from coredb import daemonqueue
class PluginAPI:
def __init__(self, pluginapi):

View File

@ -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]
create_funcs = [createAddressDB, createPeerDB,
createBlockDB, createBlockDataDB,
createForwardKeyDB, create_blacklist_db]