communicator now uses one function

This commit is contained in:
Kevin Froman 2018-01-20 19:02:56 -06:00
parent d0a93ef2de
commit 4d33005d16
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
3 changed files with 16 additions and 1 deletions

View File

@ -129,6 +129,8 @@ class API:
pass
elif action == 'getPGP':
resp = Response(self._utils.exportMyPubkey())
elif action == 'storeData':
pass
return resp

View File

@ -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

View File

@ -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