started work on db block data, improved block time stamping messages a bit
This commit is contained in:
parent
98bc3b3271
commit
dc51ab8980
@ -48,6 +48,7 @@ class Core:
|
||||
self.queueDB = self.dataDir + 'queue.db'
|
||||
self.peerDB = self.dataDir + 'peers.db'
|
||||
self.blockDB = self.dataDir + 'blocks.db'
|
||||
self.blockDataDB = self.dataDir + 'block-data.db'
|
||||
self.blockDataLocation = self.dataDir + 'blocks/'
|
||||
self.addressDB = self.dataDir + 'address.db'
|
||||
self.hsAddress = ''
|
||||
|
@ -96,7 +96,7 @@ class DBCreator:
|
||||
conn = sqlite3.connect(self.core.blockDB)
|
||||
c = conn.cursor()
|
||||
c.execute('''CREATE TABLE hashes(
|
||||
hash text not null,
|
||||
hash text distinct not null,
|
||||
dateReceived int,
|
||||
decrypted int,
|
||||
dataType text,
|
||||
@ -111,6 +111,19 @@ class DBCreator:
|
||||
conn.commit()
|
||||
conn.close()
|
||||
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):
|
||||
'''
|
||||
|
@ -362,6 +362,7 @@ class OnionrUtils:
|
||||
'''Validate metadata meets onionr spec (does not validate proof value computation), take in either dictionary or json string'''
|
||||
# TODO, make this check sane sizes
|
||||
retData = False
|
||||
maxClockDifference = 60
|
||||
|
||||
# convert to dict if it is json string
|
||||
if type(metadata) is str:
|
||||
@ -390,13 +391,14 @@ class OnionrUtils:
|
||||
break
|
||||
if i == 'time':
|
||||
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
|
||||
if (metadata[i] - self.getEpoch()) > 30:
|
||||
logger.warn('Block metadata time stamp is set for the future, which is not allowed.')
|
||||
isFuture = (metadata[i] - self.getEpoch())
|
||||
if isFuture > maxClockDifference:
|
||||
logger.warn('Block timestamp is skewed to the future over the max %s: %s' (maxClockDifference, isFuture))
|
||||
break
|
||||
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':
|
||||
try:
|
||||
assert int(metadata[i]) > self.getEpoch()
|
||||
@ -440,7 +442,7 @@ class OnionrUtils:
|
||||
return retVal
|
||||
|
||||
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:
|
||||
int(data)
|
||||
except ValueError:
|
||||
|
Loading…
Reference in New Issue
Block a user