progress in removing core
This commit is contained in:
parent
dbbefafd19
commit
08d3e3a231
@ -15,3 +15,5 @@ tor_hs_address_file = home + 'hs/hostname'
|
|||||||
run_check_file = home + '.runcheck'
|
run_check_file = home + '.runcheck'
|
||||||
|
|
||||||
data_nonce_file = home + 'block-nonces.dat'
|
data_nonce_file = home + 'block-nonces.dat'
|
||||||
|
|
||||||
|
keys_file = home + 'keys.txt'
|
@ -19,13 +19,11 @@
|
|||||||
'''
|
'''
|
||||||
import json, threading
|
import json, threading
|
||||||
from flask import Blueprint, Response, request
|
from flask import Blueprint, Response, request
|
||||||
import core
|
import onionrblocks
|
||||||
|
|
||||||
ib = Blueprint('insertblock', __name__)
|
ib = Blueprint('insertblock', __name__)
|
||||||
|
|
||||||
@ib.route('/insertblock', methods=['POST'])
|
@ib.route('/insertblock', methods=['POST'])
|
||||||
def client_api_insert_block():
|
def client_api_insert_block():
|
||||||
c = core.Core()
|
|
||||||
encrypt = False
|
encrypt = False
|
||||||
bData = request.get_json(force=True)
|
bData = request.get_json(force=True)
|
||||||
message = bData['message']
|
message = bData['message']
|
||||||
@ -59,5 +57,5 @@ def client_api_insert_block():
|
|||||||
meta = json.loads(bData['meta'])
|
meta = json.loads(bData['meta'])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
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')
|
return Response('success')
|
@ -32,7 +32,7 @@ def handle_announce(clientAPI, request):
|
|||||||
powHash = ''
|
powHash = ''
|
||||||
randomData = ''
|
randomData = ''
|
||||||
newNode = ''
|
newNode = ''
|
||||||
ourAdder = clientAPI._core.hsAddress.encode()
|
ourAdder = clientAPI.hsAddress.encode()
|
||||||
try:
|
try:
|
||||||
newNode = request.form['node'].encode()
|
newNode = request.form['node'].encode()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@ -45,17 +45,17 @@ def handle_announce(clientAPI, request):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
logger.warn('No random data specified for upload')
|
logger.warn('No random data specified for upload')
|
||||||
else:
|
else:
|
||||||
nodes = newNode + clientAPI._core.hsAddress.encode()
|
nodes = newNode + clientAPI.hsAddress.encode()
|
||||||
nodes = clientAPI._core._crypto.blake2bHash(nodes)
|
nodes = clientAPI.crypto.blake2bHash(nodes)
|
||||||
powHash = clientAPI._core._crypto.blake2bHash(randomData + nodes)
|
powHash = clientAPI.crypto.blake2bHash(randomData + nodes)
|
||||||
try:
|
try:
|
||||||
powHash = powHash.decode()
|
powHash = powHash.decode()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
if powHash.startswith('0' * onionrvalues.OnionrValues().announce_pow):
|
if powHash.startswith('0' * onionrvalues.OnionrValues().announce_pow):
|
||||||
newNode = bytesconverter.bytes_to_str(newNode)
|
newNode = bytesconverter.bytes_to_str(newNode)
|
||||||
if stringvalidators.validate_transport(newNode) and not newNode in clientAPI._core.onionrInst.communicatorInst.newPeers:
|
if stringvalidators.validate_transport(newNode) and not newNode in clientAPI.onionrInst.communicatorInst.newPeers:
|
||||||
clientAPI._core.onionrInst.communicatorInst.newPeers.append(newNode)
|
clientAPI.onionrInst.communicatorInst.newPeers.append(newNode)
|
||||||
resp = 'Success'
|
resp = 'Success'
|
||||||
else:
|
else:
|
||||||
logger.warn(newNode.decode() + ' failed to meet POW: ' + powHash)
|
logger.warn(newNode.decode() + ' failed to meet POW: ' + powHash)
|
||||||
|
@ -19,10 +19,11 @@
|
|||||||
'''
|
'''
|
||||||
from flask import Response, Blueprint, request, send_from_directory, abort
|
from flask import Response, Blueprint, request, send_from_directory, abort
|
||||||
from . import getblocks, upload, announce
|
from . import getblocks, upload, announce
|
||||||
|
from coredb import keydb
|
||||||
class PublicEndpoints:
|
class PublicEndpoints:
|
||||||
def __init__(self, public_api):
|
def __init__(self, public_api):
|
||||||
client_API = public_api.clientAPI
|
client_API = public_api.clientAPI
|
||||||
config = client_API._core.config
|
config = client_API.config
|
||||||
|
|
||||||
public_endpoints_bp = Blueprint('publicendpoints', __name__)
|
public_endpoints_bp = Blueprint('publicendpoints', __name__)
|
||||||
self.public_endpoints_bp = public_endpoints_bp
|
self.public_endpoints_bp = public_endpoints_bp
|
||||||
@ -61,7 +62,7 @@ class PublicEndpoints:
|
|||||||
|
|
||||||
@public_endpoints_bp.route('/pex')
|
@public_endpoints_bp.route('/pex')
|
||||||
def peer_exchange():
|
def peer_exchange():
|
||||||
response = ','.join(client_API._core.listAdders(recent=3600))
|
response = ','.join(keydb.listkeys.list_adders(recent=3600))
|
||||||
if len(response) == 0:
|
if len(response) == 0:
|
||||||
response = ''
|
response = ''
|
||||||
return Response(response)
|
return Response(response)
|
||||||
|
@ -26,7 +26,7 @@ def get_public_block_list(clientAPI, publicAPI, request):
|
|||||||
# Provide a list of our blocks, with a date offset
|
# Provide a list of our blocks, with a date offset
|
||||||
dateAdjust = request.args.get('date')
|
dateAdjust = request.args.get('date')
|
||||||
bList = blockmetadb.get_block_list(dateRec=dateAdjust)
|
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:
|
for b in publicAPI.hideBlocks:
|
||||||
if b in bList:
|
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
|
# 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'''
|
'''data is the block hash in hex'''
|
||||||
resp = ''
|
resp = ''
|
||||||
if stringvalidators.validate_hash(data):
|
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():
|
if data in blockmetadb.get_block_list():
|
||||||
block = clientAPI.getBlockData(data, raw=True)
|
block = clientAPI.getBlockData(data, raw=True)
|
||||||
try:
|
try:
|
||||||
|
@ -30,7 +30,7 @@ def accept_upload(clientAPI, request):
|
|||||||
else:
|
else:
|
||||||
if sys.getsizeof(data) < 100000000:
|
if sys.getsizeof(data) < 100000000:
|
||||||
try:
|
try:
|
||||||
if blockimporter.importBlockFromData(data, clientAPI._core):
|
if blockimporter.importBlockFromData(data):
|
||||||
resp = 'success'
|
resp = 'success'
|
||||||
else:
|
else:
|
||||||
logger.warn('Error encountered importing uploaded block')
|
logger.warn('Error encountered importing uploaded block')
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
'''
|
'''
|
||||||
import base64
|
import base64
|
||||||
from flask import Blueprint, Response, request, abort
|
from flask import Blueprint, Response, request, abort
|
||||||
import core, onionrblockapi, onionrexceptions
|
import onionrblockapi, onionrexceptions
|
||||||
from onionrutils import stringvalidators
|
from onionrutils import stringvalidators
|
||||||
|
|
||||||
site_api = Blueprint('siteapi', __name__)
|
site_api = Blueprint('siteapi', __name__)
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
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 core
|
|
||||||
from flask import Blueprint, Response, request, abort
|
from flask import Blueprint, Response, request, abort
|
||||||
from . import profiles
|
from . import profiles
|
||||||
|
|
||||||
|
@ -114,7 +114,6 @@ def get_commands(onionr_inst):
|
|||||||
'import-blocks': importnewblocks.import_new_blocks,
|
'import-blocks': importnewblocks.import_new_blocks,
|
||||||
'importblocks': importnewblocks.import_new_blocks,
|
'importblocks': importnewblocks.import_new_blocks,
|
||||||
|
|
||||||
'introduce': onionr_inst.onionrCore.introduceNode,
|
|
||||||
'pex': dopex.do_PEX,
|
'pex': dopex.do_PEX,
|
||||||
|
|
||||||
'getpassword': onionr_inst.printWebPassword,
|
'getpassword': onionr_inst.printWebPassword,
|
||||||
@ -158,7 +157,6 @@ cmd_help = {
|
|||||||
'listconn': 'list connected peers',
|
'listconn': 'list connected peers',
|
||||||
'pex': 'exchange addresses with peers (done automatically)',
|
'pex': 'exchange addresses with peers (done automatically)',
|
||||||
'blacklist-block': 'deletes a block by hash and permanently removes it from your node',
|
'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]',
|
'friend': '[add|remove] [public key/id]',
|
||||||
'add-id': 'Generate a new ID (key pair)',
|
'add-id': 'Generate a new ID (key pair)',
|
||||||
'change-id': 'Change active ID',
|
'change-id': 'Change active ID',
|
||||||
|
@ -20,16 +20,17 @@
|
|||||||
import sys
|
import sys
|
||||||
import logger
|
import logger
|
||||||
from onionrutils import stringvalidators
|
from onionrutils import stringvalidators
|
||||||
|
from onionrstorage import removeblock
|
||||||
def ban_block(o_inst):
|
def ban_block(o_inst):
|
||||||
try:
|
try:
|
||||||
ban = sys.argv[2]
|
ban = sys.argv[2]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
ban = logger.readline('Enter a block hash:')
|
ban = logger.readline('Enter a block hash:')
|
||||||
if stringvalidators.validate_hash(ban):
|
if stringvalidators.validate_hash(ban):
|
||||||
if not o_inst.onionrCore._blacklist.inBlacklist(ban):
|
if not o_inst.blacklist.inBlacklist(ban):
|
||||||
try:
|
try:
|
||||||
o_inst.onionrCore._blacklist.addToDB(ban)
|
o_inst.blacklist.addToDB(ban)
|
||||||
o_inst.onionrCore.removeBlock(ban)
|
removeblock.remove_block(ban)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
logger.error('Could not blacklist block', error=error, terminal=True)
|
logger.error('Could not blacklist block', error=error, terminal=True)
|
||||||
else:
|
else:
|
||||||
|
@ -24,10 +24,11 @@ import onionr, apiservers, logger, communicator
|
|||||||
import onionrevents as events
|
import onionrevents as events
|
||||||
from netcontroller import NetController
|
from netcontroller import NetController
|
||||||
from onionrutils import localcommand
|
from onionrutils import localcommand
|
||||||
|
import filepaths
|
||||||
from coredb import daemonqueue
|
from coredb import daemonqueue
|
||||||
|
|
||||||
def _proper_shutdown(o_inst):
|
def _proper_shutdown(o_inst):
|
||||||
localcommand.local_command(o_inst.onionrCore, 'shutdown')
|
localcommand.local_command('shutdown')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def daemon(o_inst):
|
def daemon(o_inst):
|
||||||
@ -36,9 +37,9 @@ def daemon(o_inst):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
# remove runcheck if it exists
|
# 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.')
|
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.ClientAPI, args=(o_inst, o_inst.debug, onionr.API_VERSION), daemon=True).start()
|
||||||
Thread(target=apiservers.PublicAPI, args=[o_inst.getClientApi()], daemon=True).start()
|
Thread(target=apiservers.PublicAPI, args=[o_inst.getClientApi()], daemon=True).start()
|
||||||
@ -46,7 +47,7 @@ def daemon(o_inst):
|
|||||||
apiHost = ''
|
apiHost = ''
|
||||||
while apiHost == '':
|
while apiHost == '':
|
||||||
try:
|
try:
|
||||||
with open(o_inst.onionrCore.publicApiHostFile, 'r') as hostFile:
|
with open(filepaths.public_API_host_file, 'r') as hostFile:
|
||||||
apiHost = hostFile.read()
|
apiHost = hostFile.read()
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
@ -55,30 +56,30 @@ def daemon(o_inst):
|
|||||||
|
|
||||||
logger.raw('', terminal=True)
|
logger.raw('', terminal=True)
|
||||||
# print nice header thing :)
|
# 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.header()
|
||||||
o_inst.version(verbosity = 5, function = logger.info)
|
o_inst.version(verbosity = 5, function = logger.info)
|
||||||
logger.debug('Python version %s' % platform.python_version())
|
logger.debug('Python version %s' % platform.python_version())
|
||||||
|
|
||||||
if o_inst._developmentMode:
|
if o_inst._developmentMode:
|
||||||
logger.warn('Development mode enabled', timestamp = False, terminal=True)
|
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)
|
logger.info('Tor is starting...', terminal=True)
|
||||||
if not net.startTor():
|
if not net.startTor():
|
||||||
localcommand.local_command(o_inst.onionrCore, 'shutdown')
|
localcommand.local_command('shutdown')
|
||||||
sys.exit(1)
|
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))
|
logger.debug('Started .onion service: %s' % (logger.colors.underline + net.myID))
|
||||||
else:
|
else:
|
||||||
logger.debug('.onion service disabled')
|
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:
|
try:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
_proper_shutdown(o_inst)
|
_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 = Thread(target=communicator.startCommunicator, args=(o_inst, str(net.socksPort)), daemon=True)
|
||||||
communicatorThread.start()
|
communicatorThread.start()
|
||||||
|
|
||||||
@ -105,7 +106,7 @@ def daemon(o_inst):
|
|||||||
|
|
||||||
signal.signal(signal.SIGINT, _ignore_sigint)
|
signal.signal(signal.SIGINT, _ignore_sigint)
|
||||||
daemonqueue.daemon_queue_add('shutdown')
|
daemonqueue.daemon_queue_add('shutdown')
|
||||||
localcommand.local_command(o_inst.onionrCore, 'shutdown')
|
localcommand.local_command('shutdown')
|
||||||
|
|
||||||
net.killTor()
|
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
|
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)
|
logger.warn('Stopping the running daemon...', timestamp = False, terminal=True)
|
||||||
try:
|
try:
|
||||||
events.event('daemon_stop', onionr = o_inst)
|
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:
|
try:
|
||||||
daemonqueue.daemon_queue_qdd('shutdown')
|
daemonqueue.daemon_queue_qdd('shutdown')
|
||||||
except sqlite3.OperationalError:
|
except sqlite3.OperationalError:
|
||||||
|
@ -22,6 +22,7 @@ import base64, sys, os
|
|||||||
import logger
|
import logger
|
||||||
from onionrblockapi import Block
|
from onionrblockapi import Block
|
||||||
from onionrutils import stringvalidators
|
from onionrutils import stringvalidators
|
||||||
|
from onionrblocks import insert
|
||||||
def add_file(o_inst, singleBlock=False, blockType='bin'):
|
def add_file(o_inst, singleBlock=False, blockType='bin'):
|
||||||
'''
|
'''
|
||||||
Adds a file to the onionr network
|
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)
|
logger.info('Adding file... this might take a long time.', terminal=True)
|
||||||
try:
|
try:
|
||||||
with open(filename, 'rb') as singleFile:
|
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:
|
if len(blockhash) > 0:
|
||||||
logger.info('File %s saved in block %s' % (filename, blockhash), terminal=True)
|
logger.info('File %s saved in block %s' % (filename, blockhash), terminal=True)
|
||||||
except:
|
except:
|
||||||
@ -66,5 +67,5 @@ def getFile(o_inst):
|
|||||||
return
|
return
|
||||||
|
|
||||||
with open(fileName, 'wb') as myFile:
|
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
|
return
|
@ -19,18 +19,19 @@
|
|||||||
'''
|
'''
|
||||||
import sys
|
import sys
|
||||||
import logger
|
import logger
|
||||||
|
from coredb import keydb
|
||||||
def add_peer(o_inst):
|
def add_peer(o_inst):
|
||||||
try:
|
try:
|
||||||
newPeer = sys.argv[2]
|
newPeer = sys.argv[2]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if newPeer in o_inst.onionrCore.listPeers():
|
if newPeer in keydb.listkeys.list_peers():
|
||||||
logger.info('We already have that key', terminal=True)
|
logger.info('We already have that key', terminal=True)
|
||||||
return
|
return
|
||||||
logger.info("Adding peer: " + logger.colors.underline + newPeer, terminal=True)
|
logger.info("Adding peer: " + logger.colors.underline + newPeer, terminal=True)
|
||||||
try:
|
try:
|
||||||
if o_inst.onionrCore.addPeer(newPeer):
|
if keydb.addkeys.add_peer(newPeer):
|
||||||
logger.info('Successfully added key', terminal=True)
|
logger.info('Successfully added key', terminal=True)
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
logger.error('Failed to add key', terminal=True)
|
logger.error('Failed to add key', terminal=True)
|
||||||
@ -43,7 +44,7 @@ def add_address(o_inst):
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
logger.info("Adding address: " + logger.colors.underline + newAddress, terminal=True)
|
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)
|
logger.info("Successfully added address.", terminal=True)
|
||||||
else:
|
else:
|
||||||
logger.warn("Unable to add address.", terminal=True)
|
logger.warn("Unable to add address.", terminal=True)
|
@ -23,7 +23,9 @@ from onionrblockapi import Block
|
|||||||
import onionr
|
import onionr
|
||||||
from onionrutils import checkcommunicator, mnemonickeys
|
from onionrutils import checkcommunicator, mnemonickeys
|
||||||
from utils import sizeutils
|
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):
|
def show_stats(o_inst):
|
||||||
try:
|
try:
|
||||||
# define stats messages here
|
# define stats messages here
|
||||||
@ -31,7 +33,7 @@ def show_stats(o_inst):
|
|||||||
signedBlocks = len(Block.getBlocks(signed = True))
|
signedBlocks = len(Block.getBlocks(signed = True))
|
||||||
messages = {
|
messages = {
|
||||||
# info about local client
|
# 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
|
# file and folder size stats
|
||||||
'div1' : True, # this creates a solid line across the screen, a div
|
'div1' : True, # this creates a solid line across the screen, a div
|
||||||
@ -41,8 +43,8 @@ def show_stats(o_inst):
|
|||||||
|
|
||||||
# count stats
|
# count stats
|
||||||
'div2' : True,
|
'div2' : True,
|
||||||
'Known Peers' : str(max(len(o_inst.onionrCore.listPeers()) - 1, 0)),
|
'Known Peers' : str(max(len(keydb.listkeys.list_peers()) - 1, 0)),
|
||||||
'Enabled Plugins' : str(len(o_inst.onionrCore.config.get('plugins.enabled', list()))) + ' / ' + str(len(os.listdir(o_inst.dataDir + 'plugins/'))),
|
'Enabled Plugins' : str(len(o_inst.config.get('plugins.enabled', list()))) + ' / ' + str(len(os.listdir(o_inst.dataDir + 'plugins/'))),
|
||||||
'Stored Blocks' : str(totalBlocks),
|
'Stored Blocks' : str(totalBlocks),
|
||||||
'Percent Blocks Signed' : str(round(100 * signedBlocks / max(totalBlocks, 1), 2)) + '%'
|
'Percent Blocks Signed' : str(round(100 * signedBlocks / max(totalBlocks, 1), 2)) + '%'
|
||||||
}
|
}
|
||||||
@ -87,8 +89,8 @@ def show_details(o_inst):
|
|||||||
details = {
|
details = {
|
||||||
'Node Address' : o_inst.get_hostname(),
|
'Node Address' : o_inst.get_hostname(),
|
||||||
'Web Password' : o_inst.getWebPassword(),
|
'Web Password' : o_inst.getWebPassword(),
|
||||||
'Public Key' : o_inst.onionrCore._crypto.pubKey,
|
'Public Key' : crypto.pubKey,
|
||||||
'Human-readable Public Key' : mnemonickeys.get_human_readable_ID(o_inst.onionrCore)
|
'Human-readable Public Key' : mnemonickeys.get_human_readable_ID()
|
||||||
}
|
}
|
||||||
|
|
||||||
for detail in details:
|
for detail in details:
|
||||||
|
@ -22,10 +22,10 @@ import logger
|
|||||||
from onionrutils import getclientapiserver
|
from onionrutils import getclientapiserver
|
||||||
def open_home(o_inst):
|
def open_home(o_inst):
|
||||||
try:
|
try:
|
||||||
url = getclientapiserver.get_client_API_server(o_inst.onionrCore)
|
url = getclientapiserver.get_client_API_server()
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
logger.error('Onionr seems to not be running (could not get api host)', terminal=True)
|
logger.error('Onionr seems to not be running (could not get api host)', terminal=True)
|
||||||
else:
|
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)
|
logger.info('If Onionr does not open automatically, use this URL: ' + url, terminal=True)
|
||||||
webbrowser.open_new_tab(url)
|
webbrowser.open_new_tab(url)
|
@ -28,25 +28,25 @@ def add_ID(o_inst):
|
|||||||
sys.argv[2]
|
sys.argv[2]
|
||||||
assert sys.argv[2] == 'true'
|
assert sys.argv[2] == 'true'
|
||||||
except (IndexError, AssertionError) as e:
|
except (IndexError, AssertionError) as e:
|
||||||
newID = o_inst.onionrCore._crypto.keyManager.addKey()[0]
|
newID = o_inst.crypto.keyManager.addKey()[0]
|
||||||
else:
|
else:
|
||||||
logger.warn('Deterministic keys require random and long passphrases.', terminal=True)
|
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('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)
|
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: ')
|
pass2 = getpass.getpass(prompt='Confirm entry: ')
|
||||||
if o_inst.onionrCore._crypto.safeCompare(pass1, pass2):
|
if o_inst.crypto.safeCompare(pass1, pass2):
|
||||||
try:
|
try:
|
||||||
logger.info('Generating deterministic key. This can take a while.', terminal=True)
|
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:
|
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)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
logger.error('Passwords do not match.', terminal=True)
|
logger.error('Passwords do not match.', terminal=True)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
try:
|
try:
|
||||||
o_inst.onionrCore._crypto.keyManager.addKey(pubKey=newID,
|
o_inst.crypto.keyManager.addKey(pubKey=newID,
|
||||||
privKey=privKey)
|
privKey=privKey)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
logger.error('That ID is already available, you can change to it with the change-id command.', terminal=True)
|
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)
|
logger.warn('Specify pubkey to use', terminal=True)
|
||||||
else:
|
else:
|
||||||
if stringvalidators.validate_pub_key(key):
|
if stringvalidators.validate_pub_key(key):
|
||||||
if key in o_inst.onionrCore._crypto.keyManager.getPubkeyList():
|
if key in o_inst.crypto.keyManager.getPubkeyList():
|
||||||
o_inst.onionrCore.config.set('general.public_key', key)
|
o_inst.config.set('general.public_key', key)
|
||||||
o_inst.onionrCore.config.save()
|
o_inst.config.save()
|
||||||
logger.info('Set active key to: %s' % (key,), terminal=True)
|
logger.info('Set active key to: %s' % (key,), terminal=True)
|
||||||
logger.info('Restart Onionr if it is running.', terminal=True)
|
logger.info('Restart Onionr if it is running.', terminal=True)
|
||||||
else:
|
else:
|
||||||
@ -82,22 +82,22 @@ def friend_command(o_inst):
|
|||||||
action = action.lower()
|
action = action.lower()
|
||||||
if action == 'list':
|
if action == 'list':
|
||||||
# List out peers marked as our friend
|
# 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)
|
logger.info(friend.publicKey + ' - ' + friend.get_info('name'), terminal=True)
|
||||||
elif action in ('add', 'remove'):
|
elif action in ('add', 'remove'):
|
||||||
try:
|
try:
|
||||||
friend = sys.argv[3]
|
friend = sys.argv[3]
|
||||||
if not stringvalidators.validate_pub_key(friend):
|
if not stringvalidators.validate_pub_key(friend):
|
||||||
raise onionrexceptions.InvalidPubkey('Public key is invalid')
|
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
|
raise onionrexceptions.KeyNotKnown
|
||||||
friend = onionrusers.OnionrUser(o_inst.onionrCore, friend)
|
friend = onionrusers.OnionrUser(o_inst., friend)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
logger.warn('Friend ID is required.', terminal=True)
|
logger.warn('Friend ID is required.', terminal=True)
|
||||||
action = 'error' # set to 'error' so that the finally block does not process anything
|
action = 'error' # set to 'error' so that the finally block does not process anything
|
||||||
except onionrexceptions.KeyNotKnown:
|
except onionrexceptions.KeyNotKnown:
|
||||||
o_inst.onionrCore.addPeer(friend)
|
o_inst..addPeer(friend)
|
||||||
friend = onionrusers.OnionrUser(o_inst.onionrCore, friend)
|
friend = onionrusers.OnionrUser(o_inst., friend)
|
||||||
finally:
|
finally:
|
||||||
if action == 'add':
|
if action == 'add':
|
||||||
friend.setTrust(1)
|
friend.setTrust(1)
|
||||||
|
@ -18,14 +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 os, shutil
|
import os, shutil
|
||||||
import logger, core
|
import logger
|
||||||
from onionrutils import localcommand
|
from onionrutils import localcommand
|
||||||
|
|
||||||
def reset_tor():
|
def reset_tor():
|
||||||
c = core.Core()
|
|
||||||
tor_dir = c.dataDir + 'tordata'
|
tor_dir = c.dataDir + 'tordata'
|
||||||
if os.path.exists(tor_dir):
|
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)
|
logger.warn('Cannot delete Tor data while Onionr is running', terminal=True)
|
||||||
else:
|
else:
|
||||||
shutil.rmtree(tor_dir)
|
shutil.rmtree(tor_dir)
|
@ -22,14 +22,14 @@ import nacl.signing, nacl.encoding, nacl.public, nacl.hash, nacl.pwhash, nacl.ut
|
|||||||
import unpaddedbase32
|
import unpaddedbase32
|
||||||
import logger, onionrproofs
|
import logger, onionrproofs
|
||||||
from onionrutils import stringvalidators, epoch, bytesconverter
|
from onionrutils import stringvalidators, epoch, bytesconverter
|
||||||
import onionrexceptions, keymanager, core, onionrutils
|
import filepaths
|
||||||
|
import onionrexceptions, keymanager, onionrutils
|
||||||
import config
|
import config
|
||||||
config.reload()
|
config.reload()
|
||||||
|
|
||||||
class OnionrCrypto:
|
class OnionrCrypto:
|
||||||
def __init__(self, coreInstance):
|
def __init__(self):
|
||||||
self._core = coreInstance
|
self._keyFile = filepaths.keys_file
|
||||||
self._keyFile = self._core.dataDir + 'keys.txt'
|
|
||||||
self.pubKey = None
|
self.pubKey = None
|
||||||
self.privKey = None
|
self.privKey = None
|
||||||
self.secrets = secrets
|
self.secrets = secrets
|
||||||
@ -39,8 +39,8 @@ class OnionrCrypto:
|
|||||||
|
|
||||||
# Load our own pub/priv Ed25519 keys, gen & save them if they don't exist
|
# Load our own pub/priv Ed25519 keys, gen & save them if they don't exist
|
||||||
if os.path.exists(self._keyFile):
|
if os.path.exists(self._keyFile):
|
||||||
if len(self._core.config.get('general.public_key', '')) > 0:
|
if len(config.get('general.public_key', '')) > 0:
|
||||||
self.pubKey = self._core.config.get('general.public_key')
|
self.pubKey = config.get('general.public_key')
|
||||||
else:
|
else:
|
||||||
self.pubKey = self.keyManager.getPubkeyList()[0]
|
self.pubKey = self.keyManager.getPubkeyList()[0]
|
||||||
self.privKey = self.keyManager.getPrivkey(self.pubKey)
|
self.privKey = self.keyManager.getPrivkey(self.pubKey)
|
||||||
@ -249,10 +249,10 @@ class OnionrCrypto:
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
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')):
|
if difficulty < int(config.get('general.minimum_block_pow')):
|
||||||
difficulty = int(self._core.config.get('general.minimum_block_pow'))
|
difficulty = int(config.get('general.minimum_block_pow'))
|
||||||
mainHash = '0000000000000000000000000000000000000000000000000000000000000000'#nacl.hash.blake2b(nacl.utils.random()).decode()
|
mainHash = '0000000000000000000000000000000000000000000000000000000000000000'#nacl.hash.blake2b(nacl.utils.random()).decode()
|
||||||
puzzle = mainHash[:difficulty]
|
puzzle = mainHash[:difficulty]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user