work on fixing mallable metadata & thread work

master
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') logger.debug('Communicator heartbeat')
heartBeatTimer = 0 heartBeatTimer = 0
if blockProcessTimer == blockProcessAmount: if blockProcessTimer == blockProcessAmount:
lT1 = threading.Thread(target=self.lookupBlocks, name="lt1", args=(isThread=True,)) lT1 = threading.Thread(target=self.lookupBlocks, name="lt1", args=(True,))
lT2 = threading.Thread(target=self.lookupBlocks, name="lt2", args=(isThread=True,)) lT2 = threading.Thread(target=self.lookupBlocks, name="lt2", args=(True,))
lT3 = threading.Thread(target=self.lookupBlocks, name="lt3", args=(isThread=True,)) lT3 = threading.Thread(target=self.lookupBlocks, name="lt3", args=(True,))
lT4 = threading.Thread(target=self.lookupBlocks, name="lt4", args=(isThread=True,)) lT4 = threading.Thread(target=self.lookupBlocks, name="lt4", args=(True,))
pbT1 = threading.Thread(target=self.processBlocks, name='pbT1', args=(isThread=True,)) pbT1 = threading.Thread(target=self.processBlocks, name='pbT1', args=(True,))
pbT2 = threading.Thread(target=self.processBlocks, name='pbT2', args=(isThread=True,)) pbT2 = threading.Thread(target=self.processBlocks, name='pbT2', args=(True,))
pbT3 = threading.Thread(target=self.processBlocks, name='pbT3', args=(isThread=True,)) pbT3 = threading.Thread(target=self.processBlocks, name='pbT3', args=(True,))
pbT4 = threading.Thread(target=self.processBlocks, name='pbT4', args=(isThread=True,)) pbT4 = threading.Thread(target=self.processBlocks, name='pbT4', args=(True,))
if (self.maxThreads - 8) >= threading.active_count(): if (self.maxThreads - 8) >= threading.active_count():
lT1.start() lT1.start()
lT2.start() lT2.start()
@ -550,22 +550,25 @@ class OnionrCommunicate:
blockContent = self._core.getData(i) blockContent = self._core.getData(i)
try: try:
#blockMetadata = json.loads(self._core.getData(i)).split('}')[0] + '}' #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: try:
blockMetadata = blockMetadata.decode() blockMetadata = blockMetadata.decode()
except AttributeError: except AttributeError:
pass pass
blockMetadata = json.loads(blockMetadata + '}') #blockMetadata = json.loads(blockMetadata + '}')
try: try:
blockMetadata['sig'] blockMetadata['sig']
blockMetadata['id'] blockMetadata['meta']['id']
except KeyError: except KeyError:
pass pass
else: 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: try:
creator = creator.decode() creator = creator.decode()
except AttributeError: except AttributeError:

View File

@ -637,18 +637,20 @@ class Core:
retData = '' retData = ''
metadata = {'type': header} metadata = {'type': header}
sig = {}
metadata = json.dumps(metadata)
metadata = metadata.encode()
if sign: 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() ourID = self._crypto.pubKeyHashID()
# Convert from bytes on some py versions? # Convert from bytes on some py versions?
try: try:
ourID = ourID.decode() ourID = ourID.decode()
except AttributeError: except AttributeError:
pass pass
metadata['id'] = ourID metadata = {'sig': signature, 'meta': metadata.decode()}
metadata['sig'] = signature
metadata = json.dumps(metadata) metadata = json.dumps(metadata)
metadata = metadata.encode() metadata = metadata.encode()