improved api-communicator integration, panel

This commit is contained in:
Kevin Froman 2019-01-20 16:54:04 -06:00
parent d2e7ced776
commit a9e61e2827
8 changed files with 24 additions and 14 deletions

View File

@ -256,7 +256,7 @@ class API:
self.debug = debug
self._privateDelayTime = 3
self._core = core.Core()
self._core = onionrInst.onionrCore
self.startTime = self._core._utils.getEpoch()
self._crypto = onionrcrypto.OnionrCrypto(self._core)
self._utils = onionrutils.OnionrUtils(self._core)

View File

@ -40,7 +40,7 @@ class OnionrCommunicatorDaemon:
# initalize core with Tor socks port being 3rd argument
self.proxyPort = proxyPort
self._core = core.Core(torPort=self.proxyPort)
self._core = onionrInst.onionrCore
# intalize NIST beacon salt and time
self.nistSaltTimestamp = 0
@ -93,7 +93,6 @@ class OnionrCommunicatorDaemon:
self.startTime = self._core._utils.getEpoch()
if developmentMode:
print('enabling heartbeat')
OnionrCommunicatorTimers(self, self.heartbeat, 30)
# Set timers, function reference, seconds
@ -485,10 +484,12 @@ class OnionrCommunicatorDaemon:
retData = onionrpeers.PeerProfiles(peer, self._core)
return retData
def getUptime(self):
return self._core._utils.getEpoch() - self.startTime
def heartbeat(self):
'''Show a heartbeat debug message'''
currentTime = self._core._utils.getEpoch() - self.startTime
logger.debug('Heartbeat. Node running for %s.' % self.daemonTools.humanReadableTime(currentTime))
logger.debug('Heartbeat. Node running for %s.' % self.daemonTools.humanReadableTime(self.getUptime()))
self.decrementThreadCount('heartbeat')
def daemonCommands(self):

View File

@ -45,6 +45,7 @@ class Core:
self.dataDir = 'data/'
try:
self.onionrInst = None
self.queueDB = self.dataDir + 'queue.db'
self.peerDB = self.dataDir + 'peers.db'
self.blockDB = self.dataDir + 'blocks.db'

View File

@ -74,6 +74,7 @@ class Onionr:
self.communicatorInst = None
self.onionrCore = core.Core()
self.onionrCore.onionrInst = self
#self.deleteRunFiles()
self.onionrUtils = onionrutils.OnionrUtils(self.onionrCore)
@ -751,7 +752,7 @@ class Onionr:
# TODO: make runable on windows
#communicatorProc = subprocess.Popen([communicatorDaemon, 'run', str(net.socksPort)])
self.onionrCore.torPort = net.socksPort
communicatorThread = Thread(target=communicator2.startCommunicator, args=(self, str(net.socksPort)))
communicatorThread.start()

View File

@ -36,7 +36,7 @@ class SerializedData:
def getStats(self):
'''Return statistics about our node'''
stats = {}
stats['uptime'] = int(self._core.daemonQueueSimple('localCommand', 'getuptime'))
stats['connectedNodes'] = self._core.daemonQueueSimple('connectedPeers')
stats['uptime'] = self._core.onionrInst.communicatorInst.getUptime()
stats['connectedNodes'] = '\n'.join(self._core.onionrInst.communicatorInst.onlinePeers)
stats['blockCount'] = len(self._core.getBlockList())
return json.dumps(stats)

View File

@ -17,7 +17,7 @@
<img class='logo' src='/shared/onionr-icon.png' alt='onionr logo'>
<span class='logoText'>Onionr Web Control Panel</span>
<div class='content'>
<button id='shutdownNode'>Shutdown Node</button>
<button id='shutdownNode'>Shutdown Node</button> <button id='refreshStats'>Refresh Stats</button>
<h2>Stats</h2>
<p>Uptime: <span id='uptime'></span></p>
<p>Stored Blocks: <span id='storedBlocks'></span></p>

View File

@ -21,7 +21,10 @@ uptimeDisplay = document.getElementById('uptime')
connectedDisplay = document.getElementById('connectedNodes')
storedBlockDisplay = document.getElementById('storedBlocks')
function getStats(){
stats = JSON.parse(httpGet('getstats', webpass))
uptimeDisplay.innerText = stats['uptime'] + ' seconds'
connectedDisplay.innerText = stats['connectedNodes']
storedBlockDisplay.innerText = stats['blockCount']
}
getStats()

View File

@ -1,8 +1,12 @@
shutdownBtn = document.getElementById('shutdownNode')
refreshStatsBtn = document.getElementById('refreshStats')
shutdownBtn.onclick = function(){
if (! nowebpass){
httpGet('shutdownclean')
overlay('shutdownNotice')
}
}
refreshStatsBtn.onclick = function(){
getStats()
}