started work on db block data, improved block time stamping messages a bit

master
Kevin Froman 2018-12-16 12:21:44 -06:00
parent 98bc3b3271
commit dc51ab8980
3 changed files with 22 additions and 6 deletions

View File

@ -48,6 +48,7 @@ class Core:
self.queueDB = self.dataDir + 'queue.db' self.queueDB = self.dataDir + 'queue.db'
self.peerDB = self.dataDir + 'peers.db' self.peerDB = self.dataDir + 'peers.db'
self.blockDB = self.dataDir + 'blocks.db' self.blockDB = self.dataDir + 'blocks.db'
self.blockDataDB = self.dataDir + 'block-data.db'
self.blockDataLocation = self.dataDir + 'blocks/' self.blockDataLocation = self.dataDir + 'blocks/'
self.addressDB = self.dataDir + 'address.db' self.addressDB = self.dataDir + 'address.db'
self.hsAddress = '' self.hsAddress = ''

View File

@ -96,7 +96,7 @@ class DBCreator:
conn = sqlite3.connect(self.core.blockDB) conn = sqlite3.connect(self.core.blockDB)
c = conn.cursor() c = conn.cursor()
c.execute('''CREATE TABLE hashes( c.execute('''CREATE TABLE hashes(
hash text not null, hash text distinct not null,
dateReceived int, dateReceived int,
decrypted int, decrypted int,
dataType text, dataType text,
@ -111,6 +111,19 @@ class DBCreator:
conn.commit() conn.commit()
conn.close() conn.close()
return return
def createBlockDataDB(self):
if os.path.exists(self.core.blockDataDB):
raise Exception("Block data database already exists")
conn = sqlite3.connect(self.core.blockDataDB)
c = conn.cursor()
c.execute('''CREATE TABLE blockData(
hash text distinct not null,
data blob not null
);
''')
conn.commit()
conn.close()
def createForwardKeyDB(self): def createForwardKeyDB(self):
''' '''

View File

@ -362,6 +362,7 @@ class OnionrUtils:
'''Validate metadata meets onionr spec (does not validate proof value computation), take in either dictionary or json string''' '''Validate metadata meets onionr spec (does not validate proof value computation), take in either dictionary or json string'''
# TODO, make this check sane sizes # TODO, make this check sane sizes
retData = False retData = False
maxClockDifference = 60
# convert to dict if it is json string # convert to dict if it is json string
if type(metadata) is str: if type(metadata) is str:
@ -390,13 +391,14 @@ class OnionrUtils:
break break
if i == 'time': if i == 'time':
if not self.isIntegerString(metadata[i]): if not self.isIntegerString(metadata[i]):
logger.warn('Block metadata time stamp is not integer string') logger.warn('Block metadata time stamp is not integer string or int')
break break
if (metadata[i] - self.getEpoch()) > 30: isFuture = (metadata[i] - self.getEpoch())
logger.warn('Block metadata time stamp is set for the future, which is not allowed.') if isFuture > maxClockDifference:
logger.warn('Block timestamp is skewed to the future over the max %s: %s' (maxClockDifference, isFuture))
break break
if (self.getEpoch() - metadata[i]) > maxAge: if (self.getEpoch() - metadata[i]) > maxAge:
logger.warn('Block is older than allowed: %s' % (maxAge,)) logger.warn('Block is outdated: %s' % (metadata[i],))
elif i == 'expire': elif i == 'expire':
try: try:
assert int(metadata[i]) > self.getEpoch() assert int(metadata[i]) > self.getEpoch()
@ -440,7 +442,7 @@ class OnionrUtils:
return retVal return retVal
def isIntegerString(self, data): def isIntegerString(self, data):
'''Check if a string is a valid base10 integer''' '''Check if a string is a valid base10 integer (also returns true if already an int)'''
try: try:
int(data) int(data)
except ValueError: except ValueError: