progress in removing onionr core
This commit is contained in:
parent
bf8a9c4f27
commit
8163292ed9
16 changed files with 175 additions and 203 deletions
|
@ -21,8 +21,10 @@
|
|||
import sqlite3, os
|
||||
import onionrevents as events
|
||||
from onionrutils import localcommand, epoch
|
||||
from .. import dbfiles
|
||||
import dbcreator
|
||||
|
||||
def daemon_queue(core_inst):
|
||||
def daemon_queue():
|
||||
'''
|
||||
Gives commands to the communication proccess/daemon by reading an sqlite3 database
|
||||
|
||||
|
@ -30,28 +32,26 @@ def daemon_queue(core_inst):
|
|||
'''
|
||||
|
||||
retData = False
|
||||
if not os.path.exists(core_inst.queueDB):
|
||||
core_inst.dbCreate.createDaemonDB()
|
||||
if not os.path.exists(dbfiles.daemon_queue_db):
|
||||
dbcreator.createDaemonDB()
|
||||
else:
|
||||
conn = sqlite3.connect(core_inst.queueDB, timeout=30)
|
||||
conn = sqlite3.connect(dbfiles.daemon_queue_db, timeout=30)
|
||||
c = conn.cursor()
|
||||
try:
|
||||
for row in c.execute('SELECT command, data, date, min(ID), responseID FROM commands group by id'):
|
||||
retData = row
|
||||
break
|
||||
except sqlite3.OperationalError:
|
||||
core_inst.dbCreate.createDaemonDB()
|
||||
dbcreator.createDaemonDB()
|
||||
else:
|
||||
if retData != False:
|
||||
c.execute('DELETE FROM commands WHERE id=?;', (retData[3],))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
events.event('queue_pop', data = {'data': retData}, onionr = core_inst.onionrInst)
|
||||
|
||||
return retData
|
||||
|
||||
def daemon_queue_add(core_inst, command, data='', responseID=''):
|
||||
def daemon_queue_add(command, data='', responseID=''):
|
||||
'''
|
||||
Add a command to the daemon queue, used by the communication daemon (communicator.py)
|
||||
'''
|
||||
|
@ -59,7 +59,7 @@ def daemon_queue_add(core_inst, command, data='', responseID=''):
|
|||
retData = True
|
||||
|
||||
date = epoch.get_epoch()
|
||||
conn = sqlite3.connect(core_inst.queueDB, timeout=30)
|
||||
conn = sqlite3.connect(dbfiles.daemon_queue_db, timeout=30)
|
||||
c = conn.cursor()
|
||||
t = (command, data, date, responseID)
|
||||
try:
|
||||
|
@ -67,24 +67,23 @@ def daemon_queue_add(core_inst, command, data='', responseID=''):
|
|||
conn.commit()
|
||||
except sqlite3.OperationalError:
|
||||
retData = False
|
||||
core_inst.daemonQueue()
|
||||
events.event('queue_push', data = {'command': command, 'data': data}, onionr = core_inst.onionrInst)
|
||||
daemon_queue()
|
||||
conn.close()
|
||||
return retData
|
||||
|
||||
def daemon_queue_get_response(core_inst, responseID=''):
|
||||
def daemon_queue_get_response(responseID=''):
|
||||
'''
|
||||
Get a response sent by communicator to the API, by requesting to the API
|
||||
'''
|
||||
assert len(responseID) > 0
|
||||
resp = localcommand.local_command(core_inst, 'queueResponse/' + responseID)
|
||||
if len(responseID) > 0: raise ValueError('ResponseID should not be empty')
|
||||
resp = localcommand.local_command(dbfiles.daemon_queue_db, 'queueResponse/' + responseID)
|
||||
return resp
|
||||
|
||||
def clear_daemon_queue(core_inst):
|
||||
def clear_daemon_queue():
|
||||
'''
|
||||
Clear the daemon queue (somewhat dangerous)
|
||||
'''
|
||||
conn = sqlite3.connect(core_inst.queueDB, timeout=30)
|
||||
conn = sqlite3.connect(dbfiles.daemon_queue_db, timeout=30)
|
||||
c = conn.cursor()
|
||||
|
||||
try:
|
||||
|
@ -93,5 +92,4 @@ def clear_daemon_queue(core_inst):
|
|||
except:
|
||||
pass
|
||||
|
||||
conn.close()
|
||||
events.event('queue_clear', onionr = core_inst.onionrInst)
|
||||
conn.close()
|
|
@ -2,4 +2,9 @@ from utils import identifyhome
|
|||
home = identifyhome.identify_home()
|
||||
if not home.endswith('/'): home += '/'
|
||||
|
||||
block_meta_db = '%sblock-metadata.db'
|
||||
block_meta_db = '%sblock-metadata.db' % (home,)
|
||||
block_data_db = '%sblocks/block-data.db' % (home,)
|
||||
daemon_queue_db = '%sdaemon-queue.db' % (home,)
|
||||
address_info_db = '%saddress.db' % (home,)
|
||||
user_id_info_db = '%susers.db' % (home,)
|
||||
forward_keys_db = '%sforward-keys.db' % (home,)
|
|
@ -20,7 +20,7 @@
|
|||
import sqlite3
|
||||
import onionrevents as events
|
||||
from onionrutils import stringvalidators
|
||||
|
||||
from . import listkeys
|
||||
def add_peer(core_inst, peerID, name=''):
|
||||
'''
|
||||
Adds a public key to the key database (misleading function name)
|
||||
|
|
|
@ -20,14 +20,15 @@
|
|||
import sqlite3
|
||||
import logger
|
||||
from onionrutils import epoch
|
||||
def list_peers(core_inst, randomOrder=True, getPow=False, trust=0):
|
||||
from .. import dbfiles
|
||||
def list_peers(randomOrder=True, getPow=False, trust=0):
|
||||
'''
|
||||
Return a list of public keys (misleading function name)
|
||||
|
||||
randomOrder determines if the list should be in a random order
|
||||
trust sets the minimum trust to list
|
||||
'''
|
||||
conn = sqlite3.connect(core_inst.peerDB, timeout=30)
|
||||
conn = sqlite3.connect(dbfiles.user_id_info_db, timeout=30)
|
||||
c = conn.cursor()
|
||||
|
||||
payload = ''
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue