From cd0b69b03fdbfba4dc96d798550f4c55484a235c Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Fri, 21 Aug 2020 09:56:49 -0500 Subject: [PATCH] Use init-time creation only of StorageCounter to use less inotify instances --- src/onionrblocks/insert/main.py | 3 +-- src/onionrproofs/__init__.py | 4 +++- src/onionrstorage/removeblock.py | 3 ++- src/onionrstorage/setdata.py | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/onionrblocks/insert/main.py b/src/onionrblocks/insert/main.py index 360b83ff..81e07e6f 100644 --- a/src/onionrblocks/insert/main.py +++ b/src/onionrblocks/insert/main.py @@ -36,6 +36,7 @@ from onionrtypes import UserIDSecretKey You should have received a copy of the GNU General Public License along with this program. If not, see . """ +storage_counter = storagecounter.StorageCounter() def _check_upload_queue(): @@ -73,8 +74,6 @@ def insert_block(data: Union[str, bytes], header: str = 'txt', our_private_key = crypto.priv_key our_pub_key = crypto.pub_key - storage_counter = storagecounter.StorageCounter() - allocationReachedMessage = 'Cannot insert block, disk allocation reached.' if storage_counter.is_full(): logger.error(allocationReachedMessage) diff --git a/src/onionrproofs/__init__.py b/src/onionrproofs/__init__.py index d7172efd..c5cb61f6 100755 --- a/src/onionrproofs/__init__.py +++ b/src/onionrproofs/__init__.py @@ -28,11 +28,13 @@ from .blocknoncestart import BLOCK_NONCE_START_INT """ config.reload() +storage_counter = storagecounter.StorageCounter() + def getDifficultyModifier(): """returns the difficulty modifier for block storage based on a variety of factors, currently only disk use. """ - percentUse = storagecounter.StorageCounter().get_percent() + percentUse = storage_counter.get_percent() difficultyIncrease = math.floor(4 * percentUse) # difficulty increase is a step function return difficultyIncrease diff --git a/src/onionrstorage/removeblock.py b/src/onionrstorage/removeblock.py index d6ab4272..337c8f3a 100644 --- a/src/onionrstorage/removeblock.py +++ b/src/onionrstorage/removeblock.py @@ -25,6 +25,7 @@ from etc.onionrvalues import DATABASE_LOCK_TIMEOUT You should have received a copy of the GNU General Public License along with this program. If not, see . """ +storage_counter = storagecounter.StorageCounter() def remove_block(block): @@ -42,6 +43,6 @@ def remove_block(block): conn.commit() conn.close() dataSize = sys.getsizeof(onionrstorage.getData(block)) - storagecounter.StorageCounter().remove_bytes(dataSize) + storage_counter.remove_bytes(dataSize) else: raise onionrexceptions.InvalidHexHash diff --git a/src/onionrstorage/setdata.py b/src/onionrstorage/setdata.py index 4efe3e40..fb07ef9f 100644 --- a/src/onionrstorage/setdata.py +++ b/src/onionrstorage/setdata.py @@ -27,11 +27,11 @@ from etc.onionrvalues import DATABASE_LOCK_TIMEOUT You should have received a copy of the GNU General Public License along with this program. If not, see . """ +storage_counter = storagecounter.StorageCounter() 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(