diff --git a/src/communicator/__init__.py b/src/communicator/__init__.py index 3861ece5..dcb5525f 100755 --- a/src/communicator/__init__.py +++ b/src/communicator/__init__.py @@ -71,6 +71,7 @@ class OnionrCommunicatorDaemon: self.kv.put('dbTimestamps', {}) self.kv.put('blocksToUpload', []) self.kv.put('cooldownPeer', {}) + self.kv.put('generating_blocks', []) if config.get('general.offline_mode', False): self.isOnline = False @@ -93,10 +94,6 @@ class OnionrCommunicatorDaemon: # list of peer's profiles (onionrpeers.PeerProfile instances) self.peerProfiles = [] - self.announceProgress = {} - - self.generating_blocks = [] - # amount of threads running by name, used to prevent too many self.threadCounts = {} diff --git a/src/communicator/daemoneventhooks/removefrominsertqueue.py b/src/communicator/daemoneventhooks/removefrominsertqueue.py index ff22b1e7..d135ccd9 100644 --- a/src/communicator/daemoneventhooks/removefrominsertqueue.py +++ b/src/communicator/daemoneventhooks/removefrominsertqueue.py @@ -4,6 +4,7 @@ Remove block hash from daemon's upload list. """ from typing import TYPE_CHECKING if TYPE_CHECKING: + from deadsimplekv import DeadSimpleKV from communicator import OnionrCommunicatorDaemon from onionrtypes import BlockHash """ @@ -25,7 +26,8 @@ if TYPE_CHECKING: def remove_from_insert_queue(comm_inst: "OnionrCommunicatorDaemon", b_hash: "BlockHash"): """Remove block hash from daemon's upload list.""" + kv: "DeadSimpleKV" = comm_inst.shared_state.get_by_string("DeadSimpleKV") try: - comm_inst.generating_blocks.remove(b_hash) + kv.get('generating_blocks').remove(b_hash) except ValueError: pass diff --git a/src/communicator/onlinepeers/clearofflinepeer.py b/src/communicator/onlinepeers/clearofflinepeer.py index a8f14b75..d5b1bbd2 100644 --- a/src/communicator/onlinepeers/clearofflinepeer.py +++ b/src/communicator/onlinepeers/clearofflinepeer.py @@ -25,8 +25,9 @@ if TYPE_CHECKING: def clear_offline_peer(comm_inst: 'OnionrCommunicatorDaemon'): """Remove the longest offline peer to retry later.""" + kv: "DeadSimpleKV" = comm_inst.shared_state.get_by_string("DeadSimpleKV") try: - removed = comm_inst..pop(0) + removed = kv.get('offlinePeers').pop(0) except IndexError: pass else: diff --git a/src/communicatorutils/announcenode.py b/src/communicatorutils/announcenode.py index 052486ae..e4580f6d 100755 --- a/src/communicatorutils/announcenode.py +++ b/src/communicatorutils/announcenode.py @@ -44,8 +44,7 @@ def announce_node(daemon): if daemon.config.get('general.security_level', 0) == 0: # Announce to random online peers for i in kv.get('onlinePeers'): - if i not in kv.get('announceCache') and\ - i not in daemon.announceProgress: + if i not in kv.get('announceCache'): peer = i break else: diff --git a/src/httpapi/insertblock.py b/src/httpapi/insertblock.py index ce25b968..d0aac3b8 100644 --- a/src/httpapi/insertblock.py +++ b/src/httpapi/insertblock.py @@ -35,18 +35,17 @@ def client_api_insert_block(): insert_data: JSONSerializable = request.get_json(force=True) message = insert_data['message'] message_hash = bytesconverter.bytes_to_str(hashers.sha3_hash(message)) + kv: 'DeadSimpleKV' = g.too_many.get_by_string('DeadSimpleKV') # Detect if message (block body) is not specified if type(message) is None: return 'failure due to unspecified message', 400 # Detect if block with same message is already being inserted - if message_hash in g.too_many.get_by_string( - "OnionrCommunicatorDaemon").generating_blocks: + if message_hash in kv.get('generating_blocks'): return 'failure due to duplicate insert', 400 else: - g.too_many.get_by_string( - "OnionrCommunicatorDaemon").generating_blocks.append(message_hash) + kv.get('generating_blocks').append(message_hash) encrypt_type = '' sign = True