work on new flow plugin and block metadata caching

master
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 return
def getBlockList(self, unsaved = False): # TODO: Use unsaved def getBlockList(self, unsaved = False): # TODO: Use unsaved??
''' '''
Get list of our blocks Get list of our blocks
''' '''
@ -658,6 +658,16 @@ class Core:
def updateBlockInfo(self, hash, key, data): def updateBlockInfo(self, hash, key, data):
''' '''
sets info associated with a block 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'): 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/>. 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 import json, os, sys, datetime, base64
class Block: class Block:
@ -32,6 +32,7 @@ class Block:
hash = hash.decode() hash = hash.decode()
except AttributeError: except AttributeError:
pass pass
self.hash = hash self.hash = hash
self.core = core self.core = core
self.btype = type self.btype = type
@ -55,6 +56,9 @@ class Block:
if self.getCore() is None: if self.getCore() is None:
self.core = onionrcore.Core() 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 # update the blocks' contents if it exists
if not self.getHash() is None: if not self.getHash() is None:
if not self.update(): if not self.update():

View File

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

View File

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