Finished removing onionrutils for the most part, except for some possible bugs remaining
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
|
||||
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
|
||||
logger.info('Block passed proof, saving.', terminal=True)
|
||||
try:
|
||||
|
@ -46,6 +46,6 @@ def importBlockFromData(content, coreInst):
|
|||
pass
|
||||
else:
|
||||
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
|
||||
return retData
|
|
@ -20,7 +20,7 @@
|
|||
import base64
|
||||
import onionrproofs, logger
|
||||
from etc import onionrvalues
|
||||
from onionrutils import basicrequests
|
||||
from onionrutils import basicrequests, bytesconverter
|
||||
|
||||
def announce_node(daemon):
|
||||
'''Announce our node to our peers'''
|
||||
|
@ -53,7 +53,7 @@ def announce_node(daemon):
|
|||
combinedNodes = ourID + peer
|
||||
if ourID != 1:
|
||||
#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
|
||||
if type(existingRand) is type(None) or not existingRand.endswith('0' * ov.announce_pow):
|
||||
existingRand = ''
|
||||
|
|
|
@ -75,7 +75,7 @@ def download_blocks_from_communicator(comm_inst):
|
|||
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
|
||||
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
|
||||
logger.info('Attempting to save block %s...' % blockHash[:12])
|
||||
try:
|
||||
|
@ -85,7 +85,7 @@ def download_blocks_from_communicator(comm_inst):
|
|||
removeFromQueue = False
|
||||
else:
|
||||
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:
|
||||
logger.warn('POW failed for block %s.' % blockHash)
|
||||
else:
|
||||
|
|
|
@ -42,7 +42,7 @@ def upload_blocks_from_communicator(comm_inst):
|
|||
url = 'http://' + peer + '/upload'
|
||||
data = {'block': block.Block(bl).getRaw()}
|
||||
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:
|
||||
localcommand.local_command(core, 'waitforshare/' + bl, post=True)
|
||||
finishedUploads.append(bl)
|
||||
|
|
|
@ -306,7 +306,7 @@ class Core:
|
|||
dateClaimed - timestamp claimed inside the block, only as trustworthy as the block author is
|
||||
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):
|
||||
'''
|
||||
|
@ -437,8 +437,11 @@ class Core:
|
|||
else:
|
||||
# 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 self.config.get('general.security_level', 1) > 0:
|
||||
localcommand.local_command(self, '/waitforshare/' + retData, post=True, maxWait=5)
|
||||
self.daemonQueueAdd('uploadBlock', retData)
|
||||
else:
|
||||
print('shite', localcommand.local_command(self, '/ping', maxWait=10))
|
||||
self.addToBlockDB(retData, selfInsert=True, dataSaved=True)
|
||||
blockmetadata.process_block_metadata(self, retData)
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ import base64
|
|||
from flask import Response
|
||||
import logger
|
||||
from etc import onionrvalues
|
||||
from onionrutils import stringvalidators
|
||||
from onionrutils import stringvalidators, bytesconverter
|
||||
|
||||
def handle_announce(clientAPI, request):
|
||||
'''
|
||||
|
@ -53,7 +53,7 @@ def handle_announce(clientAPI, request):
|
|||
except AttributeError:
|
||||
pass
|
||||
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:
|
||||
clientAPI._core.onionrInst.communicatorInst.newPeers.append(newNode)
|
||||
resp = 'Success'
|
||||
|
|
|
@ -131,7 +131,7 @@ def raw(data, fd = sys.stdout, terminal = False):
|
|||
Outputs raw data to console without formatting
|
||||
'''
|
||||
|
||||
if terminal and (get_settings() & OUTPUT_TO_CONSOLE):
|
||||
if (get_settings() & OUTPUT_TO_CONSOLE):
|
||||
try:
|
||||
ts = fd.write('%s\n' % data)
|
||||
except OSError:
|
||||
|
|
|
@ -43,7 +43,6 @@ try:
|
|||
except ImportError:
|
||||
raise Exception("You need the PySocks module (for use with socks5 proxy to use Tor)")
|
||||
|
||||
|
||||
class Onionr:
|
||||
def __init__(self):
|
||||
'''
|
||||
|
|
|
@ -60,7 +60,7 @@ def daemon(o_inst):
|
|||
logger.debug('Python version %s' % platform.python_version())
|
||||
|
||||
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)
|
||||
logger.info('Tor is starting...', terminal=True)
|
||||
if not net.startTor():
|
||||
|
|
|
@ -43,6 +43,7 @@ def process_block_metadata(core_inst, blockHash):
|
|||
myBlock.decrypt()
|
||||
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
|
||||
print('blockType', blockType)
|
||||
signer = bytesconverter.bytes_to_str(myBlock.signer)
|
||||
valid = myBlock.verifySig()
|
||||
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 != '':
|
||||
data = '&data=' + urllib.parse.quote_plus(data)
|
||||
payload = 'http://%s/%s%s' % (hostname, command, data)
|
||||
print(payload)
|
||||
try:
|
||||
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:
|
||||
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:
|
||||
if not silent:
|
||||
logger.error('Failed to make local request (command: %s):%s' % (command, error), terminal=True)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import json
|
||||
import logger, onionrexceptions
|
||||
from etc import onionrvalues
|
||||
from onionrutils import stringvalidators, epoch
|
||||
from onionrutils import stringvalidators, epoch, bytesconverter
|
||||
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'''
|
||||
# TODO, make this check sane sizes
|
||||
|
@ -59,7 +59,7 @@ def validate_metadata(core_inst, metadata, blockData):
|
|||
else:
|
||||
# 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)
|
||||
nonce = core_inst._utils.bytesToStr(core_inst._crypto.sha3Hash(blockData))
|
||||
nonce = bytesconverter.bytes_to_str(core_inst._crypto.sha3Hash(blockData))
|
||||
try:
|
||||
with open(core_inst.dataNonceFile, 'r') as nonceFile:
|
||||
if nonce in nonceFile.read():
|
||||
|
|
|
@ -23,7 +23,7 @@ import logger, config, threading, time, datetime
|
|||
from onionrblockapi import Block
|
||||
import onionrexceptions
|
||||
from onionrusers import onionrusers
|
||||
from onionrutils import stringvalidators, escapeansi
|
||||
from onionrutils import stringvalidators, escapeansi, bytesconverter
|
||||
import locale, sys, os, json
|
||||
|
||||
locale.setlocale(locale.LC_ALL, '')
|
||||
|
@ -136,7 +136,7 @@ class OnionrMail:
|
|||
else:
|
||||
cancel = ''
|
||||
readBlock.verifySig()
|
||||
senderDisplay = self.myCore._utils.bytesToStr(readBlock.signer)
|
||||
senderDisplay = bytesconverter.bytes_to_str(readBlock.signer)
|
||||
if len(senderDisplay.strip()) == 0:
|
||||
senderDisplay = 'Anonymous'
|
||||
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",))
|
||||
print('')
|
||||
if reply == "-r":
|
||||
self.draft_message(self.myCore._utils.bytesToStr(readBlock.signer,))
|
||||
self.draft_message(bytesconverter.bytes_to_str(readBlock.signer,))
|
||||
else:
|
||||
logger.readline("Press enter to continue")
|
||||
print('')
|
||||
|
@ -200,7 +200,7 @@ class OnionrMail:
|
|||
self.sentMessages = {}
|
||||
for i in self.sentboxTools.listSent():
|
||||
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:
|
||||
logger.info('%s. %s - %s - (%s) - %s' % (count, i['hash'], i['peer'][:12], i['subject'], i['date']), terminal=True)
|
||||
count += 1
|
||||
|
|
Loading…
Reference in New Issue