From cc703fc4048f00419f19b0f746049a7dda7f7640 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sun, 15 Nov 2020 18:52:52 +0000 Subject: [PATCH] progress removing communicator timers --- src/communicator/__init__.py | 14 ++++++-------- src/communicatorutils/cooldownpeer.py | 9 ++++----- src/communicatorutils/lookupadders.py | 3 +-- src/sneakernet/__init__.py | 5 +++-- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/communicator/__init__.py b/src/communicator/__init__.py index 788d7c6f..db79a6b2 100755 --- a/src/communicator/__init__.py +++ b/src/communicator/__init__.py @@ -98,19 +98,17 @@ class OnionrCommunicatorDaemon: add_onionr_thread(onlinepeers.clear_offline_peer, [self.kv], 58) add_onionr_thread( - housekeeping.clean_old_blocks, self.shared_state, 20, 1) + housekeeping.clean_old_blocks, [self.shared_state], 20, 1) - # Timer to discover new peers - OnionrCommunicatorTimers( - self, lookupadders.lookup_new_peer_transports_with_communicator, - 60, requires_peer=True, my_args=[shared_state], max_threads=2) + # Discover new peers + add_onionr_thread( + lookupadders.lookup_new_peer_transports_with_communicator, + [shared_state], 60, 3) # Timer for adjusting which peers # we actively communicate to at any given time, # to avoid over-using peers - OnionrCommunicatorTimers( - self, cooldownpeer.cooldown_peer, 30, - my_args=[self], requires_peer=True) + add_onionr_thread(cooldownpeer.cooldown_peer, [self.shared_state], 30, 60) # Timer to read the upload queue and upload the entries to peers OnionrCommunicatorTimers( diff --git a/src/communicatorutils/cooldownpeer.py b/src/communicatorutils/cooldownpeer.py index 639d92aa..0e57db8b 100755 --- a/src/communicatorutils/cooldownpeer.py +++ b/src/communicatorutils/cooldownpeer.py @@ -25,10 +25,10 @@ if TYPE_CHECKING: """ -def cooldown_peer(comm_inst): +def cooldown_peer(shared_state): """Randomly add an online peer to cooldown, so we can connect a new one.""" - kv: "DeadSimpleKV" = comm_inst.shared_state.get_by_string("DeadSimpleKV") - config = comm_inst.config + kv: "DeadSimpleKV" = shared_state.get_by_string("DeadSimpleKV") + config = shared_state.get_by_string("OnionrCommunicatorDaemon").config online_peer_amount = len(kv.get('onlinePeers')) minTime = 300 cooldown_time = 600 @@ -55,7 +55,6 @@ def cooldown_peer(comm_inst): except ValueError: break else: - onlinepeers.remove_online_peer(comm_inst, to_cool) + onlinepeers.remove_online_peer(kv, to_cool) kv.get('cooldownPeer')[to_cool] = epoch.get_epoch() - comm_inst.decrementThreadCount('cooldown_peer') diff --git a/src/communicatorutils/lookupadders.py b/src/communicatorutils/lookupadders.py index 76d18953..788ffa12 100755 --- a/src/communicatorutils/lookupadders.py +++ b/src/communicatorutils/lookupadders.py @@ -63,5 +63,4 @@ def lookup_new_peer_transports_with_communicator(shared_state): newPeers.remove(x) except ValueError: pass - kv.get('newPeers').extend(newPeers) - shared_state.get_by_string("OnionrCommunicatorDaemon").decrementThreadCount('lookup_new_peer_transports_with_communicator') + kv.get('newPeers').extend(newPeers) \ No newline at end of file diff --git a/src/sneakernet/__init__.py b/src/sneakernet/__init__.py index 0d6f8a98..9c78b568 100644 --- a/src/sneakernet/__init__.py +++ b/src/sneakernet/__init__.py @@ -45,9 +45,10 @@ class _Importer(FileSystemEventHandler): os.remove(event.src_path) try: import_block_from_data(block_data) - except( + except( # noqa onionrexceptions.DataExists, - onionrexceptions.BlockMetaEntryExists) as _: + onionrexceptions.BlockMetaEntryExists, + onionrexceptions.InvalidMetadata) as _: return if block_data_location in event.src_path: try: