From 4d33005d163252e1df5febb514c65ff564d6e4c1 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sat, 20 Jan 2018 19:02:56 -0600 Subject: [PATCH] communicator now uses one function --- onionr/api.py | 2 ++ onionr/communicator.py | 13 +++++++++++++ onionr/onionr.py | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/onionr/api.py b/onionr/api.py index 7df0a0c4..c47b5339 100755 --- a/onionr/api.py +++ b/onionr/api.py @@ -129,6 +129,8 @@ class API: pass elif action == 'getPGP': resp = Response(self._utils.exportMyPubkey()) + elif action == 'storeData': + pass return resp diff --git a/onionr/communicator.py b/onionr/communicator.py index 3e81a472..40979bbc 100755 --- a/onionr/communicator.py +++ b/onionr/communicator.py @@ -69,6 +69,19 @@ class OnionrCommunicate: def sendPeerProof(self, peerID, data): '''This function sends the proof result to a peer previously fetched with getPeerProof''' return + def performGet(self, action, peer, data=None, type='tor'): + '''performs a request to a peer through Tor or i2p (currently only tor)''' + if not peer.endswith('.onion') and not peer.endswith('.onion/'): + raise PeerError('Currently only Tor .onion peers are supported. You must manually specify .onion') + socksPort = sys.argv[2] + proxies = {'http': 'socks5://127.0.0.1:' + str(socksPort), 'https': 'socks5://127.0.0.1:' + str(socksPort)} + headers = {'user-agent': 'PyOnionr'} + url = 'http://' + peer + '/public/?action=' + action + if data != None: + url = url + '&data=' + data + r = requests.get(url, headers=headers, proxies=proxies) + return r.text + shouldRun = False debug = False diff --git a/onionr/onionr.py b/onionr/onionr.py index 4fa8c19c..bd5e40a1 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -128,7 +128,7 @@ class Onionr: net.startTor() print(colors.GREEN + 'Started Tor .onion service: ' + colors.UNDERLINE + net.myID + colors.RESET) time.sleep(1) - subprocess.Popen(["./communicator.py", "run"]) + subprocess.Popen(["./communicator.py", "run", net.socksPort]) print('Started communicator') api.API(self.config, self.debug) return