From b8348be65ac6b17d73da0680b054ed2376c66037 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sun, 23 Feb 2020 02:12:13 -0600 Subject: [PATCH] now avoid looking up older than allowed blocks --- src/communicatorutils/lookupblocks.py | 40 +++++++++++++++------------ src/etc/onionrvalues.py | 2 +- src/onionrutils/validatemetadata.py | 2 +- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/communicatorutils/lookupblocks.py b/src/communicatorutils/lookupblocks.py index b2e2a35c..873863d1 100755 --- a/src/communicatorutils/lookupblocks.py +++ b/src/communicatorutils/lookupblocks.py @@ -1,9 +1,20 @@ -''' - Onionr - Private P2P Communication +"""Onionr - Private P2P Communication - Lookup new blocks with the communicator using a random connected peer -''' -''' +Lookup new blocks with the communicator using a random connected peer +""" +from gevent import time + +import logger +import onionrproofs +from onionrutils import stringvalidators, epoch +from communicator import peeraction, onlinepeers +from coredb import blockmetadb +from utils import reconstructhash +from onionrblocks import onionrblacklist +import onionrexceptions +import config +from etc import onionrvalues +""" This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or @@ -16,17 +27,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . -''' -from gevent import time +""" -import logger, onionrproofs -from onionrutils import stringvalidators, epoch -from communicator import peeraction, onlinepeers -from coredb import blockmetadb -from utils import reconstructhash -from onionrblocks import onionrblacklist -import onionrexceptions blacklist = onionrblacklist.OnionrBlackList() + + def lookup_blocks_from_communicator(comm_inst): logger.info('Looking up new blocks') tryAmount = 2 @@ -65,9 +70,8 @@ def lookup_blocks_from_communicator(comm_inst): try: lastLookupTime = comm_inst.dbTimestamps[peer] except KeyError: - lastLookupTime = 0 - else: - listLookupCommand += '?date=%s' % (lastLookupTime,) + lastLookupTime = epoch.get_epoch() - config.get("general.max_block_age", onionrvalues.DEFAULT_EXPIRE) + listLookupCommand += '?date=%s' % (lastLookupTime,) try: newBlocks = peeraction.peer_action(comm_inst, peer, listLookupCommand) # get list of new block hashes except Exception as error: @@ -99,4 +103,4 @@ def lookup_blocks_from_communicator(comm_inst): logger.info('Discovered %s new block%s' % (new_block_count, block_string), terminal=True) comm_inst.download_blocks_timer.count = int(comm_inst.download_blocks_timer.frequency * 0.99) comm_inst.decrementThreadCount('lookup_blocks_from_communicator') - return \ No newline at end of file + return diff --git a/src/etc/onionrvalues.py b/src/etc/onionrvalues.py index 10a90307..1abe19a4 100755 --- a/src/etc/onionrvalues.py +++ b/src/etc/onionrvalues.py @@ -53,7 +53,7 @@ BLOCK_EXPORT_FILE_EXT = '.dat' # Begin OnionrValues migrated values """30 days is plenty of time for someone to decide to renew a block""" -DEFAULT_EXPIRE = 2592000 +DEFAULT_EXPIRE = 2678400 # Metadata header section length limits, in bytes BLOCK_METADATA_LENGTHS = {'meta': 1000, 'sig': 200, 'signer': 200, 'time': 10, 'pow': 1000, 'encryptType': 4, 'expire': 14} diff --git a/src/onionrutils/validatemetadata.py b/src/onionrutils/validatemetadata.py index 202652f9..9349ec9e 100644 --- a/src/onionrutils/validatemetadata.py +++ b/src/onionrutils/validatemetadata.py @@ -37,7 +37,7 @@ def validate_metadata(metadata, block_data) -> bool: pass # Validate metadata dict for invalid keys to sizes that are too large - maxAge = min(config.get("general.max_block_age", onionrvalues.DEFAULT_EXPIRE), onionrvalues.DEFAULT_EXPIRE) + maxAge = config.get("general.max_block_age", onionrvalues.DEFAULT_EXPIRE) if type(metadata) is dict: for i in metadata: try: