fixed importer
This commit is contained in:
parent
4bbbff7651
commit
faf85c10d2
@ -11,6 +11,7 @@ bootstrap_file_location = 'static-data/bootstrap-nodes.txt'
|
|||||||
data_nonce_file = home + 'block-nonces.dat'
|
data_nonce_file = home + 'block-nonces.dat'
|
||||||
forward_keys_file = home + 'forward-keys.db'
|
forward_keys_file = home + 'forward-keys.db'
|
||||||
cached_storage = home + 'cachedstorage.dat'
|
cached_storage = home + 'cachedstorage.dat'
|
||||||
|
export_location = home + 'block-export/'
|
||||||
|
|
||||||
tor_hs_address_file = home + 'hs/hostname'
|
tor_hs_address_file = home + 'hs/hostname'
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ import netcontroller
|
|||||||
from onionrblockapi import Block
|
from onionrblockapi import Block
|
||||||
import onionrexceptions, communicator, setupconfig
|
import onionrexceptions, communicator, setupconfig
|
||||||
import onionrcommands as commands # Many command definitions are here
|
import onionrcommands as commands # Many command definitions are here
|
||||||
from utils import identifyhome
|
from utils import identifyhome, hastor
|
||||||
from coredb import keydb
|
from coredb import keydb
|
||||||
import filepaths
|
import filepaths
|
||||||
|
|
||||||
@ -77,10 +77,6 @@ class Onionr:
|
|||||||
# Load global configuration data
|
# Load global configuration data
|
||||||
data_exists = Onionr.setupConfig(self)
|
data_exists = Onionr.setupConfig(self)
|
||||||
|
|
||||||
if netcontroller.tor_binary() is None:
|
|
||||||
logger.error('Tor is not installed', terminal=True)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
# If block data folder does not exist
|
# If block data folder does not exist
|
||||||
if not os.path.exists(self.dataDir + 'blocks/'):
|
if not os.path.exists(self.dataDir + 'blocks/'):
|
||||||
os.mkdir(self.dataDir + 'blocks/')
|
os.mkdir(self.dataDir + 'blocks/')
|
||||||
|
@ -27,6 +27,8 @@ from onionrutils import localcommand
|
|||||||
import filepaths
|
import filepaths
|
||||||
from coredb import daemonqueue
|
from coredb import daemonqueue
|
||||||
from onionrcrypto import getourkeypair
|
from onionrcrypto import getourkeypair
|
||||||
|
from utils import hastor
|
||||||
|
|
||||||
def _proper_shutdown(o_inst):
|
def _proper_shutdown(o_inst):
|
||||||
localcommand.local_command('shutdown')
|
localcommand.local_command('shutdown')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@ -35,6 +37,9 @@ def daemon(o_inst):
|
|||||||
'''
|
'''
|
||||||
Starts the Onionr communication daemon
|
Starts the Onionr communication daemon
|
||||||
'''
|
'''
|
||||||
|
if not hastor.has_tor():
|
||||||
|
logger.error("Tor is not present in system path or Onionr directory", terminal=True)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
# remove runcheck if it exists
|
# remove runcheck if it exists
|
||||||
if os.path.isfile(filepaths.run_check_file):
|
if os.path.isfile(filepaths.run_check_file):
|
||||||
|
@ -19,21 +19,18 @@
|
|||||||
'''
|
'''
|
||||||
import sys, os
|
import sys, os
|
||||||
import logger, onionrstorage
|
import logger, onionrstorage
|
||||||
|
from utils import createdirs
|
||||||
from onionrutils import stringvalidators
|
from onionrutils import stringvalidators
|
||||||
|
import filepaths
|
||||||
def doExport(o_inst, bHash):
|
def doExport(o_inst, bHash):
|
||||||
exportDir = o_inst.dataDir + 'block-export/'
|
createdirs.create_dirs()
|
||||||
if not os.path.exists(exportDir):
|
data = onionrstorage.getData(bHash)
|
||||||
if os.path.exists(o_inst.dataDir):
|
with open('%s/%s.dat' % (filepaths.export_location, bHash), 'wb') as exportFile:
|
||||||
os.mkdir(exportDir)
|
|
||||||
else:
|
|
||||||
logger.error('Onionr Not initialized', terminal=True)
|
|
||||||
data = onionrstorage.getData(o_inst.onionrCore, bHash)
|
|
||||||
with open('%s/%s.dat' % (exportDir, bHash), 'wb') as exportFile:
|
|
||||||
exportFile.write(data)
|
exportFile.write(data)
|
||||||
logger.info('Block exported as file', terminal=True)
|
logger.info('Block exported as file', terminal=True)
|
||||||
|
|
||||||
def export_block(o_inst):
|
def export_block(o_inst):
|
||||||
exportDir = o_inst.dataDir + 'block-export/'
|
exportDir = filepaths.export_location
|
||||||
try:
|
try:
|
||||||
assert stringvalidators.validate_hash(sys.argv[2])
|
assert stringvalidators.validate_hash(sys.argv[2])
|
||||||
except (IndexError, AssertionError):
|
except (IndexError, AssertionError):
|
||||||
|
@ -85,7 +85,7 @@ def process_block_metadata(blockHash):
|
|||||||
blockmetadb.update_block_info(blockHash, 'expire', expireTime)
|
blockmetadb.update_block_info(blockHash, 'expire', expireTime)
|
||||||
if not blockType is None:
|
if not blockType is None:
|
||||||
blockmetadb.update_block_info(blockHash, 'dataType', blockType)
|
blockmetadb.update_block_info(blockHash, 'dataType', blockType)
|
||||||
#onionrevents.event('processblocks', data = {'block': myBlock, 'type': blockType, 'signer': signer, 'validSig': valid}, onionr = core_inst.onionrInst)
|
onionrevents.event('processblocks', data = {'block': myBlock, 'type': blockType, 'signer': signer, 'validSig': valid})
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -21,12 +21,12 @@ import glob
|
|||||||
import logger
|
import logger
|
||||||
from onionrutils import blockmetadata
|
from onionrutils import blockmetadata
|
||||||
from coredb import blockmetadb
|
from coredb import blockmetadb
|
||||||
import filepaths, onionrcrypto
|
import filepaths
|
||||||
|
import onionrcrypto as crypto
|
||||||
def import_new_blocks(scanDir=''):
|
def import_new_blocks(scanDir=''):
|
||||||
'''
|
'''
|
||||||
This function is intended to scan for new blocks ON THE DISK and import them
|
This function is intended to scan for new blocks ON THE DISK and import them
|
||||||
'''
|
'''
|
||||||
crypto = onionrcrypto.OnionrCrypto()
|
|
||||||
blockList = blockmetadb.get_block_list()
|
blockList = blockmetadb.get_block_list()
|
||||||
exist = False
|
exist = False
|
||||||
if scanDir == '':
|
if scanDir == '':
|
||||||
@ -39,7 +39,7 @@ def import_new_blocks(scanDir=''):
|
|||||||
logger.info('Found new block on dist %s' % block, terminal=True)
|
logger.info('Found new block on dist %s' % block, terminal=True)
|
||||||
with open(block, 'rb') as newBlock:
|
with open(block, 'rb') as newBlock:
|
||||||
block = block.replace(scanDir, '').replace('.dat', '')
|
block = block.replace(scanDir, '').replace('.dat', '')
|
||||||
if crypto.sha3Hash(newBlock.read()) == block.replace('.dat', ''):
|
if crypto.hashers.sha3_hash(newBlock.read()) == block.replace('.dat', ''):
|
||||||
blockmetadb.add_to_block_DB(block.replace('.dat', ''), dataSaved=True)
|
blockmetadb.add_to_block_DB(block.replace('.dat', ''), dataSaved=True)
|
||||||
logger.info('Imported block %s.' % block, terminal=True)
|
logger.info('Imported block %s.' % block, terminal=True)
|
||||||
blockmetadata.process_block_metadata(block)
|
blockmetadata.process_block_metadata(block)
|
||||||
|
@ -4,12 +4,10 @@ import dbcreator, filepaths
|
|||||||
home = identifyhome.identify_home()
|
home = identifyhome.identify_home()
|
||||||
|
|
||||||
def create_dirs():
|
def create_dirs():
|
||||||
if not os.path.exists(home):
|
gen_dirs = [home, filepaths.block_data_location, filepaths.contacts_location, filepaths.export_location]
|
||||||
os.mkdir(home)
|
for path in gen_dirs:
|
||||||
if not os.path.exists(filepaths.block_data_location):
|
if not os.path.exists(path):
|
||||||
os.mkdir(filepaths.block_data_location)
|
os.mkdir(path)
|
||||||
if not os.path.exists(filepaths.contacts_location):
|
|
||||||
os.mkdir(filepaths.contacts_location)
|
|
||||||
|
|
||||||
for db in dbcreator.create_funcs:
|
for db in dbcreator.create_funcs:
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user