now avoid looking up older than allowed blocks

master
Kevin Froman 2020-02-23 02:12:13 -06:00
parent 34a55f63f9
commit b8348be65a
3 changed files with 24 additions and 20 deletions

View File

@ -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 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or 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 You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
''' """
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() blacklist = onionrblacklist.OnionrBlackList()
def lookup_blocks_from_communicator(comm_inst): def lookup_blocks_from_communicator(comm_inst):
logger.info('Looking up new blocks') logger.info('Looking up new blocks')
tryAmount = 2 tryAmount = 2
@ -65,9 +70,8 @@ def lookup_blocks_from_communicator(comm_inst):
try: try:
lastLookupTime = comm_inst.dbTimestamps[peer] lastLookupTime = comm_inst.dbTimestamps[peer]
except KeyError: except KeyError:
lastLookupTime = 0 lastLookupTime = epoch.get_epoch() - config.get("general.max_block_age", onionrvalues.DEFAULT_EXPIRE)
else: listLookupCommand += '?date=%s' % (lastLookupTime,)
listLookupCommand += '?date=%s' % (lastLookupTime,)
try: try:
newBlocks = peeraction.peer_action(comm_inst, peer, listLookupCommand) # get list of new block hashes newBlocks = peeraction.peer_action(comm_inst, peer, listLookupCommand) # get list of new block hashes
except Exception as error: except Exception as error:

View File

@ -53,7 +53,7 @@ BLOCK_EXPORT_FILE_EXT = '.dat'
# Begin OnionrValues migrated values # Begin OnionrValues migrated values
"""30 days is plenty of time for someone to decide to renew a block""" """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 # Metadata header section length limits, in bytes
BLOCK_METADATA_LENGTHS = {'meta': 1000, 'sig': 200, 'signer': 200, 'time': 10, 'pow': 1000, 'encryptType': 4, 'expire': 14} BLOCK_METADATA_LENGTHS = {'meta': 1000, 'sig': 200, 'signer': 200, 'time': 10, 'pow': 1000, 'encryptType': 4, 'expire': 14}

View File

@ -37,7 +37,7 @@ def validate_metadata(metadata, block_data) -> bool:
pass pass
# Validate metadata dict for invalid keys to sizes that are too large # 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: if type(metadata) is dict:
for i in metadata: for i in metadata:
try: try: