From 636cf3a8d1157827d319d1c9b8965b82250ed94f Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Wed, 7 Aug 2019 00:42:37 -0500 Subject: [PATCH] added readme for communicator --- onionr/communicator/README.md | 15 +++++++++++++++ onionr/communicator/peeraction.py | 21 +++++++++++---------- 2 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 onionr/communicator/README.md diff --git a/onionr/communicator/README.md b/onionr/communicator/README.md new file mode 100644 index 00000000..941f3642 --- /dev/null +++ b/onionr/communicator/README.md @@ -0,0 +1,15 @@ +# Onionr Communicator + +Onionr communicator is the Onionr client. It "connects" to remote Onionr peers and does things such as: + +* Finding new peers +* Uploading blocks +* Downloading blocks +* Daemon maintnence/housekeeping + +## Files + +* \_\_init\_\_.py: Contains the main communicator code. Inits and launches the communicator and sets up the timers +* peeraction.py: contains a function to send commands to remote peers +* bootstrappers.py: adds peers from the bootstrap list to the communicator to try to connect to them +* onlinepers: management of the online peer pool for the communicator \ No newline at end of file diff --git a/onionr/communicator/peeraction.py b/onionr/communicator/peeraction.py index d693ea8e..42af1e0f 100644 --- a/onionr/communicator/peeraction.py +++ b/onionr/communicator/peeraction.py @@ -20,26 +20,27 @@ import streamedrequests import logger from onionrutils import epoch, basicrequests -from . import onlinepeers from coredb import keydb -def peer_action(comm_inst, peer, action, data='', returnHeaders=False, max_resp_size=5242880): +from . import onlinepeers +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: + if not peer: return False url = 'http://%s/%s' % (peer, action) - if len(data) > 0: - url += '&data=' + data - keydb.transportinfo.set_address_info(peer, 'lastConnectAttempt', epoch.get_epoch()) # mark the time we're trying to request this peer + # mark the time we're trying to request this peer + keydb.transportinfo.set_address_info(peer, 'lastConnectAttempt', epoch.get_epoch()) + try: - retData = basicrequests.do_get_request( url, port=comm_inst.proxyPort, max_size=max_resp_size) + 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) - retData = False + ret_data = False penalty_score = -100 # if request failed, (error), mark peer offline - if retData == False: + if not ret_data: try: comm_inst.getPeerProfileInstance(peer).addScore(penalty_score) onlinepeers.remove_online_peer(comm_inst, peer) @@ -52,4 +53,4 @@ def peer_action(comm_inst, peer, action, data='', returnHeaders=False, max_resp_ peer_profile = comm_inst.getPeerProfileInstance(peer) peer_profile.update_connect_time() peer_profile.addScore(1) - return retData # If returnHeaders, returns tuple of data, headers. if not, just data string + return ret_data # If returnHeaders, returns tuple of data, headers. if not, just data string