From e0f59784b1800dd01a707b1d20c330112e68179b Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Wed, 14 Oct 2020 00:07:41 +0000 Subject: [PATCH] Fix mixmate and sneakernet --- src/communicatorutils/uploadblocks/mixmate/__init__.py | 5 ++++- src/onionrblocks/insert/main.py | 3 ++- src/sneakernet/__init__.py | 7 +++++-- static-data/default-plugins/pms/loadinbox.py | 10 ++++++++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/communicatorutils/uploadblocks/mixmate/__init__.py b/src/communicatorutils/uploadblocks/mixmate/__init__.py index 446ac44a..a3ddcfda 100644 --- a/src/communicatorutils/uploadblocks/mixmate/__init__.py +++ b/src/communicatorutils/uploadblocks/mixmate/__init__.py @@ -39,7 +39,10 @@ def block_mixer(upload_list: List[onionrtypes.BlockHash], """ bl = onionrblockapi.Block(block_to_mix) - if time.time() - bl.claimedTime > onionrvalues.BLOCK_POOL_MAX_AGE: + try: + if time.time() - bl.claimedTime > onionrvalues.BLOCK_POOL_MAX_AGE: raise ValueError + except TypeError: + pass if block_to_mix: upload_list.append(block_to_mix) diff --git a/src/onionrblocks/insert/main.py b/src/onionrblocks/insert/main.py index ebae296e..971ac1f5 100644 --- a/src/onionrblocks/insert/main.py +++ b/src/onionrblocks/insert/main.py @@ -183,8 +183,9 @@ def insert_block(data: Union[str, bytes], header: str = 'txt', # if peer is already known pass else: + logger.warn(f"{asymPeer} is not a valid key to make a block to") raise onionrexceptions.InvalidPubkey( - asymPeer + ' is not a valid base32 encoded ed25519 key') + 'tried to make block to invalid key is not a valid base32 encoded ed25519 key') # compile metadata metadata['meta'] = jsonMeta diff --git a/src/sneakernet/__init__.py b/src/sneakernet/__init__.py index 65439159..5d9be61d 100644 --- a/src/sneakernet/__init__.py +++ b/src/sneakernet/__init__.py @@ -37,8 +37,11 @@ class _Importer(FileSystemEventHandler): def on_created(event): if not event.src_path.endswith(BLOCK_EXPORT_FILE_EXT): return - with open(event.src_path, 'rb') as block_file: - block_data = block_file.read() + try: + with open(event.src_path, 'rb') as block_file: + block_data = block_file.read() + except FileNotFoundError: + return os.remove(event.src_path) try: import_block_from_data(block_data) diff --git a/static-data/default-plugins/pms/loadinbox.py b/static-data/default-plugins/pms/loadinbox.py index cda1e9e6..6a215f71 100755 --- a/static-data/default-plugins/pms/loadinbox.py +++ b/static-data/default-plugins/pms/loadinbox.py @@ -21,7 +21,7 @@ import deadsimplekv as simplekv along with this program. If not, see . """ - +inbox_cache = {} def load_inbox(): inbox_list = [] deleted = simplekv.DeadSimpleKV(identifyhome.identify_home() + '/mailcache.dat').get('deleted_mail') @@ -29,8 +29,14 @@ def load_inbox(): deleted = [] for blockHash in blockmetadb.get_blocks_by_type('pm'): + if blockHash in deleted: + continue + if blockHash in inbox_cache: + inbox_list.append(blockHash) + continue block = onionrblockapi.Block(blockHash) block.decrypt() - if block.decrypted and reconstructhash.deconstruct_hash(blockHash) not in deleted: + if block.decrypted and reconstructhash.deconstruct_hash(blockHash): + inbox_cache[blockHash] = True inbox_list.append(blockHash) return inbox_list