Removed use of communicator's storagecounter to reduce coupling

master
Kevin 2020-07-24 03:24:41 -05:00
parent b4be481f81
commit 47013431d2
5 changed files with 15 additions and 15 deletions

View File

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Made storagecounter use a watchdog (inotify) instead of excessive file reads * Made storagecounter use a watchdog (inotify) instead of excessive file reads
* Bumped urllib3 to 1.25.10 * Bumped urllib3 to 1.25.10
* Removed use of communicator's storagecounter to reduce coupling
## [5.0.0] - 2020-07-23 ## [5.0.0] - 2020-07-23

View File

@ -3,9 +3,7 @@
This file contains both the OnionrCommunicate class for This file contains both the OnionrCommunicate class for
communcating with peers and code to operate as a daemon, communcating with peers and code to operate as a daemon,
getting commands from the command queue database getting commands from the command queue database
(see core.Core.daemonQueue)
""" """
import os
import time import time
import config import config
@ -24,14 +22,10 @@ from communicatorutils import announcenode, deniableinserts
from communicatorutils import cooldownpeer from communicatorutils import cooldownpeer
from communicatorutils import housekeeping from communicatorutils import housekeeping
from communicatorutils import netcheck from communicatorutils import netcheck
from onionrutils import localcommand
from onionrutils import epoch from onionrutils import epoch
from onionrcommands.openwebinterface import get_url from onionrcommands.openwebinterface import get_url
from etc import humanreadabletime from etc import humanreadabletime
import onionrservices import onionrservices
import filepaths
from onionrblocks import storagecounter
from coredb import dbfiles
from netcontroller import NetController from netcontroller import NetController
from . import bootstrappeers from . import bootstrappeers
from . import daemoneventhooks from . import daemoneventhooks
@ -62,7 +56,6 @@ class OnionrCommunicatorDaemon:
# configure logger and stuff # configure logger and stuff
self.config = config self.config = config
self.storage_counter = storagecounter.StorageCounter()
self.isOnline = True # Assume we're connected to the internet self.isOnline = True # Assume we're connected to the internet
self.shared_state = shared_state # TooManyObjects module self.shared_state = shared_state # TooManyObjects module
@ -153,11 +146,13 @@ class OnionrCommunicatorDaemon:
# Timer to reset the longest offline peer # Timer to reset the longest offline peer
# so contact can be attempted again # so contact can be attempted again
OnionrCommunicatorTimers( OnionrCommunicatorTimers(
self, onlinepeers.clear_offline_peer, 58, my_args=[self], max_threads=1) self, onlinepeers.clear_offline_peer, 58, my_args=[self],
max_threads=1)
# Timer to cleanup old blocks # Timer to cleanup old blocks
blockCleanupTimer = OnionrCommunicatorTimers( blockCleanupTimer = OnionrCommunicatorTimers(
self, housekeeping.clean_old_blocks, 20, my_args=[self], max_threads=1) self, housekeeping.clean_old_blocks, 20, my_args=[self],
max_threads=1)
# Timer to discover new peers # Timer to discover new peers
OnionrCommunicatorTimers( OnionrCommunicatorTimers(
@ -243,7 +238,6 @@ class OnionrCommunicatorDaemon:
'First run detected. Run openhome to get setup.', 'First run detected. Run openhome to get setup.',
terminal=True) terminal=True)
get_url() get_url()
while not config.get('onboarding.done', True) and \ while not config.get('onboarding.done', True) and \
not self.shutdown: not self.shutdown:

View File

@ -12,7 +12,7 @@ from gevent import spawn
import onionrexceptions import onionrexceptions
import logger import logger
import onionrpeers import onionrpeers
import communicator
from communicator import peeraction from communicator import peeraction
from communicator import onlinepeers from communicator import onlinepeers
from onionrutils import blockmetadata from onionrutils import blockmetadata
@ -39,11 +39,12 @@ from . import shoulddownload
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 download_blocks_from_communicator(comm_inst: "OnionrCommunicatorDaemon"): def download_blocks_from_communicator(comm_inst: "OnionrCommunicatorDaemon"):
"""Use communicator instance to download blocks in the comms's queue""" """Use communicator instance to download blocks in the comms's queue"""
blacklist = onionrblacklist.OnionrBlackList() blacklist = onionrblacklist.OnionrBlackList()
storage_counter = storagecounter.StorageCounter()
LOG_SKIP_COUNT = 50 # for how many iterations we skip logging the counter LOG_SKIP_COUNT = 50 # for how many iterations we skip logging the counter
count: int = 0 count: int = 0
metadata_validation_result: bool = False metadata_validation_result: bool = False
@ -51,7 +52,6 @@ def download_blocks_from_communicator(comm_inst: "OnionrCommunicatorDaemon"):
for blockHash in list(comm_inst.blockQueue): for blockHash in list(comm_inst.blockQueue):
count += 1 count += 1
triedQueuePeers = [] # List of peers we've tried for a block
try: try:
blockPeers = list(comm_inst.blockQueue[blockHash]) blockPeers = list(comm_inst.blockQueue[blockHash])
except KeyError: except KeyError:

View File

@ -12,6 +12,7 @@ from coredb import blockmetadb, dbfiles
import onionrstorage import onionrstorage
from onionrstorage import removeblock from onionrstorage import removeblock
from onionrblocks import onionrblacklist from onionrblocks import onionrblacklist
from onionrblocks.storagecounter import StorageCounter
""" """
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
@ -27,6 +28,8 @@ from onionrblocks import onionrblacklist
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()
def __remove_from_upload(comm_inst, block_hash: str): def __remove_from_upload(comm_inst, block_hash: str):
try: try:
@ -46,7 +49,7 @@ def clean_old_blocks(comm_inst):
__remove_from_upload(comm_inst, bHash) __remove_from_upload(comm_inst, bHash)
logger.info('Deleted block: %s' % (bHash,)) logger.info('Deleted block: %s' % (bHash,))
while comm_inst.storage_counter.is_full(): while storage_counter.is_full():
try: try:
oldest = blockmetadb.get_block_list()[0] oldest = blockmetadb.get_block_list()[0]
except IndexError: except IndexError:

View File

@ -14,6 +14,7 @@ from onionrblocks import onionrblacklist
import onionrexceptions import onionrexceptions
import config import config
from etc import onionrvalues from etc import onionrvalues
from onionrblocks.storagecounter import StorageCounter
""" """
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
@ -30,6 +31,7 @@ from etc import onionrvalues
""" """
blacklist = onionrblacklist.OnionrBlackList() blacklist = onionrblacklist.OnionrBlackList()
storage_counter = StorageCounter()
def lookup_blocks_from_communicator(comm_inst): def lookup_blocks_from_communicator(comm_inst):
@ -51,7 +53,7 @@ def lookup_blocks_from_communicator(comm_inst):
if not comm_inst.isOnline: if not comm_inst.isOnline:
break break
# check if disk allocation is used # check if disk allocation is used
if comm_inst.storage_counter.is_full(): if storage_counter.is_full():
logger.debug( logger.debug(
'Not looking up new blocks due to maximum amount of disk used') 'Not looking up new blocks due to maximum amount of disk used')
break break