Onionr/onionr/serializeddata.py

43 lines
1.5 KiB
Python
Raw Normal View History

2019-02-02 03:49:11 +00:00
'''
Onionr - Private P2P Communication
2019-02-02 03:49:11 +00:00
This module serializes various data pieces for use in other modules, in particular the web api
'''
'''
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
2019-07-19 19:49:56 +00:00
import json
from coredb import blockmetadb
2019-02-02 03:49:11 +00:00
class SerializedData:
2019-07-19 19:49:56 +00:00
def __init__(self, o_inst):
2019-02-02 03:49:11 +00:00
'''
Serialized data is in JSON format:
{
'success': bool,
'foo': 'bar',
etc
}
'''
2019-07-19 19:49:56 +00:00
self.o_inst = o_inst
2019-02-02 03:49:11 +00:00
def getStats(self):
'''Return statistics about our node'''
stats = {}
2019-07-19 19:49:56 +00:00
stats['uptime'] = self.o_inst.communicatorInst.getUptime()
stats['connectedNodes'] = '\n'.join(self.o_inst.communicatorInst.onlinePeers)
stats['blockCount'] = len(blockmetadb.get_block_list())
2019-07-19 19:49:56 +00:00
stats['blockQueueCount'] = len(self.o_inst.communicatorInst.blockQueue)
2019-02-02 03:49:11 +00:00
return json.dumps(stats)