From ff5bdd62f24a2b24c7568934b56ee9e9c511cc20 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sat, 5 May 2018 01:19:25 -0500 Subject: [PATCH] work on fixing mallable metadata & thread work --- onionr/communicator.py | 29 ++++++++++++++++------------- onionr/core.py | 14 ++++++++------ 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/onionr/communicator.py b/onionr/communicator.py index 95d83bbf..b78b2154 100755 --- a/onionr/communicator.py +++ b/onionr/communicator.py @@ -103,14 +103,14 @@ class OnionrCommunicate: logger.debug('Communicator heartbeat') heartBeatTimer = 0 if blockProcessTimer == blockProcessAmount: - lT1 = threading.Thread(target=self.lookupBlocks, name="lt1", args=(isThread=True,)) - lT2 = threading.Thread(target=self.lookupBlocks, name="lt2", args=(isThread=True,)) - lT3 = threading.Thread(target=self.lookupBlocks, name="lt3", args=(isThread=True,)) - lT4 = threading.Thread(target=self.lookupBlocks, name="lt4", args=(isThread=True,)) - pbT1 = threading.Thread(target=self.processBlocks, name='pbT1', args=(isThread=True,)) - pbT2 = threading.Thread(target=self.processBlocks, name='pbT2', args=(isThread=True,)) - pbT3 = threading.Thread(target=self.processBlocks, name='pbT3', args=(isThread=True,)) - pbT4 = threading.Thread(target=self.processBlocks, name='pbT4', args=(isThread=True,)) + lT1 = threading.Thread(target=self.lookupBlocks, name="lt1", args=(True,)) + lT2 = threading.Thread(target=self.lookupBlocks, name="lt2", args=(True,)) + lT3 = threading.Thread(target=self.lookupBlocks, name="lt3", args=(True,)) + lT4 = threading.Thread(target=self.lookupBlocks, name="lt4", args=(True,)) + pbT1 = threading.Thread(target=self.processBlocks, name='pbT1', args=(True,)) + pbT2 = threading.Thread(target=self.processBlocks, name='pbT2', args=(True,)) + pbT3 = threading.Thread(target=self.processBlocks, name='pbT3', args=(True,)) + pbT4 = threading.Thread(target=self.processBlocks, name='pbT4', args=(True,)) if (self.maxThreads - 8) >= threading.active_count(): lT1.start() lT2.start() @@ -550,22 +550,25 @@ class OnionrCommunicate: blockContent = self._core.getData(i) try: #blockMetadata = json.loads(self._core.getData(i)).split('}')[0] + '}' - blockMetadata = self._core.getData(i).split(b'}')[0] + blockMetadata = self._core.getData(i) + blockMetadata = json.loads(blockMetadata[:blockMetadata.rfind(b'}') + 1]) try: blockMetadata = blockMetadata.decode() except AttributeError: pass - blockMetadata = json.loads(blockMetadata + '}') + #blockMetadata = json.loads(blockMetadata + '}') try: blockMetadata['sig'] - blockMetadata['id'] + blockMetadata['meta']['id'] except KeyError: pass - + else: - creator = self._utils.getPeerByHashId(blockMetadata['id']) + blockData = json.dumps(blockMetadata['meta']) + blockMetadata[blockMetadata.rfind(b'}') + 1:] + + creator = self._utils.getPeerByHashId(blockMetadata['meta']['id']) try: creator = creator.decode() except AttributeError: diff --git a/onionr/core.py b/onionr/core.py index 1cdbf574..05bcd9d7 100644 --- a/onionr/core.py +++ b/onionr/core.py @@ -637,20 +637,22 @@ class Core: retData = '' metadata = {'type': header} + sig = {} + + metadata = json.dumps(metadata) + metadata = metadata.encode() if sign: - signature = self._crypto.edSign(data, self._crypto.privKey, encodeResult=True) + signature = self._crypto.edSign(metadata + data, self._crypto.privKey, encodeResult=True) ourID = self._crypto.pubKeyHashID() # Convert from bytes on some py versions? try: ourID = ourID.decode() except AttributeError: pass - metadata['id'] = ourID - metadata['sig'] = signature - - metadata = json.dumps(metadata) - metadata = metadata.encode() + metadata = {'sig': signature, 'meta': metadata.decode()} + metadata = json.dumps(metadata) + metadata = metadata.encode() if len(data) == 0: logger.error('Will not insert empty block')