fixed housekeeping being broken
This commit is contained in:
		
							parent
							
								
									c0def6fb7e
								
							
						
					
					
						commit
						665cb0c732
					
				
					 12 changed files with 62 additions and 29 deletions
				
			
		|  | @ -44,11 +44,14 @@ def clean_old_blocks(comm_inst): | |||
|         logger.info('Deleted block: %s' % (bHash,)) | ||||
| 
 | ||||
|     while comm_inst.storage_counter.is_full(): | ||||
|         oldest = blockmetadb.get_block_list()[0] | ||||
|         try: | ||||
|             oldest = blockmetadb.get_block_list()[0] | ||||
|         except IndexError: | ||||
|             break | ||||
|         blacklist.addToDB(oldest) | ||||
|         removeblock.remove_block(oldest) | ||||
|         onionrstorage.deleteBlock(oldest) | ||||
|         __remove_from_upload.remove(comm_inst, oldest) | ||||
|         __remove_from_upload(comm_inst, oldest) | ||||
|         logger.info('Deleted block: %s' % (oldest,)) | ||||
| 
 | ||||
|     comm_inst.decrementThreadCount('clean_old_blocks') | ||||
|  |  | |||
|  | @ -1,9 +1,15 @@ | |||
| ''' | ||||
|     Onionr - Private P2P Communication | ||||
| """Onionr - Private P2P Communication. | ||||
| 
 | ||||
|     Add an entry to the block metadata database | ||||
| ''' | ||||
| ''' | ||||
| Add an entry to the block metadata database | ||||
| """ | ||||
| import os | ||||
| import sqlite3 | ||||
| import secrets | ||||
| from onionrutils import epoch, blockmetadata | ||||
| from etc import onionrvalues | ||||
| from .. import dbfiles | ||||
| from onionrexceptions import BlockMetaEntryExists | ||||
| """ | ||||
|     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,20 +22,18 @@ | |||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| ''' | ||||
| import os, sqlite3, secrets | ||||
| from onionrutils import epoch, blockmetadata | ||||
| from etc import onionrvalues | ||||
| from .. import dbfiles | ||||
| """ | ||||
| 
 | ||||
| 
 | ||||
| def add_to_block_DB(newHash, selfInsert=False, dataSaved=False): | ||||
|     ''' | ||||
|     """ | ||||
|         Add a hash value to the block db | ||||
| 
 | ||||
|         Should be in hex format! | ||||
|     ''' | ||||
|     """ | ||||
| 
 | ||||
|     if blockmetadata.has_block(newHash): | ||||
|         return | ||||
|         raise | ||||
|     conn = sqlite3.connect(dbfiles.block_meta_db, timeout=onionrvalues.DATABASE_LOCK_TIMEOUT) | ||||
|     c = conn.cursor() | ||||
|     currentTime = epoch.get_epoch() + secrets.randbelow(301) | ||||
|  | @ -40,4 +44,4 @@ def add_to_block_DB(newHash, selfInsert=False, dataSaved=False): | |||
|     data = (newHash, currentTime, '', selfInsert) | ||||
|     c.execute('INSERT INTO hashes (hash, dateReceived, dataType, dataSaved) VALUES(?, ?, ?, ?);', data) | ||||
|     conn.commit() | ||||
|     conn.close() | ||||
|     conn.close() | ||||
|  |  | |||
|  | @ -42,7 +42,6 @@ DATABASE_LOCK_TIMEOUT = 60 | |||
| 
 | ||||
| # Block creation anonymization requirements | ||||
| MIN_BLOCK_UPLOAD_PEER_PERCENT = 0.1 | ||||
| MIN_SHARE_WAIT_DELAY_SECS = 5 | ||||
| 
 | ||||
| WSGI_SERVER_REQUEST_TIMEOUT_SECS = 120 | ||||
| 
 | ||||
|  | @ -55,7 +54,8 @@ BLOCK_EXPORT_FILE_EXT = '.dat' | |||
| """30 days is plenty of time for someone to decide to renew a block""" | ||||
| 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} | ||||
| BLOCK_METADATA_LENGTHS = {'meta': 1000, 'sig': 200, 'signer': 200, 'time': 10, | ||||
|                           'pow': 1000, 'encryptType': 4, 'expire': 14} | ||||
| 
 | ||||
| # Pool Eligibility Max Age | ||||
| BLOCK_POOL_MAX_AGE = 300 | ||||
|  |  | |||
|  | @ -62,6 +62,8 @@ def insert_block(data: Union[str, bytes], header: str = 'txt', | |||
|     """ | ||||
|         Inserts a block into the network | ||||
|         encryptType must be specified to encrypt a block | ||||
|         if expire is less than date, assumes seconds into future. | ||||
|             if not assume exact epoch | ||||
|     """ | ||||
|     our_private_key = crypto.priv_key | ||||
|     our_pub_key = crypto.pub_key | ||||
|  | @ -180,6 +182,9 @@ def insert_block(data: Union[str, bytes], header: str = 'txt', | |||
|     # ensure expire is integer and of sane length | ||||
|     if type(expire) is not type(None): | ||||
|         if not len(str(int(expire))) < 20: raise ValueError('expire must be valid int less than 20 digits in length') | ||||
|         # if expire is less than date, assume seconds into future | ||||
|         if expire < epoch.get_epoch(): | ||||
|             expire = epoch.get_epoch() + expire | ||||
|         metadata['expire'] = expire | ||||
| 
 | ||||
|     # send block data (and metadata) to POW module to get tokenized block data | ||||
|  | @ -207,8 +212,14 @@ def insert_block(data: Union[str, bytes], header: str = 'txt', | |||
|             coredb.blockmetadb.add.add_to_block_DB(retData, selfInsert=True, dataSaved=True) | ||||
| 
 | ||||
|             if expire is None: | ||||
|                 coredb.blockmetadb.update_block_info(retData, 'expire', | ||||
|                                                      createTime + onionrvalues.DEFAULT_EXPIRE) | ||||
|                 coredb.blockmetadb.update_block_info( | ||||
|                     retData, 'expire', | ||||
|                     createTime + | ||||
|                     min( | ||||
|                         onionrvalues.DEFAULT_EXPIRE, | ||||
|                         config.get( | ||||
|                             'general.max_block_age', | ||||
|                             onionrvalues.DEFAULT_EXPIRE))) | ||||
|             else: | ||||
|                 coredb.blockmetadb.update_block_info(retData, 'expire', expire) | ||||
| 
 | ||||
|  |  | |||
|  | @ -54,7 +54,7 @@ class ReplayAttack(Exception): | |||
| class InvalidUpdate(Exception): | ||||
|     pass | ||||
| 
 | ||||
| class DifficultyTooLarge(Exception): | ||||
| class BlockMetaEntryExists(Exception): | ||||
|     pass | ||||
| 
 | ||||
| class InvalidMetadata(Exception): | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue