Moved blocksToUpload to KV to further reduce coupling

This commit is contained in:
Kevin 2020-07-26 19:02:39 -05:00
parent 97a5f50271
commit 10c1cd7803
8 changed files with 28 additions and 16 deletions

View file

@ -4,6 +4,10 @@ Cleanup old Onionr blocks and forward secrecy keys using the communicator.
Ran from a communicator timer usually
"""
import sqlite3
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from deadsimplekv import DeadSimpleKV
import logger
from onionrusers import onionrusers
@ -32,8 +36,9 @@ storage_counter = StorageCounter()
def __remove_from_upload(comm_inst, block_hash: str):
kv: "DeadSimpleKV" = comm_inst.shared_state.get_by_string("DeadSimpleKV")
try:
comm_inst.blocksToUpload.remove(block_hash)
kv.get('blocksToUpload').remove(block_hash)
except ValueError:
pass

View file

@ -2,8 +2,13 @@
Lookup new blocks with the communicator using a random connected peer
"""
from typing import TYPE_CHECKING
from gevent import time
if TYPE_CHECKING:
from deadsimplekv import DeadSimpleKV
import logger
import onionrproofs
from onionrutils import stringvalidators, epoch

View file

@ -47,8 +47,8 @@ def upload_blocks_from_communicator(comm_inst: 'OnionrCommunicatorDaemon'):
sessionmanager.BlockUploadSessionManager)
tried_peers: UserID = []
finishedUploads = []
comm_inst.blocksToUpload = onionrcrypto.cryptoutils.random_shuffle(
comm_inst.blocksToUpload)
kv.put('blocksToUpload', onionrcrypto.cryptoutils.random_shuffle(
kv.get('blocksToUpload')))
def remove_from_hidden(bl):
sleep(60)
@ -58,8 +58,8 @@ def upload_blocks_from_communicator(comm_inst: 'OnionrCommunicatorDaemon'):
except ValueError:
pass
if len(comm_inst.blocksToUpload) != 0:
for bl in comm_inst.blocksToUpload:
if len(kv.get('blocksToUpload')) != 0:
for bl in kv.get('blocksToUpload'):
if not stringvalidators.validate_hash(bl):
logger.warn('Requested to upload invalid block', terminal=True)
comm_inst.decrementThreadCount(TIMER_NAME)
@ -116,7 +116,7 @@ def upload_blocks_from_communicator(comm_inst: 'OnionrCommunicatorDaemon'):
session_manager.clean_session()
for x in finishedUploads:
try:
comm_inst.blocksToUpload.remove(x)
kv.get('blocksToUpload').remove(x)
comm_inst.shared_state.get_by_string(
'PublicAPI').hideBlocks.remove(x)

View file

@ -116,11 +116,11 @@ class BlockUploadSessionManager:
# Remove the blocks from the sessions, upload list,
# and waitforshare list
try:
comm_inst.blocksToUpload.remove(
kv.get('blocksToUpload').remove(
reconstructhash.reconstruct_hash(sess.block_hash))
except ValueError:
pass
try:
comm_inst.blocksToUpload.remove(sess.block_hash)
kv.get('blocksToUpload').remove(sess.block_hash)
except ValueError:
pass