progress in removing core

master
Kevin Froman 2019-07-20 19:29:08 -05:00
parent f843ccc3b2
commit 50a8e8958a
9 changed files with 26 additions and 31 deletions

View File

@ -23,6 +23,7 @@ from gevent.pywsgi import WSGIServer
from onionrutils import epoch from onionrutils import epoch
import httpapi, filepaths, logger import httpapi, filepaths, logger
from . import register_private_blueprints from . import register_private_blueprints
import serializeddata
class PrivateAPI: class PrivateAPI:
''' '''
Client HTTP api Client HTTP api
@ -40,6 +41,7 @@ class PrivateAPI:
config = onionrInst.config config = onionrInst.config
self.config = config self.config = config
self.debug = debug self.debug = debug
self.serializer = serializeddata.SerializedData(onionrInst)
self.startTime = epoch.get_epoch() self.startTime = epoch.get_epoch()
app = flask.Flask(__name__) app = flask.Flask(__name__)
bindPort = int(config.get('client.client.port', 59496)) bindPort = int(config.get('client.client.port', 59496))

View File

@ -19,6 +19,8 @@
''' '''
from flask import Response, Blueprint, request, send_from_directory, abort from flask import Response, Blueprint, request, send_from_directory, abort
from httpapi import apiutils from httpapi import apiutils
import onionrcrypto
pub_key = onionrcrypto.pub_key
class PrivateEndpoints: class PrivateEndpoints:
def __init__(self, client_api): def __init__(self, client_api):
private_endpoints_bp = Blueprint('privateendpoints', __name__) private_endpoints_bp = Blueprint('privateendpoints', __name__)
@ -105,7 +107,7 @@ class PrivateEndpoints:
@private_endpoints_bp.route('/getActivePubkey') @private_endpoints_bp.route('/getActivePubkey')
def getActivePubkey(): def getActivePubkey():
return Response(onionrcrypto.OnionrCrypto().pubKey) return Response(pub_key)
@private_endpoints_bp.route('/getHumanReadable/<name>') @private_endpoints_bp.route('/getHumanReadable/<name>')
def getHumanReadable(name): def getHumanReadable(name):

View File

@ -236,7 +236,7 @@ class Onionr:
commands.onionrstatistics.show_peers(self) commands.onionrstatistics.show_peers(self)
def listPeers(self): def listPeers(self):
logger.info('Peer transport address list:') logger.info('Peer transport address list:', terminal=True)
for i in keydb.listkeys.list_adders(): for i in keydb.listkeys.list_adders():
logger.info(i, terminal=True) logger.info(i, terminal=True)
@ -354,7 +354,6 @@ class Onionr:
''' '''
Displays a message suggesting help Displays a message suggesting help
''' '''
if __name__ == '__main__':
logger.info('Do ' + logger.colors.bold + sys.argv[0] + ' --help' + logger.colors.reset + logger.colors.fg.green + ' for Onionr help.', terminal=True) logger.info('Do ' + logger.colors.bold + sys.argv[0] + ' --help' + logger.colors.reset + logger.colors.fg.green + ' for Onionr help.', terminal=True)
def start(self, input = False, override = False): def start(self, input = False, override = False):

View File

@ -39,7 +39,6 @@ def __event_caller(event_name, data = {}, onionr = None):
logger.warn('Event "%s" failed for plugin "%s".' % (event_name, plugin), terminal=True) logger.warn('Event "%s" failed for plugin "%s".' % (event_name, plugin), terminal=True)
logger.debug(str(e), terminal=True) logger.debug(str(e), terminal=True)
def event(event_name, data = {}, onionr = None, threaded = True): def event(event_name, data = {}, onionr = None, threaded = True):
''' '''
Calls an event on all plugins (if defined) Calls an event on all plugins (if defined)
@ -62,12 +61,11 @@ def call(plugin, event_name, data = None, pluginapi = None):
attribute = 'on_' + str(event_name).lower() attribute = 'on_' + str(event_name).lower()
if hasattr(plugin, attribute): if hasattr(plugin, attribute):
#logger.debug('Calling event ' + str(event_name))
getattr(plugin, attribute)(pluginapi, data) getattr(plugin, attribute)(pluginapi, data)
return True return True
except Exception as e: except Exception as e:
logger.error(str(e)) logger.error(str(e), terminal=True)
return False return False
else: else:
return True return True

View File

@ -92,8 +92,6 @@ class CommandAPI:
for name in names: for name in names:
self.pluginapi.get_onionr().addCommand(name, call) self.pluginapi.get_onionr().addCommand(name, call)
return
def unregister(self, names): def unregister(self, names):
if isinstance(names, str): if isinstance(names, str):
names = [names] names = [names]

View File

@ -19,14 +19,16 @@
''' '''
import onionrblockapi import onionrblockapi
from coredb import blockmetadb from coredb import blockmetadb
def load_inbox(myCore): import filepaths
import deadsimplekv as simplekv
def load_inbox():
inbox_list = [] inbox_list = []
deleted = myCore.keyStore.get('deleted_mail') deleted = simplekv.DeadSimpleKV(filepaths.cached_storage).get('deleted_mail')
if deleted is None: if deleted is None:
deleted = [] deleted = []
for blockHash in blockmetadb.get_blocks_by_type('pm'): for blockHash in blockmetadb.get_blocks_by_type('pm'):
block = onionrblockapi.Block(blockHash, core=myCore) block = onionrblockapi.Block(blockHash)
block.decrypt() block.decrypt()
if block.decrypted and blockHash not in deleted: if block.decrypted and blockHash not in deleted:
inbox_list.append(blockHash) inbox_list.append(blockHash)

View File

@ -19,15 +19,15 @@
''' '''
import sys, os, json import sys, os, json
from flask import Response, request, redirect, Blueprint, abort from flask import Response, request, redirect, Blueprint, abort
import core
from onionrusers import contactmanager from onionrusers import contactmanager
from onionrutils import stringvalidators from onionrutils import stringvalidators
import filepaths
import deadsimplekv as simplekv
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__))) sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
import loadinbox, sentboxdb import loadinbox, sentboxdb
flask_blueprint = Blueprint('mail', __name__) flask_blueprint = Blueprint('mail', __name__)
c = core.Core() kv = simplekv.DeadSimpleKV(filepaths.cached_storage)
kv = c.keyStore
@flask_blueprint.route('/mail/ping') @flask_blueprint.route('/mail/ping')
def mail_ping(): def mail_ping():
@ -48,12 +48,12 @@ def mail_delete(block):
@flask_blueprint.route('/mail/getinbox') @flask_blueprint.route('/mail/getinbox')
def list_inbox(): def list_inbox():
return ','.join(loadinbox.load_inbox(c)) return ','.join(loadinbox.load_inbox())
@flask_blueprint.route('/mail/getsentbox') @flask_blueprint.route('/mail/getsentbox')
def list_sentbox(): def list_sentbox():
kv.refresh() kv.refresh()
sentbox_list = sentboxdb.SentBox(c).listSent() sentbox_list = sentboxdb.SentBox().listSent()
list_copy = list(sentbox_list) list_copy = list(sentbox_list)
deleted = kv.get('deleted_mail') deleted = kv.get('deleted_mail')
if deleted is None: if deleted is None:
@ -62,5 +62,5 @@ def list_sentbox():
if x['hash'] in deleted: if x['hash'] in deleted:
sentbox_list.remove(x) sentbox_list.remove(x)
continue continue
x['name'] = contactmanager.ContactManager(c, x['peer'], saveUser=False).get_info('name') x['name'] = contactmanager.ContactManager(x['peer'], saveUser=False).get_info('name')
return json.dumps(sentbox_list) return json.dumps(sentbox_list)

View File

@ -25,7 +25,6 @@ import onionrexceptions
from onionrusers import onionrusers from onionrusers import onionrusers
from onionrutils import stringvalidators, escapeansi, bytesconverter from onionrutils import stringvalidators, escapeansi, bytesconverter
import locale, sys, os, json import locale, sys, os, json
from coredb import blockmetadb
locale.setlocale(locale.LC_ALL, '') locale.setlocale(locale.LC_ALL, '')
@ -35,7 +34,7 @@ PLUGIN_VERSION = '0.0.1'
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__))) sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
import sentboxdb, mailapi, loadinbox # import after path insert import sentboxdb, mailapi, loadinbox # import after path insert
flask_blueprint = mailapi.flask_blueprint flask_blueprint = mailapi.flask_blueprint
"""
def draw_border(text): def draw_border(text):
# This function taken from https://stackoverflow.com/a/20757491 by https://stackoverflow.com/users/816449/bunyk, under https://creativecommons.org/licenses/by-sa/3.0/ # This function taken from https://stackoverflow.com/a/20757491 by https://stackoverflow.com/users/816449/bunyk, under https://creativecommons.org/licenses/by-sa/3.0/
lines = text.splitlines() lines = text.splitlines()
@ -62,10 +61,9 @@ class MailStrings:
class OnionrMail: class OnionrMail:
def __init__(self, pluginapi): def __init__(self, pluginapi):
self.myCore = pluginapi.get_core()
self.strings = MailStrings(self) self.strings = MailStrings(self)
self.sentboxTools = sentboxdb.SentBox(self.myCore) self.sentboxTools = sentboxdb.SentBox()
self.sentboxList = [] self.sentboxList = []
self.sentMessages = {} self.sentMessages = {}
self.doSigs = True self.doSigs = True
@ -293,7 +291,7 @@ class OnionrMail:
pass pass
else: else:
logger.warn('Invalid choice.', terminal=True) logger.warn('Invalid choice.', terminal=True)
return return """
def add_deleted(keyStore, bHash): def add_deleted(keyStore, bHash):
existing = keyStore.get('deleted_mail') existing = keyStore.get('deleted_mail')
@ -318,7 +316,5 @@ def on_init(api, data = None):
''' '''
pluginapi = api pluginapi = api
mail = OnionrMail(pluginapi)
api.commands.register(['mail'], mail.menu)
api.commands.register_help('mail', 'Interact with OnionrMail')
return return

View File

@ -18,15 +18,13 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
''' '''
import sqlite3, os import sqlite3, os
import core
from onionrutils import epoch from onionrutils import epoch
from utils import identifyhome
class SentBox: class SentBox:
def __init__(self, mycore): def __init__(self):
assert isinstance(mycore, core.Core) self.dbLocation = identifyhome.identify_home() + '/sentbox.db'
self.dbLocation = mycore.dataDir + 'sentbox.db'
if not os.path.exists(self.dbLocation): if not os.path.exists(self.dbLocation):
self.createDB() self.createDB()
self.core = mycore
return return
def connect(self): def connect(self):