Moved blocksToUpload to KV to further reduce coupling
This commit is contained in:
parent
97a5f50271
commit
10c1cd7803
8 changed files with 28 additions and 16 deletions
|
@ -68,6 +68,7 @@ class OnionrCommunicatorDaemon:
|
|||
self.kv.put('announceCache', {})
|
||||
self.kv.put('newPeers', [])
|
||||
self.kv.put('dbTimestamps', {})
|
||||
self.kv.put('blocksToUpload', [])
|
||||
|
||||
if config.get('general.offline_mode', False):
|
||||
self.isOnline = False
|
||||
|
@ -78,8 +79,6 @@ class OnionrCommunicatorDaemon:
|
|||
# initialize core with Tor socks port being 3rd argument
|
||||
self.proxyPort = shared_state.get(NetController).socksPort
|
||||
|
||||
# Upload information, list of blocks to upload
|
||||
self.blocksToUpload = []
|
||||
self.upload_session_manager = self.shared_state.get(
|
||||
uploadblocks.sessionmanager.BlockUploadSessionManager)
|
||||
self.shared_state.share_object()
|
||||
|
|
|
@ -15,6 +15,7 @@ from communicatorutils import restarttor
|
|||
|
||||
if TYPE_CHECKING:
|
||||
from toomanyobjs import TooMany
|
||||
from deadsimplekv import DeadSimpleKV
|
||||
from communicator import OnionrCommunicatorDaemon
|
||||
from httpapi.daemoneventsapi import DaemonEventsBP
|
||||
from onionrtypes import BlockHash
|
||||
|
@ -45,6 +46,7 @@ def daemon_event_handlers(shared_state: 'TooMany'):
|
|||
comm_inst = _get_inst('OnionrCommunicatorDaemon')
|
||||
public_api: 'PublicAPI' = _get_inst('PublicAPI')
|
||||
events_api: 'DaemonEventsBP' = _get_inst('DaemonEventsBP')
|
||||
kv: 'DeadSimpleKV' = _get_inst('DeadSimpleKV')
|
||||
|
||||
def remove_from_insert_queue_wrapper(block_hash: 'BlockHash'):
|
||||
remove_from_insert_queue(comm_inst, block_hash)
|
||||
|
@ -59,7 +61,7 @@ def daemon_event_handlers(shared_state: 'TooMany'):
|
|||
raise ValueError
|
||||
public_api.hideBlocks.append(block)
|
||||
try:
|
||||
mixmate.block_mixer(comm_inst.blocksToUpload, block)
|
||||
mixmate.block_mixer(kv.get('blocksToUpload'), block)
|
||||
except ValueError:
|
||||
pass
|
||||
return "removed"
|
||||
|
|
|
@ -13,6 +13,7 @@ import filepaths
|
|||
from onionrutils import localcommand
|
||||
if TYPE_CHECKING:
|
||||
from communicator import OnionrCommunicatorDaemon
|
||||
from deadsimplekv import DeadSimpleKV
|
||||
"""
|
||||
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
|
||||
|
@ -47,19 +48,20 @@ class UploadQueue:
|
|||
self.communicator = communicator
|
||||
cache: deadsimplekv.DeadSimpleKV = deadsimplekv.DeadSimpleKV(
|
||||
UPLOAD_MEMORY_FILE)
|
||||
self.kv: "DeadSimpleKV" = communicator.shared_state.get_by_string("DeadSimpleKV")
|
||||
self.store_obj = cache
|
||||
cache = cache.get('uploads')
|
||||
if cache is None:
|
||||
cache = []
|
||||
|
||||
_add_to_hidden_blocks(cache)
|
||||
self.communicator.blocksToUpload.extend(cache)
|
||||
self.kv.get('blocksToUpload').extend(cache)
|
||||
|
||||
atexit.register(self.save)
|
||||
|
||||
def save(self):
|
||||
"""Save to disk on shutdown or if called manually."""
|
||||
bl: deadsimplekv.DeadSimpleKV = self.communicator.blocksToUpload
|
||||
bl: deadsimplekv.DeadSimpleKV = self.kv.get('blocksToUpload')
|
||||
if len(bl) == 0:
|
||||
try:
|
||||
os.remove(UPLOAD_MEMORY_FILE)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue