Add status check function
parent
7b7c4e01cb
commit
c144bc40b3
|
@ -111,6 +111,10 @@ class OnionrCommunicate:
|
||||||
if announceAttemptCount >= announceAttempts:
|
if announceAttemptCount >= announceAttempts:
|
||||||
logger.warn('Unable to announce to ' + command[1])
|
logger.warn('Unable to announce to ' + command[1])
|
||||||
break
|
break
|
||||||
|
elif command[0] == 'runCheck':
|
||||||
|
logger.info('Status check; looks good.')
|
||||||
|
open('data/.runcheck', 'w+').close()
|
||||||
|
break
|
||||||
apiRunningCheckCount += 1
|
apiRunningCheckCount += 1
|
||||||
# check if local API is up
|
# check if local API is up
|
||||||
if apiRunningCheckCount > apiRunningCheckRate:
|
if apiRunningCheckCount > apiRunningCheckRate:
|
||||||
|
|
|
@ -99,17 +99,17 @@ def commandInstallPlugin():
|
||||||
return True
|
return True
|
||||||
elif valid_hash and real_block:
|
elif valid_hash and real_block:
|
||||||
blockhash = str(pkobh)
|
blockhash = str(pkobh)
|
||||||
logger.debug('Using block ' + blockhash + '...')
|
logger.debug('Using block %s...' % blockhash)
|
||||||
elif valid_key and not real_key:
|
elif valid_key and not real_key:
|
||||||
logger.error('Public key not found. Try adding the node by address manually, if possible.')
|
logger.error('Public key not found. Try adding the node by address manually, if possible.')
|
||||||
logger.debug('Is valid key, but the key is not a known one.')
|
logger.debug('Is valid key, but the key is not a known one.')
|
||||||
elif valid_key and real_key:
|
elif valid_key and real_key:
|
||||||
publickey = str(pkobh)
|
publickey = str(pkobh)
|
||||||
logger.debug('Using public key ' + publickey + '...')
|
logger.debug('Using public key %s...' % publickey)
|
||||||
|
|
||||||
saveKey(pluginname, pkobh)
|
saveKey(pluginname, pkobh)
|
||||||
else:
|
else:
|
||||||
logger.error('Unknown data \"' + str(pkobh) + '\"; must be public key or block hash.')
|
logger.error('Unknown data "%s"; must be public key or block hash.' % str(pkobh))
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
help()
|
help()
|
||||||
|
|
|
@ -59,14 +59,14 @@ class OnionrUtils:
|
||||||
|
|
||||||
sign = self._core._crypto.edSign(message, self._core._crypto.privKey, encodeResult=True)
|
sign = self._core._crypto.edSign(message, self._core._crypto.privKey, encodeResult=True)
|
||||||
#encrypted = self._core._crypto.pubKeyEncrypt(message, pubkey, anonymous=True, encodedData=True).decode()
|
#encrypted = self._core._crypto.pubKeyEncrypt(message, pubkey, anonymous=True, encodedData=True).decode()
|
||||||
|
|
||||||
payload['sig'] = sign
|
payload['sig'] = sign
|
||||||
payload['msg'] = message
|
payload['msg'] = message
|
||||||
payload = json.dumps(payload)
|
payload = json.dumps(payload)
|
||||||
message = payload
|
message = payload
|
||||||
encrypted = self._core._crypto.pubKeyEncrypt(message, pubkey, anonymous=True, encodedData=True).decode()
|
encrypted = self._core._crypto.pubKeyEncrypt(message, pubkey, anonymous=True, encodedData=True).decode()
|
||||||
|
|
||||||
|
|
||||||
block = self._core.insertBlock(encrypted, header='pm', sign=False)
|
block = self._core.insertBlock(encrypted, header='pm', sign=False)
|
||||||
if block == '':
|
if block == '':
|
||||||
logger.error('Could not send PM')
|
logger.error('Could not send PM')
|
||||||
|
@ -383,7 +383,7 @@ class OnionrUtils:
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
logger.error('Failed to open block ' + str(i) + '.', error=error)
|
logger.error('Failed to open block ' + str(i) + '.', error=error)
|
||||||
return
|
return
|
||||||
|
|
||||||
def getPeerByHashId(self, hash):
|
def getPeerByHashId(self, hash):
|
||||||
'''
|
'''
|
||||||
Return the pubkey of the user if known from the 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):
|
for row in c.execute('SELECT ID FROM peers where hashID=?', command):
|
||||||
if row[0] != '':
|
if row[0] != '':
|
||||||
retData = 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
|
||||||
|
|
Loading…
Reference in New Issue