Finished removing onionrutils for the most part, except for some possible bugs remaining
This commit is contained in:
parent
c7e06205b7
commit
122eb4ee5f
@ -37,7 +37,7 @@ def importBlockFromData(content, coreInst):
|
|||||||
|
|
||||||
metas = blockmetadata.get_block_metadata_from_data(content) # returns tuple(metadata, meta), meta is also in metadata
|
metas = blockmetadata.get_block_metadata_from_data(content) # returns tuple(metadata, meta), meta is also in metadata
|
||||||
metadata = metas[0]
|
metadata = metas[0]
|
||||||
if validatemetadata(metadata, metas[2]): # check if metadata is valid
|
if validatemetadata.validate_metadata(coreInst, metadata, metas[2]): # check if metadata is valid
|
||||||
if coreInst._crypto.verifyPow(content): # check if POW is enough/correct
|
if coreInst._crypto.verifyPow(content): # check if POW is enough/correct
|
||||||
logger.info('Block passed proof, saving.', terminal=True)
|
logger.info('Block passed proof, saving.', terminal=True)
|
||||||
try:
|
try:
|
||||||
@ -46,6 +46,6 @@ def importBlockFromData(content, coreInst):
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
coreInst.addToBlockDB(blockHash, dataSaved=True)
|
coreInst.addToBlockDB(blockHash, dataSaved=True)
|
||||||
blockmetadata.process_block_metadata(blockHash) # caches block metadata values to block database
|
blockmetadata.process_block_metadata(coreInst, blockHash) # caches block metadata values to block database
|
||||||
retData = True
|
retData = True
|
||||||
return retData
|
return retData
|
@ -20,7 +20,7 @@
|
|||||||
import base64
|
import base64
|
||||||
import onionrproofs, logger
|
import onionrproofs, logger
|
||||||
from etc import onionrvalues
|
from etc import onionrvalues
|
||||||
from onionrutils import basicrequests
|
from onionrutils import basicrequests, bytesconverter
|
||||||
|
|
||||||
def announce_node(daemon):
|
def announce_node(daemon):
|
||||||
'''Announce our node to our peers'''
|
'''Announce our node to our peers'''
|
||||||
@ -53,7 +53,7 @@ def announce_node(daemon):
|
|||||||
combinedNodes = ourID + peer
|
combinedNodes = ourID + peer
|
||||||
if ourID != 1:
|
if ourID != 1:
|
||||||
#TODO: Extend existingRand for i2p
|
#TODO: Extend existingRand for i2p
|
||||||
existingRand = daemon._core._utils.bytesToStr(daemon._core.getAddressInfo(peer, 'powValue'))
|
existingRand = bytesconverter.bytes_to_str(daemon._core.getAddressInfo(peer, 'powValue'))
|
||||||
# Reset existingRand if it no longer meets the minimum POW
|
# Reset existingRand if it no longer meets the minimum POW
|
||||||
if type(existingRand) is type(None) or not existingRand.endswith('0' * ov.announce_pow):
|
if type(existingRand) is type(None) or not existingRand.endswith('0' * ov.announce_pow):
|
||||||
existingRand = ''
|
existingRand = ''
|
||||||
|
@ -75,7 +75,7 @@ def download_blocks_from_communicator(comm_inst):
|
|||||||
content = content.decode() # decode here because sha3Hash needs bytes above
|
content = content.decode() # decode here because sha3Hash needs bytes above
|
||||||
metas = blockmetadata.get_block_metadata_from_data(content) # returns tuple(metadata, meta), meta is also in metadata
|
metas = blockmetadata.get_block_metadata_from_data(content) # returns tuple(metadata, meta), meta is also in metadata
|
||||||
metadata = metas[0]
|
metadata = metas[0]
|
||||||
if validatemetadata.validate_metadata(comm_inist._core, metadata, metas[2]): # check if metadata is valid, and verify nonce
|
if validatemetadata.validate_metadata(comm_inst._core, metadata, metas[2]): # check if metadata is valid, and verify nonce
|
||||||
if comm_inst._core._crypto.verifyPow(content): # check if POW is enough/correct
|
if comm_inst._core._crypto.verifyPow(content): # check if POW is enough/correct
|
||||||
logger.info('Attempting to save block %s...' % blockHash[:12])
|
logger.info('Attempting to save block %s...' % blockHash[:12])
|
||||||
try:
|
try:
|
||||||
@ -85,7 +85,7 @@ def download_blocks_from_communicator(comm_inst):
|
|||||||
removeFromQueue = False
|
removeFromQueue = False
|
||||||
else:
|
else:
|
||||||
comm_inst._core.addToBlockDB(blockHash, dataSaved=True)
|
comm_inst._core.addToBlockDB(blockHash, dataSaved=True)
|
||||||
blockmetadata.process_block_metadata(blockHash) # caches block metadata values to block database
|
blockmetadata.process_block_metadata(comm_inst._core, blockHash) # caches block metadata values to block database
|
||||||
else:
|
else:
|
||||||
logger.warn('POW failed for block %s.' % blockHash)
|
logger.warn('POW failed for block %s.' % blockHash)
|
||||||
else:
|
else:
|
||||||
|
@ -42,7 +42,7 @@ def upload_blocks_from_communicator(comm_inst):
|
|||||||
url = 'http://' + peer + '/upload'
|
url = 'http://' + peer + '/upload'
|
||||||
data = {'block': block.Block(bl).getRaw()}
|
data = {'block': block.Block(bl).getRaw()}
|
||||||
proxyType = proxypicker.pick_proxy(peer)
|
proxyType = proxypicker.pick_proxy(peer)
|
||||||
logger.info("Uploading block to " + peer)
|
logger.info("Uploading block to " + peer, terminal=True)
|
||||||
if not basicrequests.do_post_request(core, url, data=data, proxyType=proxyType) == False:
|
if not basicrequests.do_post_request(core, url, data=data, proxyType=proxyType) == False:
|
||||||
localcommand.local_command(core, 'waitforshare/' + bl, post=True)
|
localcommand.local_command(core, 'waitforshare/' + bl, post=True)
|
||||||
finishedUploads.append(bl)
|
finishedUploads.append(bl)
|
||||||
|
@ -306,7 +306,7 @@ class Core:
|
|||||||
dateClaimed - timestamp claimed inside the block, only as trustworthy as the block author is
|
dateClaimed - timestamp claimed inside the block, only as trustworthy as the block author is
|
||||||
expire - expire date for a block
|
expire - expire date for a block
|
||||||
'''
|
'''
|
||||||
return coredb.blockmetadb.updateblockinfo
|
return coredb.blockmetadb.updateblockinfo.update_block_info(self, hash, key, data)
|
||||||
|
|
||||||
def insertBlock(self, data, header='txt', sign=False, encryptType='', symKey='', asymPeer='', meta = {}, expire=None, disableForward=False):
|
def insertBlock(self, data, header='txt', sign=False, encryptType='', symKey='', asymPeer='', meta = {}, expire=None, disableForward=False):
|
||||||
'''
|
'''
|
||||||
@ -437,8 +437,11 @@ class Core:
|
|||||||
else:
|
else:
|
||||||
# Tell the api server through localCommand to wait for the daemon to upload this block to make statistical analysis more difficult
|
# Tell the api server through localCommand to wait for the daemon to upload this block to make statistical analysis more difficult
|
||||||
if localcommand.local_command(self, '/ping', maxWait=10) == 'pong!':
|
if localcommand.local_command(self, '/ping', maxWait=10) == 'pong!':
|
||||||
|
if self.config.get('general.security_level', 1) > 0:
|
||||||
localcommand.local_command(self, '/waitforshare/' + retData, post=True, maxWait=5)
|
localcommand.local_command(self, '/waitforshare/' + retData, post=True, maxWait=5)
|
||||||
self.daemonQueueAdd('uploadBlock', retData)
|
self.daemonQueueAdd('uploadBlock', retData)
|
||||||
|
else:
|
||||||
|
print('shite', localcommand.local_command(self, '/ping', maxWait=10))
|
||||||
self.addToBlockDB(retData, selfInsert=True, dataSaved=True)
|
self.addToBlockDB(retData, selfInsert=True, dataSaved=True)
|
||||||
blockmetadata.process_block_metadata(self, retData)
|
blockmetadata.process_block_metadata(self, retData)
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ import base64
|
|||||||
from flask import Response
|
from flask import Response
|
||||||
import logger
|
import logger
|
||||||
from etc import onionrvalues
|
from etc import onionrvalues
|
||||||
from onionrutils import stringvalidators
|
from onionrutils import stringvalidators, bytesconverter
|
||||||
|
|
||||||
def handle_announce(clientAPI, request):
|
def handle_announce(clientAPI, request):
|
||||||
'''
|
'''
|
||||||
@ -53,7 +53,7 @@ def handle_announce(clientAPI, request):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
if powHash.startswith('0' * onionrvalues.OnionrValues().announce_pow):
|
if powHash.startswith('0' * onionrvalues.OnionrValues().announce_pow):
|
||||||
newNode = clientAPI._core._utils.bytesToStr(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._core.onionrInst.communicatorInst.newPeers:
|
||||||
clientAPI._core.onionrInst.communicatorInst.newPeers.append(newNode)
|
clientAPI._core.onionrInst.communicatorInst.newPeers.append(newNode)
|
||||||
resp = 'Success'
|
resp = 'Success'
|
||||||
|
@ -131,7 +131,7 @@ def raw(data, fd = sys.stdout, terminal = False):
|
|||||||
Outputs raw data to console without formatting
|
Outputs raw data to console without formatting
|
||||||
'''
|
'''
|
||||||
|
|
||||||
if terminal and (get_settings() & OUTPUT_TO_CONSOLE):
|
if (get_settings() & OUTPUT_TO_CONSOLE):
|
||||||
try:
|
try:
|
||||||
ts = fd.write('%s\n' % data)
|
ts = fd.write('%s\n' % data)
|
||||||
except OSError:
|
except OSError:
|
||||||
|
@ -43,7 +43,6 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
raise Exception("You need the PySocks module (for use with socks5 proxy to use Tor)")
|
raise Exception("You need the PySocks module (for use with socks5 proxy to use Tor)")
|
||||||
|
|
||||||
|
|
||||||
class Onionr:
|
class Onionr:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
'''
|
'''
|
||||||
|
@ -60,7 +60,7 @@ def daemon(o_inst):
|
|||||||
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.onionrCore.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():
|
||||||
|
@ -43,6 +43,7 @@ def process_block_metadata(core_inst, blockHash):
|
|||||||
myBlock.decrypt()
|
myBlock.decrypt()
|
||||||
if (myBlock.isEncrypted and myBlock.decrypted) or (not myBlock.isEncrypted):
|
if (myBlock.isEncrypted and myBlock.decrypted) or (not myBlock.isEncrypted):
|
||||||
blockType = myBlock.getMetadata('type') # we would use myBlock.getType() here, but it is bugged with encrypted blocks
|
blockType = myBlock.getMetadata('type') # we would use myBlock.getType() here, but it is bugged with encrypted blocks
|
||||||
|
print('blockType', blockType)
|
||||||
signer = bytesconverter.bytes_to_str(myBlock.signer)
|
signer = bytesconverter.bytes_to_str(myBlock.signer)
|
||||||
valid = myBlock.verifySig()
|
valid = myBlock.verifySig()
|
||||||
if myBlock.getMetadata('newFSKey') is not None:
|
if myBlock.getMetadata('newFSKey') is not None:
|
||||||
|
@ -19,11 +19,12 @@ def local_command(core_inst, command, data='', silent = True, post=False, postDa
|
|||||||
if data != '':
|
if data != '':
|
||||||
data = '&data=' + urllib.parse.quote_plus(data)
|
data = '&data=' + urllib.parse.quote_plus(data)
|
||||||
payload = 'http://%s/%s%s' % (hostname, command, data)
|
payload = 'http://%s/%s%s' % (hostname, command, data)
|
||||||
|
print(payload)
|
||||||
try:
|
try:
|
||||||
if post:
|
if post:
|
||||||
retData = requests.post(payload, data=postData, headers={'token': config.get('client.webpassword'), 'Connection':'close'}, timeout=(maxWait, maxWait)).text
|
retData = requests.post(payload, data=postData, headers={'token': core_inst.config.get('client.webpassword'), 'Connection':'close'}, timeout=(maxWait, maxWait)).text
|
||||||
else:
|
else:
|
||||||
retData = requests.get(payload, headers={'token': config.get('client.webpassword'), 'Connection':'close'}, timeout=(maxWait, maxWait)).text
|
retData = requests.get(payload, headers={'token': core_inst.config.get('client.webpassword'), 'Connection':'close'}, timeout=(maxWait, maxWait)).text
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
if not silent:
|
if not silent:
|
||||||
logger.error('Failed to make local request (command: %s):%s' % (command, error), terminal=True)
|
logger.error('Failed to make local request (command: %s):%s' % (command, error), terminal=True)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
import logger, onionrexceptions
|
import logger, onionrexceptions
|
||||||
from etc import onionrvalues
|
from etc import onionrvalues
|
||||||
from onionrutils import stringvalidators, epoch
|
from onionrutils import stringvalidators, epoch, bytesconverter
|
||||||
def validate_metadata(core_inst, metadata, blockData):
|
def validate_metadata(core_inst, metadata, blockData):
|
||||||
'''Validate metadata meets onionr spec (does not validate proof value computation), take in either dictionary or json string'''
|
'''Validate metadata meets onionr spec (does not validate proof value computation), take in either dictionary or json string'''
|
||||||
# TODO, make this check sane sizes
|
# TODO, make this check sane sizes
|
||||||
@ -59,7 +59,7 @@ def validate_metadata(core_inst, metadata, blockData):
|
|||||||
else:
|
else:
|
||||||
# if metadata loop gets no errors, it does not break, therefore metadata is valid
|
# if metadata loop gets no errors, it does not break, therefore metadata is valid
|
||||||
# make sure we do not have another block with the same data content (prevent data duplication and replay attacks)
|
# make sure we do not have another block with the same data content (prevent data duplication and replay attacks)
|
||||||
nonce = core_inst._utils.bytesToStr(core_inst._crypto.sha3Hash(blockData))
|
nonce = bytesconverter.bytes_to_str(core_inst._crypto.sha3Hash(blockData))
|
||||||
try:
|
try:
|
||||||
with open(core_inst.dataNonceFile, 'r') as nonceFile:
|
with open(core_inst.dataNonceFile, 'r') as nonceFile:
|
||||||
if nonce in nonceFile.read():
|
if nonce in nonceFile.read():
|
||||||
|
@ -23,7 +23,7 @@ import logger, config, threading, time, datetime
|
|||||||
from onionrblockapi import Block
|
from onionrblockapi import Block
|
||||||
import onionrexceptions
|
import onionrexceptions
|
||||||
from onionrusers import onionrusers
|
from onionrusers import onionrusers
|
||||||
from onionrutils import stringvalidators, escapeansi
|
from onionrutils import stringvalidators, escapeansi, bytesconverter
|
||||||
import locale, sys, os, json
|
import locale, sys, os, json
|
||||||
|
|
||||||
locale.setlocale(locale.LC_ALL, '')
|
locale.setlocale(locale.LC_ALL, '')
|
||||||
@ -136,7 +136,7 @@ class OnionrMail:
|
|||||||
else:
|
else:
|
||||||
cancel = ''
|
cancel = ''
|
||||||
readBlock.verifySig()
|
readBlock.verifySig()
|
||||||
senderDisplay = self.myCore._utils.bytesToStr(readBlock.signer)
|
senderDisplay = bytesconverter.bytes_to_str(readBlock.signer)
|
||||||
if len(senderDisplay.strip()) == 0:
|
if len(senderDisplay.strip()) == 0:
|
||||||
senderDisplay = 'Anonymous'
|
senderDisplay = 'Anonymous'
|
||||||
logger.info('Message received from %s' % (senderDisplay,), terminal=True)
|
logger.info('Message received from %s' % (senderDisplay,), terminal=True)
|
||||||
@ -156,7 +156,7 @@ class OnionrMail:
|
|||||||
reply = logger.readline("Press enter to continue, or enter %s to reply" % ("-r",))
|
reply = logger.readline("Press enter to continue, or enter %s to reply" % ("-r",))
|
||||||
print('')
|
print('')
|
||||||
if reply == "-r":
|
if reply == "-r":
|
||||||
self.draft_message(self.myCore._utils.bytesToStr(readBlock.signer,))
|
self.draft_message(bytesconverter.bytes_to_str(readBlock.signer,))
|
||||||
else:
|
else:
|
||||||
logger.readline("Press enter to continue")
|
logger.readline("Press enter to continue")
|
||||||
print('')
|
print('')
|
||||||
@ -200,7 +200,7 @@ class OnionrMail:
|
|||||||
self.sentMessages = {}
|
self.sentMessages = {}
|
||||||
for i in self.sentboxTools.listSent():
|
for i in self.sentboxTools.listSent():
|
||||||
self.sentboxList.append(i['hash'])
|
self.sentboxList.append(i['hash'])
|
||||||
self.sentMessages[i['hash']] = (self.myCore._utils.bytesToStr(i['message']), i['peer'], i['subject'])
|
self.sentMessages[i['hash']] = (bytesconverter.bytes_to_str(i['message']), i['peer'], i['subject'])
|
||||||
if display:
|
if display:
|
||||||
logger.info('%s. %s - %s - (%s) - %s' % (count, i['hash'], i['peer'][:12], i['subject'], i['date']), terminal=True)
|
logger.info('%s. %s - %s - (%s) - %s' % (count, i['hash'], i['peer'][:12], i['subject'], i['date']), terminal=True)
|
||||||
count += 1
|
count += 1
|
||||||
|
Loading…
Reference in New Issue
Block a user