corrected onionrstorage formatting
This commit is contained in:
		
							parent
							
								
									16ae16f042
								
							
						
					
					
						commit
						012ee33499
					
				
					 3 changed files with 28 additions and 21 deletions
				
			
		|  | @ -1,8 +1,8 @@ | |||
| ''' | ||||
|     Onionr - Private P2P Communication | ||||
| """Onionr - Private P2P Communication. | ||||
| 
 | ||||
|     This file handles block storage, providing an abstraction for storing blocks between file system and database | ||||
| ''' | ||||
| Handle block storage, providing an abstraction for | ||||
| storing blocks between file system and database | ||||
| """ | ||||
| import sys | ||||
| import sqlite3 | ||||
| import os | ||||
|  | @ -10,12 +10,10 @@ from onionrutils import bytesconverter | |||
| from onionrutils import stringvalidators | ||||
| from coredb import dbfiles | ||||
| import filepaths | ||||
| import onionrcrypto | ||||
| import onionrexceptions | ||||
| from onionrsetup import dbcreator | ||||
| from onionrcrypto import hashers | ||||
| from . import setdata | ||||
| ''' | ||||
| """ | ||||
|     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 | ||||
|  | @ -28,7 +26,7 @@ from . import setdata | |||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| ''' | ||||
| """ | ||||
| 
 | ||||
| 
 | ||||
| DB_ENTRY_SIZE_LIMIT = 10000  # Will be a config option | ||||
|  |  | |||
|  | @ -2,8 +2,11 @@ | |||
| 
 | ||||
| remove onionr block from meta db | ||||
| """ | ||||
| import sys, sqlite3 | ||||
| import onionrexceptions, onionrstorage | ||||
| import sys | ||||
| import sqlite3 | ||||
| 
 | ||||
| import onionrexceptions | ||||
| import onionrstorage | ||||
| from onionrutils import stringvalidators | ||||
| from coredb import dbfiles | ||||
| from onionrblocks import storagecounter | ||||
|  | @ -24,12 +27,10 @@ from onionrblocks import storagecounter | |||
| 
 | ||||
| 
 | ||||
| def remove_block(block): | ||||
|     """ | ||||
|         remove a block from this node (does not automatically blacklist) | ||||
|     """remove a block from this node (does not automatically blacklist). | ||||
| 
 | ||||
|         **You may want blacklist.addToDB(blockHash) | ||||
|     **You may want blacklist.addToDB(blockHash) | ||||
|     """ | ||||
| 
 | ||||
|     if stringvalidators.validate_hash(block): | ||||
|         conn = sqlite3.connect(dbfiles.block_meta_db, timeout=30) | ||||
|         c = conn.cursor() | ||||
|  |  | |||
|  | @ -5,7 +5,9 @@ Test Onionr as it is running | |||
| import sys | ||||
| import sqlite3 | ||||
| 
 | ||||
| import onionrstorage, onionrexceptions, onionrcrypto as crypto | ||||
| import onionrstorage | ||||
| import onionrexceptions | ||||
| import onionrcrypto as crypto | ||||
| import filepaths | ||||
| from onionrblocks import storagecounter | ||||
| from coredb import dbfiles | ||||
|  | @ -24,12 +26,16 @@ from onionrutils import blockmetadata, bytesconverter | |||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| """ | ||||
| def set_data(data)->str: | ||||
| 
 | ||||
| 
 | ||||
| def set_data(data) -> str: | ||||
|     """Set the data assciated with a hash.""" | ||||
|     storage_counter = storagecounter.StorageCounter() | ||||
|     data = data | ||||
|     dataSize = sys.getsizeof(data) | ||||
|     nonce_hash = crypto.hashers.sha3_hash(bytesconverter.str_to_bytes(blockmetadata.fromdata.get_block_metadata_from_data(data)[2])) | ||||
|     nonce_hash = crypto.hashers.sha3_hash( | ||||
|         bytesconverter.str_to_bytes( | ||||
|             blockmetadata.fromdata.get_block_metadata_from_data(data)[2])) | ||||
|     nonce_hash = bytesconverter.bytes_to_str(nonce_hash) | ||||
| 
 | ||||
|     if not type(data) is bytes: | ||||
|  | @ -39,15 +45,16 @@ def set_data(data)->str: | |||
| 
 | ||||
|     if type(dataHash) is bytes: | ||||
|         dataHash = dataHash.decode() | ||||
|     blockFileName = filepaths.block_data_location + dataHash + '.dat' | ||||
|     try: | ||||
|         onionrstorage.getData(dataHash) | ||||
|     except onionrexceptions.NoDataAvailable: | ||||
|         if storage_counter.add_bytes(dataSize) != False: | ||||
|         if storage_counter.add_bytes(dataSize) is not False: | ||||
|             onionrstorage.store(data, blockHash=dataHash) | ||||
|             conn = sqlite3.connect(dbfiles.block_meta_db, timeout=30) | ||||
|             c = conn.cursor() | ||||
|             c.execute("UPDATE hashes SET dataSaved=1 WHERE hash = ?;", (dataHash,)) | ||||
|             c.execute( | ||||
|                 "UPDATE hashes SET dataSaved=1 WHERE hash = ?;", | ||||
|                 (dataHash,)) | ||||
|             conn.commit() | ||||
|             conn.close() | ||||
|             with open(filepaths.data_nonce_file, 'a') as nonceFile: | ||||
|  | @ -55,6 +62,7 @@ def set_data(data)->str: | |||
|         else: | ||||
|             raise onionrexceptions.DiskAllocationReached | ||||
|     else: | ||||
|         raise onionrexceptions.DataExists("Data is already set for " + dataHash) | ||||
|         raise onionrexceptions.DataExists( | ||||
|                 "Data is already set for " + dataHash) | ||||
| 
 | ||||
|     return dataHash | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue