Onionr/src/communicatorutils/daemonqueuehandler/__init__.py

89 lines
3.4 KiB
Python
Raw Normal View History

2019-12-22 19:42:10 +00:00
"""Onionr - P2P Anonymous Storage Network.
2019-12-22 19:42:10 +00:00
Handle daemon queue commands in the communicator
"""
import logger
from onionrplugins import onionrevents as events
from onionrutils import localcommand
2019-12-27 07:53:18 +00:00
from communicatorutils.uploadblocks import mixmate
2019-12-22 19:42:10 +00:00
from coredb import daemonqueue
import filepaths
2019-12-27 07:53:18 +00:00
from .. import restarttor
2019-12-22 19:42:10 +00:00
"""
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-12-22 19:42:10 +00:00
"""
def handle_daemon_commands(comm_inst):
2019-07-17 22:41:33 +00:00
cmd = daemonqueue.daemon_queue()
response = ''
if cmd is not False:
2019-12-27 07:53:18 +00:00
events.event('daemon_command', data={'cmd': cmd})
if cmd[0] == 'shutdown':
comm_inst.shutdown = True
2019-09-26 07:43:03 +00:00
elif cmd[0] == 'runtimeTest':
2019-12-27 07:53:18 +00:00
comm_inst.shared_state.get_by_string(
"OnionrRunTestManager").run_tests()
elif cmd[0] == 'remove_from_insert_list':
try:
comm_inst.generating_blocks.remove(cmd[1])
except ValueError:
pass
elif cmd[0] == 'announceNode':
if len(comm_inst.onlinePeers) > 0:
comm_inst.announce(cmd[1])
else:
logger.debug("No nodes connected. Will not introduce node.")
2019-12-27 07:53:18 +00:00
elif cmd[0] == 'runCheck': # deprecated
logger.debug('Status check; looks good.')
2019-07-18 17:40:48 +00:00
open(filepaths.run_check_file + '.runcheck', 'w+').close()
elif cmd[0] == 'connectedPeers':
response = '\n'.join(list(comm_inst.onlinePeers)).strip()
if response == '':
response = 'none'
elif cmd[0] == 'localCommand':
2019-07-18 17:40:48 +00:00
response = localcommand.local_command(cmd[1])
elif cmd[0] == 'clearOffline':
comm_inst.offlinePeers = []
elif cmd[0] == 'restartTor':
restarttor.restart(comm_inst)
comm_inst.offlinePeers = []
elif cmd[0] == 'pex':
for i in comm_inst.timers:
if i.timerFunction.__name__ == 'lookupAdders':
i.count = (i.frequency - 1)
elif cmd[0] == 'uploadBlock':
comm_inst.blocksToUpload.append(cmd[1])
2019-12-22 19:42:10 +00:00
elif cmd[0] == 'uploadEvent':
2019-12-27 07:53:18 +00:00
localcommand.local_command('/waitforshare/' + cmd[1], post=True,
maxWait=5)
2019-12-22 19:42:10 +00:00
try:
mixmate.block_mixer(comm_inst.blocksToUpload, cmd[1])
except ValueError:
2019-12-27 07:53:18 +00:00
comm_inst.blocksToUpload.append(cmd[1])
2019-08-28 02:14:18 +00:00
else:
2019-12-27 07:53:18 +00:00
logger.debug(
'Received daemon queue cmd with no handler: %s' % (cmd[0],))
if cmd[0] not in ('', None):
if response != '':
2019-12-27 07:53:18 +00:00
localcommand.local_command('queueResponseAdd/' + cmd[4],
post=True,
postData={'data': response})
response = ''
comm_inst.decrementThreadCount('handle_daemon_commands')