minor bug fixes and linting improvements
This commit is contained in:
parent
9329b07e3b
commit
87ea8d137b
8 changed files with 223 additions and 154 deletions
|
@ -1,9 +1,10 @@
|
|||
'''
|
||||
Onionr - Private P2P Communication
|
||||
"""Onionr - Private P2P Communication.
|
||||
|
||||
add bootstrap peers to the communicator peer list
|
||||
'''
|
||||
'''
|
||||
add bootstrap peers to the communicator peer list
|
||||
"""
|
||||
from utils import readstatic, gettransports
|
||||
from coredb import keydb
|
||||
"""
|
||||
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
|
||||
|
@ -16,16 +17,16 @@
|
|||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
'''
|
||||
from utils import readstatic, gettransports
|
||||
from coredb import keydb
|
||||
"""
|
||||
|
||||
bootstrap_peers = readstatic.read_static('bootstrap-nodes.txt').split(',')
|
||||
|
||||
|
||||
def add_bootstrap_list_to_peer_list(comm_inst, peerList, db_only=False):
|
||||
'''
|
||||
Add the bootstrap list to the peer list (no duplicates)
|
||||
'''
|
||||
"""Add the bootstrap list to the peer list (no duplicates)."""
|
||||
for i in bootstrap_peers:
|
||||
if i not in peerList and i not in comm_inst.offlinePeers and not i in gettransports.get() and len(str(i).strip()) > 0:
|
||||
if not db_only: peerList.append(i)
|
||||
if i not in peerList and i not in comm_inst.offlinePeers \
|
||||
and i not in gettransports.get() and len(str(i).strip()) > 0:
|
||||
if not db_only:
|
||||
peerList.append(i)
|
||||
keydb.addkeys.add_address(i)
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
'''
|
||||
Onionr - Private P2P Communication
|
||||
"""Onionr - Private P2P Communication.
|
||||
|
||||
This file implements logic for performing requests to Onionr peers
|
||||
'''
|
||||
'''
|
||||
This file implements logic for performing requests to Onionr peers
|
||||
"""
|
||||
import streamedrequests
|
||||
import logger
|
||||
from onionrutils import epoch, basicrequests
|
||||
from coredb import keydb
|
||||
from . import onlinepeers
|
||||
"""
|
||||
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
|
||||
|
@ -16,15 +20,12 @@
|
|||
|
||||
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 streamedrequests
|
||||
import logger
|
||||
from onionrutils import epoch, basicrequests
|
||||
from coredb import keydb
|
||||
from . import onlinepeers
|
||||
"""
|
||||
|
||||
def peer_action(comm_inst, peer, action, returnHeaders=False, max_resp_size=5242880):
|
||||
'''Perform a get request to a peer'''
|
||||
|
||||
def peer_action(comm_inst, peer, action,
|
||||
returnHeaders=False, max_resp_size=5242880):
|
||||
"""Perform a get request to a peer."""
|
||||
penalty_score = -10
|
||||
if len(peer) == 0:
|
||||
return False
|
||||
|
@ -34,22 +35,28 @@ def peer_action(comm_inst, peer, action, returnHeaders=False, max_resp_size=5242
|
|||
ret_data = basicrequests.do_get_request(url, port=comm_inst.proxyPort,
|
||||
max_size=max_resp_size)
|
||||
except streamedrequests.exceptions.ResponseLimitReached:
|
||||
logger.warn('Request failed due to max response size being overflowed', terminal=True)
|
||||
logger.warn(
|
||||
'Request failed due to max response size being overflowed',
|
||||
terminal=True)
|
||||
ret_data = False
|
||||
penalty_score = -100
|
||||
# if request failed, (error), mark peer offline
|
||||
if ret_data == False: # For some reason "if not" breaks this. Prob has to do with empty string.
|
||||
if ret_data is False:
|
||||
try:
|
||||
comm_inst.getPeerProfileInstance(peer).addScore(penalty_score)
|
||||
onlinepeers.remove_online_peer(comm_inst, peer)
|
||||
keydb.transportinfo.set_address_info(peer, 'lastConnectAttempt', epoch.get_epoch())
|
||||
keydb.transportinfo.set_address_info(
|
||||
peer, 'lastConnectAttempt', epoch.get_epoch())
|
||||
if action != 'ping' and not comm_inst.shutdown:
|
||||
logger.warn(f'Lost connection to {peer}', terminal=True)
|
||||
onlinepeers.get_online_peers(comm_inst) # Will only add a new peer to pool if needed
|
||||
# Will only add a new peer to pool if needed
|
||||
onlinepeers.get_online_peers(comm_inst)
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
peer_profile = comm_inst.getPeerProfileInstance(peer)
|
||||
peer_profile.update_connect_time()
|
||||
peer_profile.addScore(1)
|
||||
return ret_data # If returnHeaders, returns tuple of data, headers. if not, just data string
|
||||
# If returnHeaders, returns tuple of data, headers.
|
||||
# If not, just data string
|
||||
return ret_data
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue