Add status check function

This commit is contained in:
Arinerron 2018-05-01 23:22:40 -07:00
parent 7b7c4e01cb
commit c144bc40b3
No known key found for this signature in database
GPG key ID: 99383627861C62F0
3 changed files with 30 additions and 7 deletions

View file

@ -59,14 +59,14 @@ class OnionrUtils:
sign = self._core._crypto.edSign(message, self._core._crypto.privKey, encodeResult=True)
#encrypted = self._core._crypto.pubKeyEncrypt(message, pubkey, anonymous=True, encodedData=True).decode()
payload['sig'] = sign
payload['msg'] = message
payload = json.dumps(payload)
message = payload
encrypted = self._core._crypto.pubKeyEncrypt(message, pubkey, anonymous=True, encodedData=True).decode()
block = self._core.insertBlock(encrypted, header='pm', sign=False)
if block == '':
logger.error('Could not send PM')
@ -383,7 +383,7 @@ class OnionrUtils:
except Exception as error:
logger.error('Failed to open block ' + str(i) + '.', error=error)
return
def getPeerByHashId(self, hash):
'''
Return the pubkey of the user if known from the hash
@ -398,4 +398,23 @@ class OnionrUtils:
for row in c.execute('SELECT ID FROM peers where hashID=?', command):
if row[0] != '':
retData = row[0]
return retData
return retData
def isCommunicatorRunning(timeout = 5, interval = 0.1):
runcheck_file = 'data/.runcheck'
if os.path.isfile(runcheck_file):
os.remove(runcheck_file)
logger.debug('%s file appears to have existed before the run check.' % runcheck_file, timestamp = False)
self._core.daemonQueueAdd('runCheck')
starttime = time.time()
while True:
time.sleep(interval)
if os.path.isfile(runcheck_file):
os.remove(runcheck_file)
return True
elif starttime - time.time() >= timeout:
return False