Removed use of communicator's storagecounter to reduce coupling

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

View file

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

View file

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

View file

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