From 08d3e3a231a483aa154d31ebb63a0784b4350c1d Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Thu, 18 Jul 2019 23:59:44 -0500 Subject: [PATCH] progress in removing core --- onionr/filepaths/__init__.py | 4 +++- onionr/httpapi/insertblock.py | 6 ++--- onionr/httpapi/miscpublicapi/announce.py | 12 +++++----- onionr/httpapi/miscpublicapi/endpoints.py | 5 ++-- onionr/httpapi/miscpublicapi/getblocks.py | 4 ++-- onionr/httpapi/miscpublicapi/upload.py | 2 +- onionr/httpapi/onionrsitesapi/__init__.py | 2 +- onionr/httpapi/profilesapi/__init__.py | 1 - onionr/onionrcommands/__init__.py | 2 -- onionr/onionrcommands/banblocks.py | 7 +++--- onionr/onionrcommands/daemonlaunch.py | 25 ++++++++++---------- onionr/onionrcommands/filecommands.py | 5 ++-- onionr/onionrcommands/keyadders.py | 7 +++--- onionr/onionrcommands/onionrstatistics.py | 14 +++++++----- onionr/onionrcommands/openwebinterface.py | 4 ++-- onionr/onionrcommands/pubkeymanager.py | 28 +++++++++++------------ onionr/onionrcommands/resettor.py | 5 ++-- onionr/onionrcrypto/__init__.py | 18 +++++++-------- 18 files changed, 77 insertions(+), 74 deletions(-) diff --git a/onionr/filepaths/__init__.py b/onionr/filepaths/__init__.py index c8c14fa2..889da5e1 100644 --- a/onionr/filepaths/__init__.py +++ b/onionr/filepaths/__init__.py @@ -14,4 +14,6 @@ tor_hs_address_file = home + 'hs/hostname' run_check_file = home + '.runcheck' -data_nonce_file = home + 'block-nonces.dat' \ No newline at end of file +data_nonce_file = home + 'block-nonces.dat' + +keys_file = home + 'keys.txt' \ No newline at end of file diff --git a/onionr/httpapi/insertblock.py b/onionr/httpapi/insertblock.py index d208bf70..bdc29f72 100644 --- a/onionr/httpapi/insertblock.py +++ b/onionr/httpapi/insertblock.py @@ -19,13 +19,11 @@ ''' import json, threading from flask import Blueprint, Response, request -import core - +import onionrblocks ib = Blueprint('insertblock', __name__) @ib.route('/insertblock', methods=['POST']) def client_api_insert_block(): - c = core.Core() encrypt = False bData = request.get_json(force=True) message = bData['message'] @@ -59,5 +57,5 @@ def client_api_insert_block(): meta = json.loads(bData['meta']) except KeyError: pass - threading.Thread(target=c.insertBlock, args=(message,), kwargs={'header': bType, 'encryptType': encryptType, 'sign':sign, 'asymPeer': to, 'meta': meta}).start() + threading.Thread(target=onionrblocks.insert.insert_block, args=(message,), kwargs={'header': bType, 'encryptType': encryptType, 'sign':sign, 'asymPeer': to, 'meta': meta}).start() return Response('success') \ No newline at end of file diff --git a/onionr/httpapi/miscpublicapi/announce.py b/onionr/httpapi/miscpublicapi/announce.py index 060bead4..89b9fbb3 100755 --- a/onionr/httpapi/miscpublicapi/announce.py +++ b/onionr/httpapi/miscpublicapi/announce.py @@ -32,7 +32,7 @@ def handle_announce(clientAPI, request): powHash = '' randomData = '' newNode = '' - ourAdder = clientAPI._core.hsAddress.encode() + ourAdder = clientAPI.hsAddress.encode() try: newNode = request.form['node'].encode() except KeyError: @@ -45,17 +45,17 @@ def handle_announce(clientAPI, request): except KeyError: logger.warn('No random data specified for upload') else: - nodes = newNode + clientAPI._core.hsAddress.encode() - nodes = clientAPI._core._crypto.blake2bHash(nodes) - powHash = clientAPI._core._crypto.blake2bHash(randomData + nodes) + nodes = newNode + clientAPI.hsAddress.encode() + nodes = clientAPI.crypto.blake2bHash(nodes) + powHash = clientAPI.crypto.blake2bHash(randomData + nodes) try: powHash = powHash.decode() except AttributeError: pass if powHash.startswith('0' * onionrvalues.OnionrValues().announce_pow): newNode = bytesconverter.bytes_to_str(newNode) - if stringvalidators.validate_transport(newNode) and not newNode in clientAPI._core.onionrInst.communicatorInst.newPeers: - clientAPI._core.onionrInst.communicatorInst.newPeers.append(newNode) + if stringvalidators.validate_transport(newNode) and not newNode in clientAPI.onionrInst.communicatorInst.newPeers: + clientAPI.onionrInst.communicatorInst.newPeers.append(newNode) resp = 'Success' else: logger.warn(newNode.decode() + ' failed to meet POW: ' + powHash) diff --git a/onionr/httpapi/miscpublicapi/endpoints.py b/onionr/httpapi/miscpublicapi/endpoints.py index 05e824a6..7a5db32b 100644 --- a/onionr/httpapi/miscpublicapi/endpoints.py +++ b/onionr/httpapi/miscpublicapi/endpoints.py @@ -19,10 +19,11 @@ ''' from flask import Response, Blueprint, request, send_from_directory, abort from . import getblocks, upload, announce +from coredb import keydb class PublicEndpoints: def __init__(self, public_api): client_API = public_api.clientAPI - config = client_API._core.config + config = client_API.config public_endpoints_bp = Blueprint('publicendpoints', __name__) self.public_endpoints_bp = public_endpoints_bp @@ -61,7 +62,7 @@ class PublicEndpoints: @public_endpoints_bp.route('/pex') def peer_exchange(): - response = ','.join(client_API._core.listAdders(recent=3600)) + response = ','.join(keydb.listkeys.list_adders(recent=3600)) if len(response) == 0: response = '' return Response(response) diff --git a/onionr/httpapi/miscpublicapi/getblocks.py b/onionr/httpapi/miscpublicapi/getblocks.py index c7857966..9092e9f1 100755 --- a/onionr/httpapi/miscpublicapi/getblocks.py +++ b/onionr/httpapi/miscpublicapi/getblocks.py @@ -26,7 +26,7 @@ def get_public_block_list(clientAPI, publicAPI, request): # Provide a list of our blocks, with a date offset dateAdjust = request.args.get('date') bList = blockmetadb.get_block_list(dateRec=dateAdjust) - if clientAPI._core.config.get('general.hide_created_blocks', True): + if clientAPI.config.get('general.hide_created_blocks', True): for b in publicAPI.hideBlocks: if b in bList: # Don't share blocks we created if they haven't been *uploaded* yet, makes it harder to find who created a block @@ -37,7 +37,7 @@ def get_block_data(clientAPI, publicAPI, data): '''data is the block hash in hex''' resp = '' if stringvalidators.validate_hash(data): - if not clientAPI._core.config.get('general.hide_created_blocks', True) or data not in publicAPI.hideBlocks: + if not clientAPI.config.get('general.hide_created_blocks', True) or data not in publicAPI.hideBlocks: if data in blockmetadb.get_block_list(): block = clientAPI.getBlockData(data, raw=True) try: diff --git a/onionr/httpapi/miscpublicapi/upload.py b/onionr/httpapi/miscpublicapi/upload.py index 5fd0f32c..bc8ceac9 100755 --- a/onionr/httpapi/miscpublicapi/upload.py +++ b/onionr/httpapi/miscpublicapi/upload.py @@ -30,7 +30,7 @@ def accept_upload(clientAPI, request): else: if sys.getsizeof(data) < 100000000: try: - if blockimporter.importBlockFromData(data, clientAPI._core): + if blockimporter.importBlockFromData(data): resp = 'success' else: logger.warn('Error encountered importing uploaded block') diff --git a/onionr/httpapi/onionrsitesapi/__init__.py b/onionr/httpapi/onionrsitesapi/__init__.py index 82805192..f491cc1c 100644 --- a/onionr/httpapi/onionrsitesapi/__init__.py +++ b/onionr/httpapi/onionrsitesapi/__init__.py @@ -19,7 +19,7 @@ ''' import base64 from flask import Blueprint, Response, request, abort -import core, onionrblockapi, onionrexceptions +import onionrblockapi, onionrexceptions from onionrutils import stringvalidators site_api = Blueprint('siteapi', __name__) diff --git a/onionr/httpapi/profilesapi/__init__.py b/onionr/httpapi/profilesapi/__init__.py index 681212be..1536727b 100755 --- a/onionr/httpapi/profilesapi/__init__.py +++ b/onionr/httpapi/profilesapi/__init__.py @@ -17,7 +17,6 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . ''' -import core from flask import Blueprint, Response, request, abort from . import profiles diff --git a/onionr/onionrcommands/__init__.py b/onionr/onionrcommands/__init__.py index 39a272f2..370876e1 100755 --- a/onionr/onionrcommands/__init__.py +++ b/onionr/onionrcommands/__init__.py @@ -114,7 +114,6 @@ def get_commands(onionr_inst): 'import-blocks': importnewblocks.import_new_blocks, 'importblocks': importnewblocks.import_new_blocks, - 'introduce': onionr_inst.onionrCore.introduceNode, 'pex': dopex.do_PEX, 'getpassword': onionr_inst.printWebPassword, @@ -158,7 +157,6 @@ cmd_help = { 'listconn': 'list connected peers', 'pex': 'exchange addresses with peers (done automatically)', 'blacklist-block': 'deletes a block by hash and permanently removes it from your node', - 'introduce': 'Introduce your node to the public Onionr network', 'friend': '[add|remove] [public key/id]', 'add-id': 'Generate a new ID (key pair)', 'change-id': 'Change active ID', diff --git a/onionr/onionrcommands/banblocks.py b/onionr/onionrcommands/banblocks.py index 426e852e..22bc5cf7 100755 --- a/onionr/onionrcommands/banblocks.py +++ b/onionr/onionrcommands/banblocks.py @@ -20,16 +20,17 @@ import sys import logger from onionrutils import stringvalidators +from onionrstorage import removeblock def ban_block(o_inst): try: ban = sys.argv[2] except IndexError: ban = logger.readline('Enter a block hash:') if stringvalidators.validate_hash(ban): - if not o_inst.onionrCore._blacklist.inBlacklist(ban): + if not o_inst.blacklist.inBlacklist(ban): try: - o_inst.onionrCore._blacklist.addToDB(ban) - o_inst.onionrCore.removeBlock(ban) + o_inst.blacklist.addToDB(ban) + removeblock.remove_block(ban) except Exception as error: logger.error('Could not blacklist block', error=error, terminal=True) else: diff --git a/onionr/onionrcommands/daemonlaunch.py b/onionr/onionrcommands/daemonlaunch.py index d2c81ea5..81030cd1 100755 --- a/onionr/onionrcommands/daemonlaunch.py +++ b/onionr/onionrcommands/daemonlaunch.py @@ -24,10 +24,11 @@ import onionr, apiservers, logger, communicator import onionrevents as events from netcontroller import NetController from onionrutils import localcommand +import filepaths from coredb import daemonqueue def _proper_shutdown(o_inst): - localcommand.local_command(o_inst.onionrCore, 'shutdown') + localcommand.local_command('shutdown') sys.exit(1) def daemon(o_inst): @@ -36,9 +37,9 @@ def daemon(o_inst): ''' # remove runcheck if it exists - if os.path.isfile('%s/.runcheck' % (o_inst.onionrCore.dataDir,)): + if os.path.isfile(filepaths.run_check_file): logger.debug('Runcheck file found on daemon start, deleting in advance.') - os.remove('%s/.runcheck' % (o_inst.onionrCore.dataDir,)) + os.remove(filepaths.run_check_file) Thread(target=apiservers.ClientAPI, args=(o_inst, o_inst.debug, onionr.API_VERSION), daemon=True).start() Thread(target=apiservers.PublicAPI, args=[o_inst.getClientApi()], daemon=True).start() @@ -46,7 +47,7 @@ def daemon(o_inst): apiHost = '' while apiHost == '': try: - with open(o_inst.onionrCore.publicApiHostFile, 'r') as hostFile: + with open(filepaths.public_API_host_file, 'r') as hostFile: apiHost = hostFile.read() except FileNotFoundError: pass @@ -55,30 +56,30 @@ def daemon(o_inst): logger.raw('', terminal=True) # print nice header thing :) - if o_inst.onionrCore.config.get('general.display_header', True): + if o_inst.config.get('general.display_header', True): o_inst.header() o_inst.version(verbosity = 5, function = logger.info) logger.debug('Python version %s' % platform.python_version()) if o_inst._developmentMode: logger.warn('Development mode enabled', timestamp = False, terminal=True) - net = NetController(o_inst.onionrCore.config.get('client.public.port', 59497), apiServerIP=apiHost) + net = NetController(o_inst.config.get('client.public.port', 59497), apiServerIP=apiHost) logger.info('Tor is starting...', terminal=True) if not net.startTor(): - localcommand.local_command(o_inst.onionrCore, 'shutdown') + localcommand.local_command('shutdown') sys.exit(1) - if len(net.myID) > 0 and o_inst.onionrCore.config.get('general.security_level', 1) == 0: + if len(net.myID) > 0 and o_inst.config.get('general.security_level', 1) == 0: logger.debug('Started .onion service: %s' % (logger.colors.underline + net.myID)) else: logger.debug('.onion service disabled') - logger.info('Using public key: %s' % (logger.colors.underline + o_inst.onionrCore._crypto.pubKey[:52]), terminal=True) + logger.info('Using public key: %s' % (logger.colors.underline + o_inst._crypto.pubKey[:52]), terminal=True) try: time.sleep(1) except KeyboardInterrupt: _proper_shutdown(o_inst) - o_inst.onionrCore.torPort = net.socksPort + o_inst.torPort = net.socksPort communicatorThread = Thread(target=communicator.startCommunicator, args=(o_inst, str(net.socksPort)), daemon=True) communicatorThread.start() @@ -105,7 +106,7 @@ def daemon(o_inst): signal.signal(signal.SIGINT, _ignore_sigint) daemonqueue.daemon_queue_add('shutdown') - localcommand.local_command(o_inst.onionrCore, 'shutdown') + localcommand.local_command('shutdown') net.killTor() time.sleep(5) # Time to allow threads to finish, if not any "daemon" threads will be slaughtered http://docs.python.org/library/threading.html#threading.Thread.daemon @@ -123,7 +124,7 @@ def kill_daemon(o_inst): logger.warn('Stopping the running daemon...', timestamp = False, terminal=True) try: events.event('daemon_stop', onionr = o_inst) - net = NetController(o_inst.onionrCore.config.get('client.port', 59496)) + net = NetController(o_inst.config.get('client.port', 59496)) try: daemonqueue.daemon_queue_qdd('shutdown') except sqlite3.OperationalError: diff --git a/onionr/onionrcommands/filecommands.py b/onionr/onionrcommands/filecommands.py index 7e2cd086..5df0e9f8 100755 --- a/onionr/onionrcommands/filecommands.py +++ b/onionr/onionrcommands/filecommands.py @@ -22,6 +22,7 @@ import base64, sys, os import logger from onionrblockapi import Block from onionrutils import stringvalidators +from onionrblocks import insert def add_file(o_inst, singleBlock=False, blockType='bin'): ''' Adds a file to the onionr network @@ -37,7 +38,7 @@ def add_file(o_inst, singleBlock=False, blockType='bin'): logger.info('Adding file... this might take a long time.', terminal=True) try: with open(filename, 'rb') as singleFile: - blockhash = o_inst.onionrCore.insertBlock(base64.b64encode(singleFile.read()), header=blockType) + blockhash = insert.insert_block(base64.b64encode(singleFile.read()), header=blockType) if len(blockhash) > 0: logger.info('File %s saved in block %s' % (filename, blockhash), terminal=True) except: @@ -66,5 +67,5 @@ def getFile(o_inst): return with open(fileName, 'wb') as myFile: - myFile.write(base64.b64decode(Block(bHash, core=o_inst.onionrCore).bcontent)) + myFile.write(base64.b64decode(Block(bHash).bcontent)) return \ No newline at end of file diff --git a/onionr/onionrcommands/keyadders.py b/onionr/onionrcommands/keyadders.py index b9401d60..3f590142 100755 --- a/onionr/onionrcommands/keyadders.py +++ b/onionr/onionrcommands/keyadders.py @@ -19,18 +19,19 @@ ''' import sys import logger +from coredb import keydb def add_peer(o_inst): try: newPeer = sys.argv[2] except IndexError: pass else: - if newPeer in o_inst.onionrCore.listPeers(): + if newPeer in keydb.listkeys.list_peers(): logger.info('We already have that key', terminal=True) return logger.info("Adding peer: " + logger.colors.underline + newPeer, terminal=True) try: - if o_inst.onionrCore.addPeer(newPeer): + if keydb.addkeys.add_peer(newPeer): logger.info('Successfully added key', terminal=True) except AssertionError: logger.error('Failed to add key', terminal=True) @@ -43,7 +44,7 @@ def add_address(o_inst): pass else: logger.info("Adding address: " + logger.colors.underline + newAddress, terminal=True) - if o_inst.onionrCore.addAddress(newAddress): + if keydb.addkeys.add_address(newAddress): logger.info("Successfully added address.", terminal=True) else: logger.warn("Unable to add address.", terminal=True) \ No newline at end of file diff --git a/onionr/onionrcommands/onionrstatistics.py b/onionr/onionrcommands/onionrstatistics.py index e17d23e3..4a9e6350 100755 --- a/onionr/onionrcommands/onionrstatistics.py +++ b/onionr/onionrcommands/onionrstatistics.py @@ -23,7 +23,9 @@ from onionrblockapi import Block import onionr from onionrutils import checkcommunicator, mnemonickeys from utils import sizeutils -from coredb import blockmetadb, daemonqueue +from coredb import blockmetadb, daemonqueue, keydb +import onionrcrypto +crypto = onionrcrypto.OnionrCrypto() def show_stats(o_inst): try: # define stats messages here @@ -31,7 +33,7 @@ def show_stats(o_inst): signedBlocks = len(Block.getBlocks(signed = True)) messages = { # info about local client - 'Onionr Daemon Status' : ((logger.colors.fg.green + 'Online') if checkcommunicator.is_communicator_running(o_inst.onionrCore, timeout = 9) else logger.colors.fg.red + 'Offline'), + 'Onionr Daemon Status' : ((logger.colors.fg.green + 'Online') if checkcommunicator.is_communicator_running(timeout = 9) else logger.colors.fg.red + 'Offline'), # file and folder size stats 'div1' : True, # this creates a solid line across the screen, a div @@ -41,8 +43,8 @@ def show_stats(o_inst): # count stats 'div2' : True, - 'Known Peers' : str(max(len(o_inst.onionrCore.listPeers()) - 1, 0)), - 'Enabled Plugins' : str(len(o_inst.onionrCore.config.get('plugins.enabled', list()))) + ' / ' + str(len(os.listdir(o_inst.dataDir + 'plugins/'))), + 'Known Peers' : str(max(len(keydb.listkeys.list_peers()) - 1, 0)), + 'Enabled Plugins' : str(len(o_inst.config.get('plugins.enabled', list()))) + ' / ' + str(len(os.listdir(o_inst.dataDir + 'plugins/'))), 'Stored Blocks' : str(totalBlocks), 'Percent Blocks Signed' : str(round(100 * signedBlocks / max(totalBlocks, 1), 2)) + '%' } @@ -87,8 +89,8 @@ def show_details(o_inst): details = { 'Node Address' : o_inst.get_hostname(), 'Web Password' : o_inst.getWebPassword(), - 'Public Key' : o_inst.onionrCore._crypto.pubKey, - 'Human-readable Public Key' : mnemonickeys.get_human_readable_ID(o_inst.onionrCore) + 'Public Key' : crypto.pubKey, + 'Human-readable Public Key' : mnemonickeys.get_human_readable_ID() } for detail in details: diff --git a/onionr/onionrcommands/openwebinterface.py b/onionr/onionrcommands/openwebinterface.py index 42c80b57..b0cacfa4 100755 --- a/onionr/onionrcommands/openwebinterface.py +++ b/onionr/onionrcommands/openwebinterface.py @@ -22,10 +22,10 @@ import logger from onionrutils import getclientapiserver def open_home(o_inst): try: - url = getclientapiserver.get_client_API_server(o_inst.onionrCore) + url = getclientapiserver.get_client_API_server() except FileNotFoundError: logger.error('Onionr seems to not be running (could not get api host)', terminal=True) else: - url = 'http://%s/#%s' % (url, o_inst.onionrCore.config.get('client.webpassword')) + url = 'http://%s/#%s' % (url, o_inst.config.get('client.webpassword')) logger.info('If Onionr does not open automatically, use this URL: ' + url, terminal=True) webbrowser.open_new_tab(url) \ No newline at end of file diff --git a/onionr/onionrcommands/pubkeymanager.py b/onionr/onionrcommands/pubkeymanager.py index 72db422a..8b20a769 100755 --- a/onionr/onionrcommands/pubkeymanager.py +++ b/onionr/onionrcommands/pubkeymanager.py @@ -28,25 +28,25 @@ def add_ID(o_inst): sys.argv[2] assert sys.argv[2] == 'true' except (IndexError, AssertionError) as e: - newID = o_inst.onionrCore._crypto.keyManager.addKey()[0] + newID = o_inst.crypto.keyManager.addKey()[0] else: logger.warn('Deterministic keys require random and long passphrases.', terminal=True) logger.warn('If a good passphrase is not used, your key can be easily stolen.', terminal=True) logger.warn('You should use a series of hard to guess words, see this for reference: https://www.xkcd.com/936/', terminal=True) - pass1 = getpass.getpass(prompt='Enter at least %s characters: ' % (o_inst.onionrCore._crypto.deterministicRequirement,)) + pass1 = getpass.getpass(prompt='Enter at least %s characters: ' % (o_inst.crypto.deterministicRequirement,)) pass2 = getpass.getpass(prompt='Confirm entry: ') - if o_inst.onionrCore._crypto.safeCompare(pass1, pass2): + if o_inst.crypto.safeCompare(pass1, pass2): try: logger.info('Generating deterministic key. This can take a while.', terminal=True) - newID, privKey = o_inst.onionrCore._crypto.generateDeterministic(pass1) + newID, privKey = o_inst.crypto.generateDeterministic(pass1) except onionrexceptions.PasswordStrengthError: - logger.error('Passphrase must use at least %s characters.' % (o_inst.onionrCore._crypto.deterministicRequirement,), terminal=True) + logger.error('Passphrase must use at least %s characters.' % (o_inst.crypto.deterministicRequirement,), terminal=True) sys.exit(1) else: logger.error('Passwords do not match.', terminal=True) sys.exit(1) try: - o_inst.onionrCore._crypto.keyManager.addKey(pubKey=newID, + o_inst.crypto.keyManager.addKey(pubKey=newID, privKey=privKey) except ValueError: logger.error('That ID is already available, you can change to it with the change-id command.', terminal=True) @@ -61,9 +61,9 @@ def change_ID(o_inst): logger.warn('Specify pubkey to use', terminal=True) else: if stringvalidators.validate_pub_key(key): - if key in o_inst.onionrCore._crypto.keyManager.getPubkeyList(): - o_inst.onionrCore.config.set('general.public_key', key) - o_inst.onionrCore.config.save() + if key in o_inst.crypto.keyManager.getPubkeyList(): + o_inst.config.set('general.public_key', key) + o_inst.config.save() logger.info('Set active key to: %s' % (key,), terminal=True) logger.info('Restart Onionr if it is running.', terminal=True) else: @@ -82,22 +82,22 @@ def friend_command(o_inst): action = action.lower() if action == 'list': # List out peers marked as our friend - for friend in contactmanager.ContactManager.list_friends(o_inst.onionrCore): + for friend in contactmanager.ContactManager.list_friends(o_inst.): logger.info(friend.publicKey + ' - ' + friend.get_info('name'), terminal=True) elif action in ('add', 'remove'): try: friend = sys.argv[3] if not stringvalidators.validate_pub_key(friend): raise onionrexceptions.InvalidPubkey('Public key is invalid') - if friend not in o_inst.onionrCore.listPeers(): + if friend not in o_inst..listPeers(): raise onionrexceptions.KeyNotKnown - friend = onionrusers.OnionrUser(o_inst.onionrCore, friend) + friend = onionrusers.OnionrUser(o_inst., friend) except IndexError: logger.warn('Friend ID is required.', terminal=True) action = 'error' # set to 'error' so that the finally block does not process anything except onionrexceptions.KeyNotKnown: - o_inst.onionrCore.addPeer(friend) - friend = onionrusers.OnionrUser(o_inst.onionrCore, friend) + o_inst..addPeer(friend) + friend = onionrusers.OnionrUser(o_inst., friend) finally: if action == 'add': friend.setTrust(1) diff --git a/onionr/onionrcommands/resettor.py b/onionr/onionrcommands/resettor.py index e327bccc..86bc9c3f 100755 --- a/onionr/onionrcommands/resettor.py +++ b/onionr/onionrcommands/resettor.py @@ -18,14 +18,13 @@ along with this program. If not, see . ''' import os, shutil -import logger, core +import logger from onionrutils import localcommand def reset_tor(): - c = core.Core() tor_dir = c.dataDir + 'tordata' if os.path.exists(tor_dir): - if localcommand.local_command(c, '/ping') == 'pong!': + if localcommand.local_command('/ping') == 'pong!': logger.warn('Cannot delete Tor data while Onionr is running', terminal=True) else: shutil.rmtree(tor_dir) \ No newline at end of file diff --git a/onionr/onionrcrypto/__init__.py b/onionr/onionrcrypto/__init__.py index 957733eb..f6252863 100755 --- a/onionr/onionrcrypto/__init__.py +++ b/onionr/onionrcrypto/__init__.py @@ -22,14 +22,14 @@ import nacl.signing, nacl.encoding, nacl.public, nacl.hash, nacl.pwhash, nacl.ut import unpaddedbase32 import logger, onionrproofs from onionrutils import stringvalidators, epoch, bytesconverter -import onionrexceptions, keymanager, core, onionrutils +import filepaths +import onionrexceptions, keymanager, onionrutils import config config.reload() class OnionrCrypto: - def __init__(self, coreInstance): - self._core = coreInstance - self._keyFile = self._core.dataDir + 'keys.txt' + def __init__(self): + self._keyFile = filepaths.keys_file self.pubKey = None self.privKey = None self.secrets = secrets @@ -39,8 +39,8 @@ class OnionrCrypto: # Load our own pub/priv Ed25519 keys, gen & save them if they don't exist if os.path.exists(self._keyFile): - if len(self._core.config.get('general.public_key', '')) > 0: - self.pubKey = self._core.config.get('general.public_key') + if len(config.get('general.public_key', '')) > 0: + self.pubKey = config.get('general.public_key') else: self.pubKey = self.keyManager.getPubkeyList()[0] self.privKey = self.keyManager.getPrivkey(self.pubKey) @@ -249,10 +249,10 @@ class OnionrCrypto: except AttributeError: pass - difficulty = onionrproofs.getDifficultyForNewBlock(blockContent, ourBlock=False, coreInst=self._core) + difficulty = onionrproofs.getDifficultyForNewBlock(blockContent, ourBlock=False) - if difficulty < int(self._core.config.get('general.minimum_block_pow')): - difficulty = int(self._core.config.get('general.minimum_block_pow')) + if difficulty < int(config.get('general.minimum_block_pow')): + difficulty = int(config.get('general.minimum_block_pow')) mainHash = '0000000000000000000000000000000000000000000000000000000000000000'#nacl.hash.blake2b(nacl.utils.random()).decode() puzzle = mainHash[:difficulty]