work on fixing mallable metadata & thread work

This commit is contained in:
Kevin Froman 2018-05-05 01:19:25 -05:00
parent ab1cce3616
commit ff5bdd62f2
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
2 changed files with 24 additions and 19 deletions

View File

@ -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:

View File

@ -637,18 +637,20 @@ 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 = {'sig': signature, 'meta': metadata.decode()}
metadata = json.dumps(metadata)
metadata = metadata.encode()