misc formatting improvements
This commit is contained in:
parent
39650a4ca0
commit
a83351a73c
4 changed files with 50 additions and 39 deletions
|
@ -1,8 +1,7 @@
|
|||
'''
|
||||
Onionr - Private P2P Communication
|
||||
"""Onionr - Private P2P Communication.
|
||||
|
||||
Import block data and save it
|
||||
'''
|
||||
Import block data and save it
|
||||
"""
|
||||
from onionrexceptions import BlacklistedBlock
|
||||
from onionrexceptions import DiskAllocationReached
|
||||
from onionrexceptions import InvalidProof
|
||||
|
@ -10,12 +9,13 @@ from onionrexceptions import InvalidMetadata
|
|||
import logger
|
||||
from onionrutils import validatemetadata
|
||||
from onionrutils import blockmetadata
|
||||
from onionrutils import bytesconverter
|
||||
from coredb import blockmetadb
|
||||
import onionrstorage
|
||||
import onionrcrypto as crypto
|
||||
from . import onionrblacklist
|
||||
|
||||
'''
|
||||
"""
|
||||
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,17 +28,14 @@ from . import onionrblacklist
|
|||
|
||||
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 import_block_from_data(content):
|
||||
blacklist = onionrblacklist.OnionrBlackList()
|
||||
ret_data = False
|
||||
|
||||
try:
|
||||
content = content.encode()
|
||||
except AttributeError:
|
||||
pass
|
||||
content = bytesconverter.str_to_bytes(content)
|
||||
|
||||
data_hash = crypto.hashers.sha3_hash(content)
|
||||
|
||||
|
@ -56,15 +53,15 @@ def import_block_from_data(content):
|
|||
logger.info(f'Imported block passed proof, saving: {data_hash}.',
|
||||
terminal=True)
|
||||
try:
|
||||
blockHash = onionrstorage.set_data(content)
|
||||
block_hash = onionrstorage.set_data(content)
|
||||
except DiskAllocationReached:
|
||||
logger.warn('Failed to save block due to full disk allocation')
|
||||
raise
|
||||
else:
|
||||
blockmetadb.add_to_block_DB(blockHash, dataSaved=True)
|
||||
blockmetadb.add_to_block_DB(block_hash, dataSaved=True)
|
||||
# caches block metadata values to block database
|
||||
blockmetadata.process_block_metadata(blockHash)
|
||||
ret_data = blockHash
|
||||
blockmetadata.process_block_metadata(block_hash)
|
||||
ret_data = block_hash
|
||||
else:
|
||||
raise InvalidProof
|
||||
else:
|
||||
|
|
|
@ -41,7 +41,8 @@ class BlockList:
|
|||
if auto_refresh:
|
||||
def auto_refresher():
|
||||
observer = Observer()
|
||||
observer.schedule(Refresher(), identify_home(), recursive=False)
|
||||
observer.schedule(
|
||||
Refresher(), identify_home(), recursive=False)
|
||||
observer.start()
|
||||
while observer.is_alive():
|
||||
# call import func with timeout
|
||||
|
|
|
@ -35,7 +35,8 @@ class OnionrBlackList:
|
|||
return
|
||||
|
||||
def inBlacklist(self, data):
|
||||
hashed = bytesconverter.bytes_to_str(onionrcrypto.hashers.sha3_hash(data))
|
||||
hashed = bytesconverter.bytes_to_str(
|
||||
onionrcrypto.hashers.sha3_hash(data))
|
||||
retData = False
|
||||
|
||||
if not hashed.isalnum():
|
||||
|
@ -43,8 +44,10 @@ class OnionrBlackList:
|
|||
if len(hashed) > 64:
|
||||
raise Exception("Hashed data is too large")
|
||||
|
||||
for i in self._dbExecute("SELECT * FROM blacklist WHERE hash = ?", (hashed,)):
|
||||
retData = True # this only executes if an entry is present by that hash
|
||||
for i in self._dbExecute(
|
||||
"SELECT * FROM blacklist WHERE hash = ?", (hashed,)):
|
||||
# this only executes if an entry is present by that hash
|
||||
retData = True
|
||||
break
|
||||
|
||||
return retData
|
||||
|
@ -70,7 +73,8 @@ class OnionrBlackList:
|
|||
except AttributeError:
|
||||
raise TypeError("dataType must be int")
|
||||
|
||||
for i in self._dbExecute('SELECT * FROM blacklist WHERE dataType = ?', (dataType,)):
|
||||
for i in self._dbExecute(
|
||||
'SELECT * FROM blacklist WHERE dataType = ?', (dataType,)):
|
||||
if i[1] == dataType:
|
||||
if (curTime - i[2]) >= i[3]:
|
||||
deleteList.append(i[0])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue