misc formatting improvements
This commit is contained in:
parent
39650a4ca0
commit
a83351a73c
@ -1,9 +1,22 @@
|
|||||||
'''
|
"""Onionr - Private P2P Communication.
|
||||||
Onionr - Private P2P Communication
|
|
||||||
|
|
||||||
Misc client API endpoints too small to need their own file and that need access to the client api inst
|
Misc client API endpoints too small to need their own file and that need access to the client api inst
|
||||||
'''
|
"""
|
||||||
'''
|
# For the client creation thread
|
||||||
|
import threading
|
||||||
|
|
||||||
|
# For direct connection management HTTP endpoints
|
||||||
|
from flask import Response
|
||||||
|
# To make the direct connection management blueprint in the webUI
|
||||||
|
from flask import Blueprint
|
||||||
|
# Mainly to access the shared toomanyobjs object
|
||||||
|
from flask import g
|
||||||
|
import deadsimplekv
|
||||||
|
|
||||||
|
import filepaths
|
||||||
|
import onionrservices
|
||||||
|
from onionrservices import pool
|
||||||
|
"""
|
||||||
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 +29,8 @@
|
|||||||
|
|
||||||
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/>.
|
||||||
'''
|
"""
|
||||||
import threading # For the client creation thread
|
|
||||||
|
|
||||||
from flask import Response # For direct connection management HTTP endpoints
|
|
||||||
from flask import Blueprint # To make the direct connection management blueprint in the webUI
|
|
||||||
from flask import g # Mainly to access the shared toomanyobjs object
|
|
||||||
import deadsimplekv
|
|
||||||
|
|
||||||
import filepaths
|
|
||||||
import onionrservices
|
|
||||||
from onionrservices import pool
|
|
||||||
|
|
||||||
def _get_communicator(g):
|
def _get_communicator(g):
|
||||||
while True:
|
while True:
|
||||||
@ -35,9 +39,11 @@ def _get_communicator(g):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class DirectConnectionManagement:
|
class DirectConnectionManagement:
|
||||||
def __init__(self, client_api):
|
def __init__(self, client_api):
|
||||||
direct_conn_management_bp = Blueprint('direct_conn_management', __name__)
|
direct_conn_management_bp = Blueprint(
|
||||||
|
'direct_conn_management', __name__)
|
||||||
self.direct_conn_management_bp = direct_conn_management_bp
|
self.direct_conn_management_bp = direct_conn_management_bp
|
||||||
|
|
||||||
cache = deadsimplekv.DeadSimpleKV(filepaths.cached_storage)
|
cache = deadsimplekv.DeadSimpleKV(filepaths.cached_storage)
|
||||||
@ -54,7 +60,8 @@ class DirectConnectionManagement:
|
|||||||
def make_new_connection(pubkey):
|
def make_new_connection(pubkey):
|
||||||
communicator = _get_communicator(g)
|
communicator = _get_communicator(g)
|
||||||
resp = "pending"
|
resp = "pending"
|
||||||
if pubkey in communicator.shared_state.get(pool.ServicePool).bootstrap_pending:
|
if pubkey in communicator.shared_state.get(
|
||||||
|
pool.ServicePool).bootstrap_pending:
|
||||||
return Response(resp)
|
return Response(resp)
|
||||||
|
|
||||||
if pubkey in communicator.direct_connection_clients:
|
if pubkey in communicator.direct_connection_clients:
|
||||||
@ -63,7 +70,9 @@ class DirectConnectionManagement:
|
|||||||
"""Spawn a thread that will create the client and eventually add it to the
|
"""Spawn a thread that will create the client and eventually add it to the
|
||||||
communicator.active_services
|
communicator.active_services
|
||||||
"""
|
"""
|
||||||
threading.Thread(target=onionrservices.OnionrServices().create_client,
|
threading.Thread(
|
||||||
|
target=onionrservices.OnionrServices().create_client,
|
||||||
args=[pubkey, communicator], daemon=True).start()
|
args=[pubkey, communicator], daemon=True).start()
|
||||||
|
|
||||||
return Response(resp)
|
return Response(resp)
|
||||||
|
|
@ -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 BlacklistedBlock
|
||||||
from onionrexceptions import DiskAllocationReached
|
from onionrexceptions import DiskAllocationReached
|
||||||
from onionrexceptions import InvalidProof
|
from onionrexceptions import InvalidProof
|
||||||
@ -10,12 +9,13 @@ from onionrexceptions import InvalidMetadata
|
|||||||
import logger
|
import logger
|
||||||
from onionrutils import validatemetadata
|
from onionrutils import validatemetadata
|
||||||
from onionrutils import blockmetadata
|
from onionrutils import blockmetadata
|
||||||
|
from onionrutils import bytesconverter
|
||||||
from coredb import blockmetadb
|
from coredb import blockmetadb
|
||||||
import onionrstorage
|
import onionrstorage
|
||||||
import onionrcrypto as crypto
|
import onionrcrypto as crypto
|
||||||
from . import onionrblacklist
|
from . import onionrblacklist
|
||||||
|
|
||||||
'''
|
"""
|
||||||
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
|
||||||
@ -28,17 +28,14 @@ from . import onionrblacklist
|
|||||||
|
|
||||||
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/>.
|
||||||
'''
|
"""
|
||||||
|
|
||||||
|
|
||||||
def import_block_from_data(content):
|
def import_block_from_data(content):
|
||||||
blacklist = onionrblacklist.OnionrBlackList()
|
blacklist = onionrblacklist.OnionrBlackList()
|
||||||
ret_data = False
|
ret_data = False
|
||||||
|
|
||||||
try:
|
content = bytesconverter.str_to_bytes(content)
|
||||||
content = content.encode()
|
|
||||||
except AttributeError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
data_hash = crypto.hashers.sha3_hash(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}.',
|
logger.info(f'Imported block passed proof, saving: {data_hash}.',
|
||||||
terminal=True)
|
terminal=True)
|
||||||
try:
|
try:
|
||||||
blockHash = onionrstorage.set_data(content)
|
block_hash = onionrstorage.set_data(content)
|
||||||
except DiskAllocationReached:
|
except DiskAllocationReached:
|
||||||
logger.warn('Failed to save block due to full disk allocation')
|
logger.warn('Failed to save block due to full disk allocation')
|
||||||
raise
|
raise
|
||||||
else:
|
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
|
# caches block metadata values to block database
|
||||||
blockmetadata.process_block_metadata(blockHash)
|
blockmetadata.process_block_metadata(block_hash)
|
||||||
ret_data = blockHash
|
ret_data = block_hash
|
||||||
else:
|
else:
|
||||||
raise InvalidProof
|
raise InvalidProof
|
||||||
else:
|
else:
|
||||||
|
@ -41,7 +41,8 @@ class BlockList:
|
|||||||
if auto_refresh:
|
if auto_refresh:
|
||||||
def auto_refresher():
|
def auto_refresher():
|
||||||
observer = Observer()
|
observer = Observer()
|
||||||
observer.schedule(Refresher(), identify_home(), recursive=False)
|
observer.schedule(
|
||||||
|
Refresher(), identify_home(), recursive=False)
|
||||||
observer.start()
|
observer.start()
|
||||||
while observer.is_alive():
|
while observer.is_alive():
|
||||||
# call import func with timeout
|
# call import func with timeout
|
||||||
|
@ -35,7 +35,8 @@ class OnionrBlackList:
|
|||||||
return
|
return
|
||||||
|
|
||||||
def inBlacklist(self, data):
|
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
|
retData = False
|
||||||
|
|
||||||
if not hashed.isalnum():
|
if not hashed.isalnum():
|
||||||
@ -43,8 +44,10 @@ class OnionrBlackList:
|
|||||||
if len(hashed) > 64:
|
if len(hashed) > 64:
|
||||||
raise Exception("Hashed data is too large")
|
raise Exception("Hashed data is too large")
|
||||||
|
|
||||||
for i in self._dbExecute("SELECT * FROM blacklist WHERE hash = ?", (hashed,)):
|
for i in self._dbExecute(
|
||||||
retData = True # this only executes if an entry is present by that hash
|
"SELECT * FROM blacklist WHERE hash = ?", (hashed,)):
|
||||||
|
# this only executes if an entry is present by that hash
|
||||||
|
retData = True
|
||||||
break
|
break
|
||||||
|
|
||||||
return retData
|
return retData
|
||||||
@ -70,7 +73,8 @@ class OnionrBlackList:
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise TypeError("dataType must be int")
|
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 i[1] == dataType:
|
||||||
if (curTime - i[2]) >= i[3]:
|
if (curTime - i[2]) >= i[3]:
|
||||||
deleteList.append(i[0])
|
deleteList.append(i[0])
|
||||||
|
Loading…
Reference in New Issue
Block a user