renamed old block api due to namespace conflict

fix onboarding not using optimize cpu option
This commit is contained in:
Kevin Froman 2021-01-17 04:58:28 +00:00
parent 9e2d374270
commit a3ce191ed3
70 changed files with 118 additions and 96 deletions

View File

@ -2,5 +2,5 @@ Blockio wraps safedb, the new key value database module
This is how the keys are setup and what they are for: This is how the keys are setup and what they are for:
bl-{type}: list of hashes for blocks for every stored block type bl-{type}: bytes of hashes for each block type
{block hash}: block data {block hash}: block data

View File

@ -11,7 +11,7 @@ import os
if not os.path.exists('onionr.sh'): if not os.path.exists('onionr.sh'):
os.chdir('../') os.chdir('../')
sys.path.append("src/") sys.path.append("src/")
import onionrblocks import oldblocks
amount = int(input("Number of blocks:")) amount = int(input("Number of blocks:"))
@ -24,8 +24,8 @@ else:
for i in range(amount): for i in range(amount):
if expire: if expire:
print(onionrblocks.insert(data=os.urandom(32), expire=expire)) print(oldblocks.insert(data=os.urandom(32), expire=expire))
else: else:
print(onionrblocks.insert(data=os.urandom(32))) print(oldblocks.insert(data=os.urandom(32)))
print(i, "done") print(i, "done")

View File

@ -6,7 +6,7 @@ if not os.path.exists('onionr.sh'):
os.chdir('../') os.chdir('../')
sys.path.append("src/") sys.path.append("src/")
from coredb.blockmetadb import get_block_list from coredb.blockmetadb import get_block_list
from onionrblocks.onionrblockapi import Block from oldblocks.onionrblockapi import Block
for bl in get_block_list(): for bl in get_block_list():
bl_obj = Block(bl, decrypt=False) bl_obj = Block(bl, decrypt=False)

View File

@ -5,8 +5,8 @@ import os
if not os.path.exists('onionr.sh'): if not os.path.exists('onionr.sh'):
os.chdir('../') os.chdir('../')
sys.path.append("src/") sys.path.append("src/")
import onionrblocks import oldblocks
expire = 600 expire = 600
print(onionrblocks.insert(data=os.urandom(32), expire=expire)) print(oldblocks.insert(data=os.urandom(32), expire=expire))

View File

@ -70,7 +70,7 @@ createdirs.create_dirs()
import bigbrother # noqa import bigbrother # noqa
from onionrcommands import parser # noqa from onionrcommands import parser # noqa
from onionrplugins import onionrevents as events # noqa from onionrplugins import onionrevents as events # noqa
from onionrblocks.deleteplaintext import delete_plaintext_no_blacklist # noqa from oldblocks.deleteplaintext import delete_plaintext_no_blacklist # noqa
setup.setup_config() setup.setup_config()

View File

@ -2,7 +2,13 @@
Store blocks and cache meta info such as block type Store blocks and cache meta info such as block type
""" """
import safedb from typing import TYPE_CHECKING, Union, NewType
from safedb import DBProtectionOpeningModeError
if TYPE_CHECKING:
from kasten import Kasten
from safedb import SafeDB
""" """
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -18,9 +24,10 @@ 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/>.
""" """
RawBlock = NewType('RawBlock', bytes)
def store_block(block_data):
# If Onionr daemon is running, we should use the client def store_block(block: Kasten, safe_db: SafeDB):
# API server to store blocks, if not we can
safe_db.put(block.id, block.get_packed())

View File

@ -5,7 +5,7 @@ Use the communicator to insert fake mail messages
import secrets import secrets
from etc import onionrvalues from etc import onionrvalues
import onionrblocks import oldblocks
""" """
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -30,6 +30,6 @@ def insert_deniable_block():
# This assumes on the libsodium primitives to have key-privacy # This assumes on the libsodium primitives to have key-privacy
fakePeer = onionrvalues.DENIABLE_PEER_ADDRESS fakePeer = onionrvalues.DENIABLE_PEER_ADDRESS
data = secrets.token_hex(secrets.randbelow(5120) + 1) data = secrets.token_hex(secrets.randbelow(5120) + 1)
onionrblocks.insert(data, header='pm', encryptType='asym', oldblocks.insert(data, header='pm', encryptType='asym',
asymPeer=fakePeer, disableForward=True, asymPeer=fakePeer, disableForward=True,
meta={'subject': 'foo'}) meta={'subject': 'foo'})

View File

@ -17,14 +17,14 @@ import onionrpeers
from communicator import peeraction from communicator import peeraction
from communicator import onlinepeers from communicator import onlinepeers
from onionrblocks import blockmetadata from oldblocks import blockmetadata
from onionrutils import validatemetadata from onionrutils import validatemetadata
from coredb import blockmetadb from coredb import blockmetadb
from onionrutils.localcommand import local_command from onionrutils.localcommand import local_command
import onionrcrypto import onionrcrypto
import onionrstorage import onionrstorage
from onionrblocks import onionrblacklist from oldblocks import onionrblacklist
from onionrblocks import storagecounter from oldblocks import storagecounter
from . import shoulddownload from . import shoulddownload
""" """
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify

View File

@ -4,7 +4,7 @@ Check if a block should be downloaded
(if we already have it or its blacklisted or not) (if we already have it or its blacklisted or not)
""" """
from coredb import blockmetadb from coredb import blockmetadb
from onionrblocks import onionrblacklist from oldblocks import onionrblacklist
""" """
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by

View File

@ -15,8 +15,8 @@ from onionrutils import epoch
from coredb import blockmetadb, dbfiles from coredb import blockmetadb, dbfiles
import onionrstorage import onionrstorage
from onionrstorage import removeblock from onionrstorage import removeblock
from onionrblocks import onionrblacklist from oldblocks import onionrblacklist
from onionrblocks.storagecounter import StorageCounter from oldblocks.storagecounter import StorageCounter
from etc.onionrvalues import DATABASE_LOCK_TIMEOUT from etc.onionrvalues import DATABASE_LOCK_TIMEOUT
from onionrproofs import hashMeetsDifficulty from onionrproofs import hashMeetsDifficulty
""" """
@ -103,6 +103,6 @@ def clean_blocks_not_meeting_pow(shared_state):
for block in block_list: for block in block_list:
if not hashMeetsDifficulty(block): if not hashMeetsDifficulty(block):
logger.warn( logger.warn(
f"Deleting block {block} because it was stored" + f"Deleting block {block} because it was stored" +
"with a POW level smaller than current.", terminal=True) "with a POW level smaller than current.", terminal=True)
__purge_block(shared_state, block) __purge_block(shared_state, block)

View File

@ -15,11 +15,11 @@ from onionrutils import stringvalidators, epoch
from communicator import peeraction, onlinepeers from communicator import peeraction, onlinepeers
from coredb.blockmetadb import get_block_list from coredb.blockmetadb import get_block_list
from utils import reconstructhash from utils import reconstructhash
from onionrblocks import onionrblacklist from oldblocks import onionrblacklist
import onionrexceptions import onionrexceptions
import config import config
from etc import onionrvalues from etc import onionrvalues
from onionrblocks.storagecounter import StorageCounter from oldblocks.storagecounter import StorageCounter
""" """
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by

View File

@ -13,8 +13,8 @@ from onionrtypes import UserID
import logger import logger
from communicatorutils import proxypicker from communicatorutils import proxypicker
import onionrexceptions import onionrexceptions
from onionrblocks import onionrblockapi as block from oldblocks import onionrblockapi as block
from onionrblocks.blockmetadata.fromdata import get_block_metadata_from_data from oldblocks.blockmetadata.fromdata import get_block_metadata_from_data
from onionrutils import stringvalidators, basicrequests from onionrutils import stringvalidators, basicrequests
from onionrutils.validatemetadata import validate_metadata from onionrutils.validatemetadata import validate_metadata
from communicator import onlinepeers from communicator import onlinepeers

View File

@ -6,7 +6,7 @@ import time
from typing import List from typing import List
import onionrtypes import onionrtypes
from onionrblocks import onionrblockapi from oldblocks import onionrblockapi
from .pool import UploadPool from .pool import UploadPool
from .pool import PoolFullException from .pool import PoolFullException

View File

@ -5,7 +5,7 @@ Add an entry to the block metadata database
import sqlite3 import sqlite3
import secrets import secrets
from onionrutils import epoch from onionrutils import epoch
from onionrblocks import blockmetadata from oldblocks import blockmetadata
from etc import onionrvalues from etc import onionrvalues
from .. import dbfiles from .. import dbfiles
from onionrexceptions import BlockMetaEntryExists from onionrexceptions import BlockMetaEntryExists

View File

@ -1,6 +1,6 @@
import ujson as json import ujson as json
from onionrblocks import onionrblockapi from oldblocks import onionrblockapi
from onionrutils import bytesconverter, stringvalidators from onionrutils import bytesconverter, stringvalidators
import onionrexceptions import onionrexceptions
class GetBlockData: class GetBlockData:

View File

@ -11,7 +11,7 @@ from flask import Blueprint, Response, request, g
if TYPE_CHECKING: if TYPE_CHECKING:
from deadsimplekv import DeadSimpleKV from deadsimplekv import DeadSimpleKV
import onionrblocks import oldblocks
from onionrcrypto import hashers from onionrcrypto import hashers
from onionrutils import bytesconverter from onionrutils import bytesconverter
from onionrutils import mnemonickeys from onionrutils import mnemonickeys
@ -84,7 +84,7 @@ def client_api_insert_block():
disable_forward_secrecy = False disable_forward_secrecy = False
threading.Thread( threading.Thread(
target=onionrblocks.insert, args=(message,), target=oldblocks.insert, args=(message,),
kwargs={'header': bType, 'encryptType': encrypt_type, kwargs={'header': bType, 'encryptType': encrypt_type,
'sign': sign, 'asymPeer': to, 'meta': meta, 'sign': sign, 'asymPeer': to, 'meta': meta,
'disableForward': disable_forward_secrecy}).start() 'disableForward': disable_forward_secrecy}).start()

View File

@ -18,7 +18,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
''' '''
from flask import Blueprint, Response, abort from flask import Blueprint, Response, abort
from onionrblocks import onionrblockapi from oldblocks import onionrblockapi
from .. import apiutils from .. import apiutils
from onionrutils import stringvalidators from onionrutils import stringvalidators
from coredb import blockmetadb from coredb import blockmetadb

View File

@ -3,7 +3,7 @@ from flask import Response
import unpaddedbase32 import unpaddedbase32
from coredb import blockmetadb from coredb import blockmetadb
import onionrblocks import oldblocks
from etc import onionrvalues from etc import onionrvalues
import config import config
from onionrutils import bytesconverter from onionrutils import bytesconverter
@ -18,7 +18,7 @@ def get_motd()->Response:
newest_time = 0 newest_time = 0
message = "No MOTD currently present." message = "No MOTD currently present."
for x in motds: for x in motds:
bl = onionrblocks.onionrblockapi.Block(x) bl = oldblocks.onionrblockapi.Block(x)
if not bl.verifySig() or bl.signer != bytesconverter.bytes_to_str(unpaddedbase32.repad(bytesconverter.str_to_bytes(signer))): continue if not bl.verifySig() or bl.signer != bytesconverter.bytes_to_str(unpaddedbase32.repad(bytesconverter.str_to_bytes(signer))): continue
if not bl.isSigner(signer): continue if not bl.isSigner(signer): continue
if bl.claimedTime > newest_time: if bl.claimedTime > newest_time:

View File

@ -8,8 +8,8 @@ import config
from onionrutils import bytesconverter, stringvalidators from onionrutils import bytesconverter, stringvalidators
from coredb import blockmetadb from coredb import blockmetadb
from utils import reconstructhash from utils import reconstructhash
from onionrblocks import BlockList from oldblocks import BlockList
from onionrblocks.onionrblockapi import Block from oldblocks.onionrblockapi import Block
from .. import apiutils from .. import apiutils
""" """
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify

View File

@ -10,7 +10,7 @@ from flask import abort
from flask import g from flask import g
from onionrutils import localcommand from onionrutils import localcommand
from onionrblocks import blockimporter from oldblocks import blockimporter
import onionrexceptions import onionrexceptions
import logger import logger
import config import config

View File

@ -10,7 +10,7 @@ import unpaddedbase32
from flask import Blueprint, Response, request, abort from flask import Blueprint, Response, request, abort
from onionrblocks import onionrblockapi from oldblocks import onionrblockapi
import onionrexceptions import onionrexceptions
from onionrutils import stringvalidators from onionrutils import stringvalidators
from onionrutils import mnemonickeys from onionrutils import mnemonickeys

View File

@ -10,7 +10,7 @@ import onionrexceptions
from onionrutils import mnemonickeys from onionrutils import mnemonickeys
from onionrutils import stringvalidators from onionrutils import stringvalidators
from coredb import blockmetadb from coredb import blockmetadb
from onionrblocks.onionrblockapi import Block from oldblocks.onionrblockapi import Block
from onionrtypes import BlockHash from onionrtypes import BlockHash
""" """

View File

@ -10,8 +10,8 @@ import os
import unpaddedbase32 import unpaddedbase32
from coredb import blockmetadb from coredb import blockmetadb
from onionrblocks import onionrblockapi from oldblocks import onionrblockapi
from onionrblocks import insert from oldblocks import insert
# Import types. Just for type hiting # Import types. Just for type hiting
from onionrtypes import UserID, DeterministicKeyPassphrase, BlockHash from onionrtypes import UserID, DeterministicKeyPassphrase, BlockHash

View File

@ -9,7 +9,7 @@ from gevent import sleep
import gevent import gevent
import ujson import ujson
from onionrblocks.onionrblockapi import Block from oldblocks.onionrblockapi import Block
from coredb.dbfiles import block_meta_db from coredb.dbfiles import block_meta_db
from coredb.blockmetadb import get_block_list from coredb.blockmetadb import get_block_list
from onionrutils.epoch import get_epoch from onionrutils.epoch import get_epoch

View File

@ -9,7 +9,7 @@ from typing import Set
from onionrtypes import LANIP from onionrtypes import LANIP
import logger import logger
from coredb.blockmetadb import get_block_list from coredb.blockmetadb import get_block_list
from onionrblocks.blockimporter import import_block_from_data from oldblocks.blockimporter import import_block_from_data
import onionrexceptions import onionrexceptions
from ..server import ports from ..server import ports
from onionrproofs import hashMeetsDifficulty from onionrproofs import hashMeetsDifficulty

View File

@ -12,7 +12,7 @@ from flask import Response
from flask import request from flask import request
from flask import abort from flask import abort
from onionrblocks.onionrblockapi import Block from oldblocks.onionrblockapi import Block
from httpapi.fdsafehandler import FDSafeHandler from httpapi.fdsafehandler import FDSafeHandler
from netcontroller import get_open_port from netcontroller import get_open_port
import config import config

View File

@ -10,7 +10,7 @@ import logger
from onionrutils import validatemetadata from onionrutils import validatemetadata
from onionrutils import bytesconverter from onionrutils import bytesconverter
from coredb import blockmetadb from coredb import blockmetadb
from onionrblocks import blockmetadata from oldblocks import blockmetadata
import onionrstorage import onionrstorage
import onionrcrypto as crypto import onionrcrypto as crypto
from . import onionrblacklist from . import onionrblacklist

View File

@ -3,7 +3,7 @@
Process block metadata with relevant actions Process block metadata with relevant actions
""" """
from etc import onionrvalues from etc import onionrvalues
from onionrblocks import onionrblockapi from oldblocks import onionrblockapi
from onionrutils import epoch, bytesconverter from onionrutils import epoch, bytesconverter
from coredb import blockmetadb from coredb import blockmetadb
import logger import logger

View File

@ -1,6 +1,6 @@
"""Onionr - P2P Anonymous Storage Network. """Onionr - P2P Anonymous Storage Network.
OnionrBlocks class for abstraction of blocks oldblocks class for abstraction of blocks
""" """
import datetime import datetime
import onionrstorage import onionrstorage
@ -15,7 +15,7 @@ from onionrusers import onionrusers
from onionrutils import stringvalidators, epoch from onionrutils import stringvalidators, epoch
from coredb import blockmetadb from coredb import blockmetadb
from onionrutils import bytesconverter from onionrutils import bytesconverter
import onionrblocks import oldblocks
from onionrcrypto import encryption, cryptoutils as cryptoutils, signing from onionrcrypto import encryption, cryptoutils as cryptoutils, signing
""" """
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify

View File

@ -7,7 +7,7 @@ import logger
from onionrutils import stringvalidators from onionrutils import stringvalidators
from onionrstorage import removeblock from onionrstorage import removeblock
from onionrstorage import deleteBlock from onionrstorage import deleteBlock
from onionrblocks import onionrblacklist from oldblocks import onionrblacklist
from utils import reconstructhash from utils import reconstructhash
""" """
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify

View File

@ -12,6 +12,7 @@ from communicatorutils import uploadblocks
from communicatorutils import announcenode, deniableinserts from communicatorutils import announcenode, deniableinserts
from communicatorutils import netcheck from communicatorutils import netcheck
import onionrpeers import onionrpeers
import config import config
if TYPE_CHECKING: if TYPE_CHECKING:

View File

@ -6,11 +6,11 @@ and getting files from the Onionr network
import sys import sys
import os import os
import logger import logger
from onionrblocks.onionrblockapi import Block from oldblocks.onionrblockapi import Block
import onionrexceptions import onionrexceptions
from onionrutils import stringvalidators from onionrutils import stringvalidators
from etc import onionrvalues from etc import onionrvalues
from onionrblocks import insert from oldblocks import insert
""" """
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
Dumb listing of Onionr sites Dumb listing of Onionr sites
""" """
from coredb.blockmetadb import get_blocks_by_type from coredb.blockmetadb import get_blocks_by_type
from onionrblocks.onionrblockapi import Block from oldblocks.onionrblockapi import Block
import logger import logger
""" """
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify

View File

@ -3,7 +3,7 @@
Command to make new network-wide MOTD message. Only network admin can do this Command to make new network-wide MOTD message. Only network admin can do this
The key is set in onionrvalues The key is set in onionrvalues
""" """
import onionrblocks import oldblocks
""" """
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -29,7 +29,7 @@ def motd_creator():
new = input() # nosec B323 new = input() # nosec B323
if new != 'quit': if new != 'quit':
motd += new motd += new
bl = onionrblocks.insert(motd, header='motd', sign=True) bl = oldblocks.insert(motd, header='motd', sign=True)
print(f"inserted in {bl}") print(f"inserted in {bl}")

View File

@ -4,7 +4,7 @@ This module defines commands to show stats/details about the local node
""" """
import os import os
import logger import logger
from onionrblocks import onionrblacklist from oldblocks import onionrblacklist
from onionrutils import mnemonickeys from onionrutils import mnemonickeys
from utils import sizeutils, gethostname, getconsolewidth, identifyhome from utils import sizeutils, gethostname, getconsolewidth, identifyhome
from coredb import blockmetadb, keydb from coredb import blockmetadb, keydb

View File

@ -21,7 +21,7 @@ import sqlite3
import logger import logger
from onionrutils import epoch from onionrutils import epoch
from . import scoresortedpeerlist, peerprofiles from . import scoresortedpeerlist, peerprofiles
from onionrblocks import onionrblacklist from oldblocks import onionrblacklist
import config import config
from coredb import keydb from coredb import keydb
def peer_cleanup(): def peer_cleanup():
@ -30,7 +30,7 @@ def peer_cleanup():
blacklist = onionrblacklist.OnionrBlackList() blacklist = onionrblacklist.OnionrBlackList()
adders = scoresortedpeerlist.get_score_sorted_peer_list() adders = scoresortedpeerlist.get_score_sorted_peer_list()
adders.reverse() adders.reverse()
if len(adders) > 1: if len(adders) > 1:
min_score = int(config.get('peers.minimum_score', -100)) min_score = int(config.get('peers.minimum_score', -100))

View File

@ -20,7 +20,7 @@
from coredb import keydb from coredb import keydb
from onionrutils import epoch from onionrutils import epoch
from onionrutils import stringvalidators from onionrutils import stringvalidators
from onionrblocks import onionrblacklist from oldblocks import onionrblacklist
import onionrexceptions import onionrexceptions
UPDATE_DELAY = 300 UPDATE_DELAY = 300
@ -42,7 +42,7 @@ class PeerProfiles:
self.getConnectTime() self.getConnectTime()
self.last_updated = {'connect_time': UPDATE_DELAY, 'score': UPDATE_DELAY} # Last time a given value was updated self.last_updated = {'connect_time': UPDATE_DELAY, 'score': UPDATE_DELAY} # Last time a given value was updated
if not address in keydb.listkeys.list_adders() and not onionrblacklist.OnionrBlackList().inBlacklist(address): if not address in keydb.listkeys.list_adders() and not onionrblacklist.OnionrBlackList().inBlacklist(address):
keydb.addkeys.add_address(address) keydb.addkeys.add_address(address)
@ -53,7 +53,7 @@ class PeerProfiles:
except (TypeError, ValueError) as e: except (TypeError, ValueError) as e:
self.success = 0 self.success = 0
self.score = self.success self.score = self.success
def getConnectTime(self): def getConnectTime(self):
"""set the connectTime variable for when we last connected to them, using the db value""" """set the connectTime variable for when we last connected to them, using the db value"""
try: try:
@ -62,12 +62,12 @@ class PeerProfiles:
pass pass
else: else:
return self.connectTime return self.connectTime
def update_connect_time(self): def update_connect_time(self):
if epoch.get_epoch() - self.last_updated['connect_time'] >= UPDATE_DELAY: if epoch.get_epoch() - self.last_updated['connect_time'] >= UPDATE_DELAY:
self.last_updated['connect_time'] = epoch.get_epoch() self.last_updated['connect_time'] = epoch.get_epoch()
keydb.transportinfo.set_address_info(self.address, 'lastConnect', epoch.get_epoch()) keydb.transportinfo.set_address_info(self.address, 'lastConnect', epoch.get_epoch())
def saveScore(self): def saveScore(self):
'''Save the node's score to the database''' '''Save the node's score to the database'''
if epoch.get_epoch() - self.last_updated['score'] >= UPDATE_DELAY: if epoch.get_epoch() - self.last_updated['score'] >= UPDATE_DELAY:

View File

@ -7,7 +7,7 @@ import nacl.encoding, nacl.hash, nacl.utils
import config import config
import logger import logger
from onionrblocks import onionrblockapi from oldblocks import onionrblockapi
from onionrutils import bytesconverter from onionrutils import bytesconverter
from onionrcrypto import hashers from onionrcrypto import hashers

View File

@ -9,7 +9,7 @@ import onionrexceptions
import onionrstorage import onionrstorage
from onionrutils import stringvalidators from onionrutils import stringvalidators
from coredb import dbfiles from coredb import dbfiles
from onionrblocks import storagecounter from oldblocks import storagecounter
from etc.onionrvalues import DATABASE_LOCK_TIMEOUT from etc.onionrvalues import DATABASE_LOCK_TIMEOUT
""" """
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify

View File

@ -9,7 +9,7 @@ import onionrstorage
import onionrexceptions import onionrexceptions
import onionrcrypto as crypto import onionrcrypto as crypto
import filepaths import filepaths
from onionrblocks import storagecounter, blockmetadata from oldblocks import storagecounter, blockmetadata
from coredb import dbfiles from coredb import dbfiles
from onionrutils import bytesconverter from onionrutils import bytesconverter
from etc.onionrvalues import DATABASE_LOCK_TIMEOUT from etc.onionrvalues import DATABASE_LOCK_TIMEOUT

View File

@ -5,7 +5,7 @@ import new blocks from disk, providing transport agnosticism
import glob import glob
import logger import logger
from onionrblocks import blockmetadata from oldblocks import blockmetadata
from coredb import blockmetadb from coredb import blockmetadb
import filepaths import filepaths
import onionrcrypto as crypto import onionrcrypto as crypto

View File

@ -2,7 +2,7 @@ import os
from gevent import sleep from gevent import sleep
from onionrblocks import insert from oldblocks import insert
import logger import logger
from coredb.blockmetadb import get_block_list from coredb.blockmetadb import get_block_list
from onionrutils import epoch from onionrutils import epoch

View File

@ -1,7 +1,7 @@
import os import os
import time import time
import onionrblocks import oldblocks
import logger import logger
import coredb import coredb
from communicator import peeraction from communicator import peeraction
@ -11,7 +11,7 @@ def _check_remote_node(testmanager):
def insert_bin_test(testmanager): def insert_bin_test(testmanager):
data = os.urandom(32) data = os.urandom(32)
b_hash = onionrblocks.insert(data) b_hash = oldblocks.insert(data)
time.sleep(0.3) time.sleep(0.3)
if b_hash not in testmanager._too_many.get_by_string("PublicAPI").hideBlocks: if b_hash not in testmanager._too_many.get_by_string("PublicAPI").hideBlocks:
raise ValueError("Block not hidden") raise ValueError("Block not hidden")

View File

@ -2,7 +2,7 @@ import requests
from lan.getip import best_ip from lan.getip import best_ip
from onionrblocks import insert, onionrblockapi from oldblocks import insert, onionrblockapi
from gevent import sleep from gevent import sleep
from coredb import blockmetadb from coredb import blockmetadb
from onionrutils.epoch import get_epoch from onionrutils.epoch import get_epoch

View File

@ -1,7 +1,7 @@
import os import os
from shutil import move from shutil import move
from onionrblocks import insert from oldblocks import insert
from onionrstorage import deleteBlock from onionrstorage import deleteBlock
from onionrcommands.exportblocks import export_block from onionrcommands.exportblocks import export_block
from filepaths import export_location, block_data_location, data_nonce_file from filepaths import export_location, block_data_location, data_nonce_file

View File

@ -1,6 +1,6 @@
import os import os
import onionrblocks import oldblocks
import logger import logger
import coredb import coredb
from onionrutils import epoch from onionrutils import epoch
@ -10,7 +10,7 @@ def stress_test_block_insert(testmanager):
start = epoch.get_epoch() start = epoch.get_epoch()
count = 100 count = 100
max_insert_speed = 120 max_insert_speed = 120
for x in range(count): onionrblocks.insert(os.urandom(32)) for x in range(count): oldblocks.insert(os.urandom(32))
speed = epoch.get_epoch() - start speed = epoch.get_epoch() - start
if speed < max_insert_speed: if speed < max_insert_speed:
raise ValueError(f'{count} blocks inserted too fast, {max_insert_speed}, got {speed}') raise ValueError(f'{count} blocks inserted too fast, {max_insert_speed}, got {speed}')

View File

@ -22,6 +22,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
""" """
class DBProtectionOpeningModeError(Exception):
pass
class SafeDB: class SafeDB:
"""Wrapper around dbm to optionally encrypt db values.""" """Wrapper around dbm to optionally encrypt db values."""
@ -31,7 +35,8 @@ class SafeDB:
return unprotect_string(self.db_conn[key]) return unprotect_string(self.db_conn[key])
def put( def put(
self, key: [str, bytes, bytearray], value: [bytes, bytearray]): self,
key: Union[str, bytes, bytearray], value: Union[bytes, bytearray]):
if self.protected: if self.protected:
self.db_conn[key] = protect_string(value) self.db_conn[key] = protect_string(value)
else: else:
@ -47,10 +52,10 @@ class SafeDB:
try: try:
existing_protected_mode = self.db_conn['enc'] existing_protected_mode = self.db_conn['enc']
if protected and existing_protected_mode != b'1': if protected and existing_protected_mode != b'1':
raise ValueError( raise DBProtectionOpeningModeError(
"Cannot open unencrypted database with protected=True") "Cannot open unencrypted database with protected=True")
elif not protected and existing_protected_mode != b'0': elif not protected and existing_protected_mode != b'0':
raise ValueError( raise DBProtectionOpeningModeError(
"Cannot open encrypted database in protected=False") "Cannot open encrypted database in protected=False")
except KeyError: except KeyError:
if protected: if protected:

View File

@ -10,7 +10,7 @@ from watchdog.events import FileSystemEventHandler
import config import config
from filepaths import block_data_location from filepaths import block_data_location
from etc.onionrvalues import BLOCK_EXPORT_FILE_EXT from etc.onionrvalues import BLOCK_EXPORT_FILE_EXT
from onionrblocks.blockimporter import import_block_from_data from oldblocks.blockimporter import import_block_from_data
import onionrexceptions import onionrexceptions
""" """
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify

View File

@ -20,7 +20,7 @@
import logger import logger
from coredb import keydb from coredb import keydb
import config import config
from onionrblocks import onionrblacklist from oldblocks import onionrblacklist
from utils import gettransports from utils import gettransports
def mergeAdders(newAdderList): def mergeAdders(newAdderList):
''' '''

View File

@ -11,9 +11,9 @@ from coredb import blockmetadb
import threading import threading
import time import time
import locale import locale
from onionrblocks.onionrblockapi import Block from oldblocks.onionrblockapi import Block
import logger import logger
import onionrblocks import oldblocks
from onionrutils import escapeansi, epoch, bytesconverter from onionrutils import escapeansi, epoch, bytesconverter
locale.setlocale(locale.LC_ALL, '') locale.setlocale(locale.LC_ALL, '')
@ -79,7 +79,7 @@ class OnionrFlow:
expireTime = epoch.get_epoch() + EXPIRE_TIME expireTime = epoch.get_epoch() + EXPIRE_TIME
if len(message) > 0: if len(message) > 0:
logger.info('Inserting message as block...', terminal=True) logger.info('Inserting message as block...', terminal=True)
onionrblocks.insert(message, header='brd', oldblocks.insert(message, header='brd',
expire=expireTime, expire=expireTime,
meta = { meta = {
'ch': self.channel}) 'ch': self.channel})
@ -132,7 +132,7 @@ def on_circlesend_cmd(api, data=None):
except IndexError: except IndexError:
logger.error(err_msg, terminal=True) logger.error(err_msg, terminal=True)
bl = onionrblocks.insert(sys.argv[3], header='brd', bl = oldblocks.insert(sys.argv[3], header='brd',
expire=(EXPIRE_TIME + epoch.get_epoch()), expire=(EXPIRE_TIME + epoch.get_epoch()),
meta={'ch': sys.argv[2]}) meta={'ch': sys.argv[2]})
print(bl) print(bl)

View File

@ -2,7 +2,7 @@
Load the user's inbox and return it as a list Load the user's inbox and return it as a list
""" """
from onionrblocks import onionrblockapi from oldblocks import onionrblockapi
from coredb import blockmetadb from coredb import blockmetadb
from utils import reconstructhash, identifyhome from utils import reconstructhash, identifyhome
import deadsimplekv as simplekv import deadsimplekv as simplekv

View File

@ -56,6 +56,7 @@ document.getElementById('onboardingForm').onsubmit = function(e){
submitInfo.mail = getCheckValue('useMail') submitInfo.mail = getCheckValue('useMail')
submitInfo.circles = getCheckValue('useCircles') submitInfo.circles = getCheckValue('useCircles')
submitInfo.useDark = getCheckValue('useDarkTheme') submitInfo.useDark = getCheckValue('useDarkTheme')
submitInfo.optimize = getCheckValue('optimize')
if (submitInfo.donate){ if (submitInfo.donate){
openDonateModal(submitInfo) openDonateModal(submitInfo)

View File

@ -19,7 +19,7 @@ import config
config.set("general.minimum_block_pow", 2) config.set("general.minimum_block_pow", 2)
config.set('general.minimum_send_pow', 2) config.set('general.minimum_send_pow', 2)
config.save() config.save()
from onionrblocks import BlockList, insert from oldblocks import BlockList, insert
class TestBlockList(unittest.TestCase): class TestBlockList(unittest.TestCase):

View File

@ -14,7 +14,7 @@ createdirs.create_dirs()
import onionrstorage import onionrstorage
from onionrutils import bytesconverter from onionrutils import bytesconverter
import onionrcrypto import onionrcrypto
from onionrblocks import onionrblockapi from oldblocks import onionrblockapi
from onionrsetup import setup_config, setup_default_plugins from onionrsetup import setup_config, setup_default_plugins
@ -25,20 +25,20 @@ import config
config.set("general.minimum_block_pow", 2) config.set("general.minimum_block_pow", 2)
config.set('general.minimum_send_pow', 2) config.set('general.minimum_send_pow', 2)
config.save() config.save()
import onionrblocks import oldblocks
class OnionrBlockTests(unittest.TestCase): class OnionrBlockTests(unittest.TestCase):
def test_plaintext_insert(self): def test_plaintext_insert(self):
message = 'hello world' message = 'hello world'
bl = onionrblocks.insert(message) bl = oldblocks.insert(message)
self.assertTrue(bl.startswith('0')) self.assertTrue(bl.startswith('0'))
self.assertIn(bytesconverter.str_to_bytes(message), onionrstorage.getData(bl)) self.assertIn(bytesconverter.str_to_bytes(message), onionrstorage.getData(bl))
def test_encrypted_insert(self): def test_encrypted_insert(self):
message = 'hello world2' message = 'hello world2'
bl = onionrblocks.insert(message, asymPeer=onionrcrypto.pub_key) bl = oldblocks.insert(message, asymPeer=onionrcrypto.pub_key)
self.assertIn(bytesconverter.str_to_bytes(message), onionrblockapi.Block(bl, decrypt=True).bcontent) self.assertIn(bytesconverter.str_to_bytes(message), onionrblockapi.Block(bl, decrypt=True).bcontent)
unittest.main() unittest.main()

View File

@ -10,7 +10,7 @@ createdirs.create_dirs()
from onionrcrypto import getourkeypair from onionrcrypto import getourkeypair
getourkeypair.get_keypair() getourkeypair.get_keypair()
from utils import readstatic from utils import readstatic
import onionrblocks import oldblocks
class OnionrConfig(unittest.TestCase): class OnionrConfig(unittest.TestCase):
def test_default_file(self): def test_default_file(self):
json.loads(readstatic.read_static('default_config.json')) json.loads(readstatic.read_static('default_config.json'))

View File

@ -31,7 +31,7 @@ class TestSafeDB(unittest.TestCase):
with dbm.open(db_path) as db: with dbm.open(db_path) as db:
self.assertEqual(db['enc'], b'0') self.assertEqual(db['enc'], b'0')
def test_db_create_proteced(self): def test_db_create_protected(self):
_remove_db() _remove_db()
db = safedb.SafeDB(db_path, protected=True) db = safedb.SafeDB(db_path, protected=True)
db.close() db.close()
@ -46,7 +46,7 @@ class TestSafeDB(unittest.TestCase):
db.close() db.close()
self.assertRaises(ValueError, safedb.SafeDB, db_path, protected=False) self.assertRaises(ValueError, safedb.SafeDB, db_path, protected=False)
def test_db_open_unproteced(self): def test_db_open_unprotected(self):
_remove_db() _remove_db()
with dbm.open(db_path, 'c') as db: with dbm.open(db_path, 'c') as db:
db['enc'] = b'0' db['enc'] = b'0'
@ -54,6 +54,14 @@ class TestSafeDB(unittest.TestCase):
db.close() db.close()
self.assertRaises(ValueError, safedb.SafeDB, db_path, protected=True) self.assertRaises(ValueError, safedb.SafeDB, db_path, protected=True)
def test_db_put_unprotected(self):
_remove_db()
db = safedb.SafeDB(db_path, protected=False)
db.put("test", b"Test")
db.close()
with dbm.open(db_path, 'c') as db:
self.assertEqual(db['test', b"Test"])
unittest.main() unittest.main()

View File

@ -25,9 +25,9 @@ import config
config.set("general.minimum_block_pow", 2) config.set("general.minimum_block_pow", 2)
config.set('general.minimum_send_pow', 2) config.set('general.minimum_send_pow', 2)
config.save() config.save()
import onionrblocks import oldblocks
from onionrblocks import storagecounter from oldblocks import storagecounter
import onionrstorage import onionrstorage
def _test_setup(): def _test_setup():
@ -47,13 +47,13 @@ class TestStorageCounter(unittest.TestCase):
def test_insert_too_much(self): def test_insert_too_much(self):
_test_setup() _test_setup()
config.set('allocations.disk', 1000) config.set('allocations.disk', 1000)
self.assertRaises(onionrexceptions.DiskAllocationReached, onionrblocks.insert, "test") self.assertRaises(onionrexceptions.DiskAllocationReached, oldblocks.insert, "test")
def test_count(self): def test_count(self):
_test_setup() _test_setup()
counter = storagecounter.StorageCounter() counter = storagecounter.StorageCounter()
start_value = counter.amount start_value = counter.amount
b_hash = onionrblocks.insert("test") b_hash = oldblocks.insert("test")
sleep(0.1) sleep(0.1)
self.assertGreater(counter.amount, start_value) self.assertGreater(counter.amount, start_value)
onionrstorage.removeblock.remove_block(b_hash) onionrstorage.removeblock.remove_block(b_hash)

View File

@ -10,8 +10,8 @@ from utils import createdirs
createdirs.create_dirs() createdirs.create_dirs()
from onionrcrypto import getourkeypair from onionrcrypto import getourkeypair
getourkeypair.get_keypair() getourkeypair.get_keypair()
from onionrblocks import time_insert from oldblocks import time_insert
from onionrblocks import onionrblockapi from oldblocks import onionrblockapi
from onionrsetup import setup_config, setup_default_plugins from onionrsetup import setup_config, setup_default_plugins
setup_config() setup_config()