Use init-time creation only of StorageCounter to use less inotify instances

This commit is contained in:
Kevin Froman 2020-08-21 09:56:49 -05:00
parent bbc9646a25
commit cd0b69b03f
4 changed files with 7 additions and 5 deletions

View File

@ -36,6 +36,7 @@ from onionrtypes import UserIDSecretKey
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/>.
""" """
storage_counter = storagecounter.StorageCounter()
def _check_upload_queue(): 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_private_key = crypto.priv_key
our_pub_key = crypto.pub_key our_pub_key = crypto.pub_key
storage_counter = storagecounter.StorageCounter()
allocationReachedMessage = 'Cannot insert block, disk allocation reached.' allocationReachedMessage = 'Cannot insert block, disk allocation reached.'
if storage_counter.is_full(): if storage_counter.is_full():
logger.error(allocationReachedMessage) logger.error(allocationReachedMessage)

View File

@ -28,11 +28,13 @@ from .blocknoncestart import BLOCK_NONCE_START_INT
""" """
config.reload() config.reload()
storage_counter = storagecounter.StorageCounter()
def getDifficultyModifier(): def getDifficultyModifier():
"""returns the difficulty modifier for block storage based """returns the difficulty modifier for block storage based
on a variety of factors, currently only disk use. 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 difficultyIncrease = math.floor(4 * percentUse) # difficulty increase is a step function
return difficultyIncrease return difficultyIncrease

View File

@ -25,6 +25,7 @@ from etc.onionrvalues import DATABASE_LOCK_TIMEOUT
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/>.
""" """
storage_counter = storagecounter.StorageCounter()
def remove_block(block): def remove_block(block):
@ -42,6 +43,6 @@ def remove_block(block):
conn.commit() conn.commit()
conn.close() conn.close()
dataSize = sys.getsizeof(onionrstorage.getData(block)) dataSize = sys.getsizeof(onionrstorage.getData(block))
storagecounter.StorageCounter().remove_bytes(dataSize) storage_counter.remove_bytes(dataSize)
else: else:
raise onionrexceptions.InvalidHexHash raise onionrexceptions.InvalidHexHash

View File

@ -27,11 +27,11 @@ from etc.onionrvalues import DATABASE_LOCK_TIMEOUT
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/>.
""" """
storage_counter = storagecounter.StorageCounter()
def set_data(data) -> str: def set_data(data) -> str:
"""Set the data assciated with a hash.""" """Set the data assciated with a hash."""
storage_counter = storagecounter.StorageCounter()
data = data data = data
dataSize = sys.getsizeof(data) dataSize = sys.getsizeof(data)
nonce_hash = crypto.hashers.sha3_hash( nonce_hash = crypto.hashers.sha3_hash(