work on new flow plugin and block metadata caching

This commit is contained in:
Kevin Froman 2018-07-11 14:45:38 -05:00
parent f918ae9b9c
commit d879383a8a
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
4 changed files with 21 additions and 2 deletions

View File

@ -597,7 +597,7 @@ class Core:
return
def getBlockList(self, unsaved = False): # TODO: Use unsaved
def getBlockList(self, unsaved = False): # TODO: Use unsaved??
'''
Get list of our blocks
'''
@ -658,6 +658,16 @@ class Core:
def updateBlockInfo(self, hash, key, data):
'''
sets info associated with a block
hash - the hash of a block
dateReceived - the date the block was recieved, not necessarily when it was created
decrypted - if we can successfully decrypt the block (does not describe its current state)
dataType - data type of the block
dataFound - if the data has been found for the block
dataSaved - if the data has been saved for the block
sig - optional signature by the author (not optional if author is specified)
author - multi-round partial sha3-256 hash of authors public key
dateClaimed - timestamp claimed inside the block, only as trustworthy as the block author is
'''
if key not in ('dateReceived', 'decrypted', 'dataType', 'dataFound', 'dataSaved', 'sig', 'author', 'dateClaimed'):

View File

@ -18,7 +18,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
import core as onionrcore, logger, config
import core as onionrcore, logger, config, onionrexceptions
import json, os, sys, datetime, base64
class Block:
@ -32,6 +32,7 @@ class Block:
hash = hash.decode()
except AttributeError:
pass
self.hash = hash
self.core = core
self.btype = type
@ -54,6 +55,9 @@ class Block:
# handle arguments
if self.getCore() is None:
self.core = onionrcore.Core()
if not self.core._utils.validateHash(self.hash):
raise onionrexceptions.InvalidHexHash('specified block hash is not valid')
# update the blocks' contents if it exists
if not self.getHash() is None:

View File

@ -38,6 +38,10 @@ class InvalidPubkey(Exception):
class InvalidMetadata(Exception):
pass
class InvalidHexHash(Exception):
'''When a string is not a valid hex string of appropriate length for a hash value'''
pass
# network level exceptions
class MissingPort(Exception):
pass

View File

@ -251,6 +251,7 @@ class OnionrUtils:
Read metadata from a block and cache it to the block database
'''
myBlock = Block(myBlock, self._core)
self._core.updateBlockInfo(blockHash, 'dataType', myBlock.getType())
def getBlockDBHash(self):