moved blockmetadata to onionrblocks

master
Kevin Froman 2020-11-02 01:31:11 +00:00
parent 44112750ec
commit f0cd2fb2b9
12 changed files with 56 additions and 73 deletions

View File

@ -17,7 +17,7 @@ import onionrpeers
from communicator import peeraction
from communicator import onlinepeers
from onionrutils import blockmetadata
from onionrblocks import blockmetadata
from onionrutils import validatemetadata
from coredb import blockmetadb
from onionrutils.localcommand import local_command

View File

@ -2,10 +2,10 @@
Add an entry to the block metadata database
"""
import os
import sqlite3
import secrets
from onionrutils import epoch, blockmetadata
from onionrutils import epoch
from onionrblocks import blockmetadata
from etc import onionrvalues
from .. import dbfiles
from onionrexceptions import BlockMetaEntryExists
@ -34,7 +34,8 @@ def add_to_block_DB(newHash, selfInsert=False, dataSaved=False):
if blockmetadata.has_block(newHash):
raise BlockMetaEntryExists
conn = sqlite3.connect(dbfiles.block_meta_db, timeout=onionrvalues.DATABASE_LOCK_TIMEOUT)
conn = sqlite3.connect(
dbfiles.block_meta_db, timeout=onionrvalues.DATABASE_LOCK_TIMEOUT)
c = conn.cursor()
currentTime = epoch.get_epoch() + secrets.randbelow(61)
if selfInsert or dataSaved:
@ -42,6 +43,7 @@ def add_to_block_DB(newHash, selfInsert=False, dataSaved=False):
else:
selfInsert = 0
data = (newHash, currentTime, '', selfInsert)
c.execute('INSERT INTO hashes (hash, dateReceived, dataType, dataSaved) VALUES(?, ?, ?, ?);', data)
c.execute(
'INSERT INTO hashes (hash, dateReceived, dataType, dataSaved) VALUES(?, ?, ?, ?);', data)
conn.commit()
conn.close()

View File

@ -0,0 +1,11 @@
import ujson
import nacl.utils
from nacl.public import PrivateKey, SealedBox
from .blockmetadata import get_block_metadata_from_data
def block_decrypt(raw_block) -> DecryptedBlock:
block_header, user_meta, block_data = get_block_metadata_from_data(
raw_block)

View File

@ -8,9 +8,9 @@ from onionrexceptions import InvalidProof
from onionrexceptions import InvalidMetadata
import logger
from onionrutils import validatemetadata
from onionrutils import blockmetadata
from onionrutils import bytesconverter
from coredb import blockmetadb
from onionrblocks import blockmetadata
import onionrstorage
import onionrcrypto as crypto
from . import onionrblacklist

View File

@ -1,9 +1,13 @@
'''
Onionr - Private P2P Communication
"""Onionr - Private P2P Communication.
Returns a bool if a block is in the block metadata db or not
'''
'''
Return a bool if a block is in the block metadata db or not
"""
import sqlite3
from coredb import dbfiles
import onionrexceptions
from onionrutils import stringvalidators
from etc import onionrvalues
"""
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
the Free Software Foundation, either version 3 of the License, or
@ -16,18 +20,13 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
import sqlite3
from coredb import dbfiles
import onionrexceptions
from .. import stringvalidators
from etc import onionrvalues
"""
def has_block(hash: str) -> bool:
'''
Check for new block in the block meta db
'''
conn = sqlite3.connect(dbfiles.block_meta_db,
"""Check for new block in the block meta db."""
conn = sqlite3.connect(
dbfiles.block_meta_db,
timeout=onionrvalues.DATABASE_LOCK_TIMEOUT)
c = conn.cursor()
if not stringvalidators.validate_hash(hash):

View File

@ -1,9 +1,17 @@
'''
Onionr - Private P2P Communication
"""Onionr - Private P2P Communication.
Process block metadata with relevant actions
'''
'''
Process block metadata with relevant actions
"""
from etc import onionrvalues
from onionrblocks import onionrblockapi
from onionrutils import epoch, bytesconverter
from coredb import blockmetadb
import logger
from onionrplugins import onionrevents
import onionrexceptions
from onionrusers import onionrusers
from onionrutils import updater
"""
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
the Free Software Foundation, either version 3 of the License, or
@ -16,25 +24,15 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
"""
from etc import onionrvalues
from onionrblocks import onionrblockapi
from .. import epoch, bytesconverter
from coredb import blockmetadb
import logger
from onionrplugins import onionrevents
import onionrexceptions
from onionrusers import onionrusers
from onionrutils import updater
from gevent import sleep
def process_block_metadata(blockHash: str):
'''
Read metadata from a block and cache it to the block database
"""
Read metadata from a block and cache it to the block database.
blockHash -> sha3_256 hex formatted hash of Onionr block
'''
blockHash -> sha3_256 hex formatted hash of Onionr block
"""
curTime = epoch.get_rounded_epoch(roundS=60)
myBlock = onionrblockapi.Block(blockHash)
if myBlock.isEncrypted:

View File

@ -17,7 +17,8 @@ import config
import onionrcrypto as crypto
import onionrexceptions
from onionrusers import onionrusers
from onionrutils import localcommand, blockmetadata, stringvalidators
from onionrutils import localcommand, stringvalidators
from .. import blockmetadata
import coredb
from onionrproofs import subprocesspow
import logger

View File

@ -2,7 +2,6 @@
OnionrBlocks class for abstraction of blocks
"""
import binascii
import datetime
import onionrstorage
@ -207,33 +206,6 @@ class Block:
return False
def save(self, sign = False, recreate = True):
"""
Saves a block to file and imports it into Onionr
Inputs:
- sign (bool): whether or not to sign the block before saving
- recreate (bool): if the block already exists, whether or not to recreate the block and save under a new hash
Outputs:
- (bool): whether or not the operation was successful
"""
try:
if self.isValid() is True:
self.hash = onionrblocks.insert(self.getRaw(), header = self.getType(), sign = sign, meta = self.getMetadata(), expire = self.getExpire())
if self.hash != False:
self.update()
return self.getHash()
else:
logger.warn('Not writing block; it is invalid.')
except Exception as e:
logger.error('Failed to save block.', error = e, timestamp = False)
return False
# getters
def getExpire(self):

View File

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

View File

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