From 93338e3fb91ea6ecc57c8b50cb452d319d5e564f Mon Sep 17 00:00:00 2001 From: Arinerron Date: Mon, 14 May 2018 23:16:55 -0700 Subject: [PATCH] Add repository support --- onionr/communicator.py | 2 +- .../default-plugins/pluginmanager/main.py | 55 ++++++++++++++++++- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/onionr/communicator.py b/onionr/communicator.py index a71710e9..4afdbb0d 100755 --- a/onionr/communicator.py +++ b/onionr/communicator.py @@ -563,7 +563,7 @@ class OnionrCommunicate: continue else: if (('sig' in blockMetadata) and ('id' in blockMeta2)): # id doesn't exist in blockMeta2, so this won't workin the first place - + #blockData = json.dumps(blockMetadata['meta']) + blockMetadata[blockMetadata.rfind(b'}') + 1:] creator = self._utils.getPeerByHashId(blockMeta2['id']) diff --git a/onionr/static-data/default-plugins/pluginmanager/main.py b/onionr/static-data/default-plugins/pluginmanager/main.py index a3a454d6..3fa6373c 100644 --- a/onionr/static-data/default-plugins/pluginmanager/main.py +++ b/onionr/static-data/default-plugins/pluginmanager/main.py @@ -483,11 +483,62 @@ def commandSearchPlugin(): return True def commandAddRepository(): - logger.info('This feature has not been created yet. Please check back later.') + if len(sys.argv) >= 3: + check() + + blockhash = sys.argv[2] + + if pluginapi.get_utils().validateHash(blockhash): + if pluginapi.get_utils().hasBlock(blockhash): + try: + blockContent = pluginapi.get_core().getData(blockhash) + blockContent = blockContent[blockContent.rfind(b'\n') + 1:].decode() + blockContent = json.loads(blockContent) + + pluginslist = dict() + + for pluginname, distributor in blockContent['plugins'].items(): + if pluginapi.get_utils().validatePubKey(distributor): + pluginslist[pluginname] = distributor + + logger.debug('Found %s records in repository.' % len(pluginslist)) + + if len(pluginslist) != 0: + addRepository(blockhash, pluginslist) + logger.info('Successfully added repository.') + else: + logger.error('Repository contains no records, not importing.') + except Exception as e: + logger.error('Failed to parse block.', error = e) + else: + logger.error('Block hash not found. Perhaps it has not been synced yet?') + logger.debug('Is valid hash, but does not belong to a known block.') + else: + logger.error('Unknown data "%s"; must be block hash.' % str(pkobh)) + else: + logger.info(sys.argv[0] + ' ' + sys.argv[1] + ' [block hash]') + return True def commandRemoveRepository(): - logger.info('This feature has not been created yet. Please check back later.') + if len(sys.argv) >= 3: + check() + + blockhash = sys.argv[2] + + if pluginapi.get_utils().validateHash(blockhash): + if blockhash in getRepositories(): + try: + removeRepository(blockhash) + except Exception as e: + logger.error('Failed to parse block.', error = e) + else: + logger.error('Repository has not been imported, nothing to remove.') + else: + logger.error('Unknown data "%s"; must be block hash.' % str(pkobh)) + else: + logger.info(sys.argv[0] + ' ' + sys.argv[1] + ' [block hash]') + return True def commandPublishPlugin():