parent
d17970b181
commit
d4191b2cb5
6 changed files with 142 additions and 66 deletions
@ -0,0 +1,55 @@ |
||||
''' |
||||
Onionr - P2P Microblogging Platform & Social network |
||||
|
||||
Handle daemon queue commands in the communicator |
||||
''' |
||||
''' |
||||
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/>. |
||||
''' |
||||
import logger |
||||
import onionrevents as events |
||||
def handle_daemon_commands(comm_inst): |
||||
cmd = comm_inst._core.daemonQueue() |
||||
response = '' |
||||
if cmd is not False: |
||||
events.event('daemon_command', onionr = None, data = {'cmd' : cmd}) |
||||
if cmd[0] == 'shutdown': |
||||
comm_inst.shutdown = True |
||||
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.") |
||||
elif cmd[0] == 'runCheck': # deprecated |
||||
logger.debug('Status check; looks good.') |
||||
open(comm_inst._core.dataDir + '.runcheck', 'w+').close() |
||||
elif cmd[0] == 'connectedPeers': |
||||
response = '\n'.join(list(comm_inst.onlinePeers)).strip() |
||||
if response == '': |
||||
response = 'none' |
||||
elif cmd[0] == 'localCommand': |
||||
response = comm_inst._core._utils.localCommand(cmd[1]) |
||||
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]) |
||||
|
||||
if cmd[0] not in ('', None): |
||||
if response != '': |
||||
comm_inst._core._utils.localCommand('queueResponseAdd/' + cmd[4], post=True, postData={'data': response}) |
||||
response = '' |
||||
|
||||
comm_inst.decrementThreadCount('daemonCommands') |
@ -0,0 +1,48 @@ |
||||
''' |
||||
Onionr - P2P Microblogging Platform & Social network |
||||
|
||||
Lookup new peer transport addresses using the communicator |
||||
''' |
||||
''' |
||||
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/>. |
||||
''' |
||||
import logger |
||||
|
||||
def lookup_new_peer_transports_with_communicator(comm_inst): |
||||
logger.info('Looking up new addresses...') |
||||
tryAmount = 1 |
||||
newPeers = [] |
||||
for i in range(tryAmount): |
||||
# Download new peer address list from random online peers |
||||
if len(newPeers) > 10000: |
||||
# Dont get new peers if we have too many queued up |
||||
break |
||||
peer = comm_inst.pickOnlinePeer() |
||||
newAdders = comm_inst.peerAction(peer, action='pex') |
||||
try: |
||||
newPeers = newAdders.split(',') |
||||
except AttributeError: |
||||
pass |
||||
else: |
||||
# Validate new peers are good format and not already in queue |
||||
invalid = [] |
||||
for x in newPeers: |
||||
x = x.strip() |
||||
if not comm_inst._core._utils.validateID(x) or x in comm_inst.newPeers or x == comm_inst._core.hsAddress: |
||||
# avoid adding if its our address |
||||
invalid.append(x) |
||||
for x in invalid: |
||||
newPeers.remove(x) |
||||
comm_inst.newPeers.extend(newPeers) |
||||
comm_inst.decrementThreadCount('lookupAdders') |
Loading…
Reference in new issue