diff --git a/onionr/core.py b/onionr/core.py index 017b4313..84863b40 100644 --- a/onionr/core.py +++ b/onionr/core.py @@ -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 = '' diff --git a/onionr/dbcreator.py b/onionr/dbcreator.py index f2f12f07..cde4fd83 100644 --- a/onionr/dbcreator.py +++ b/onionr/dbcreator.py @@ -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): ''' diff --git a/onionr/onionrutils.py b/onionr/onionrutils.py index 948563e3..7f5606ba 100644 --- a/onionr/onionrutils.py +++ b/onionr/onionrutils.py @@ -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: