From d879383a8a85f8764a876c9acc0a5cfea25722f0 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Wed, 11 Jul 2018 14:45:38 -0500 Subject: [PATCH] work on new flow plugin and block metadata caching --- onionr/core.py | 12 +++++++++++- onionr/onionrblockapi.py | 6 +++++- onionr/onionrexceptions.py | 4 ++++ onionr/onionrutils.py | 1 + 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/onionr/core.py b/onionr/core.py index 40f844e4..16502d25 100644 --- a/onionr/core.py +++ b/onionr/core.py @@ -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'): diff --git a/onionr/onionrblockapi.py b/onionr/onionrblockapi.py index ba0c0408..dbb358af 100644 --- a/onionr/onionrblockapi.py +++ b/onionr/onionrblockapi.py @@ -18,7 +18,7 @@ along with this program. If not, see . ''' -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: diff --git a/onionr/onionrexceptions.py b/onionr/onionrexceptions.py index e1227305..c97849c1 100644 --- a/onionr/onionrexceptions.py +++ b/onionr/onionrexceptions.py @@ -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 diff --git a/onionr/onionrutils.py b/onionr/onionrutils.py index de44e925..651e88d1 100644 --- a/onionr/onionrutils.py +++ b/onionr/onionrutils.py @@ -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):