From ccbf687ad14832573164761bbdc4a7ec91f4ebe6 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sun, 28 Jul 2019 13:05:32 -0500 Subject: [PATCH] work on chat --- onionr/onionrservices/connectionserver.py | 8 +++++--- onionr/static-data/default-plugins/chat/main.py | 3 ++- onionr/static-data/default-plugins/chat/peerserver.py | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/onionr/onionrservices/connectionserver.py b/onionr/onionrservices/connectionserver.py index e7e6abf3..b7e15334 100755 --- a/onionr/onionrservices/connectionserver.py +++ b/onionr/onionrservices/connectionserver.py @@ -21,11 +21,12 @@ from gevent.pywsgi import WSGIServer from stem.control import Controller from flask import Flask import logger, httpapi -import onionrexceptions, config +import onionrexceptions, config, filepaths from netcontroller import get_open_port from httpapi import apiutils from onionrutils import stringvalidators, basicrequests, bytesconverter from . import httpheaders +import deadsimplekv as simplekv class ConnectionServer: def __init__(self, peer, address, comm_inst=None): @@ -39,6 +40,7 @@ class ConnectionServer: service_ip = apiutils.setbindip.set_bind_IP() http_server = WSGIServer(('127.0.0.1', service_port), service_app, log=None) comm_inst.service_greenlets.append(http_server) + key_store = simplekv.DeadSimpleKV(filepaths.cached_storage) # TODO define basic endpoints useful for direct connections like stats @@ -78,8 +80,8 @@ class ConnectionServer: raise ConnectionError('Could not reach %s bootstrap address %s' % (peer, address)) else: # If no connection error, create the service and save it to local global key store - self.onionr_inst.keyStore.put('dc-' + response.service_id, bytesconverter.bytes_to_str(peer)) + key_store.put('dc-' + response.service_id, bytesconverter.bytes_to_str(peer)) logger.info('hosting on %s with %s' % (response.service_id, peer)) http_server.serve_forever() http_server.stop() - self.onionr_inst.keyStore.delete('dc-' + response.service_id) \ No newline at end of file + key_store.delete('dc-' + response.service_id) \ No newline at end of file diff --git a/onionr/static-data/default-plugins/chat/main.py b/onionr/static-data/default-plugins/chat/main.py index d00720a0..206e5e37 100755 --- a/onionr/static-data/default-plugins/chat/main.py +++ b/onionr/static-data/default-plugins/chat/main.py @@ -42,6 +42,7 @@ class Chat: self.peer = None self.transport = None self.shutdown = False + self.pluginapi = pluginapi def _sender_loop(self): print('Enter a message to send, with ctrl-d or -s on a new line.') @@ -58,7 +59,7 @@ class Chat: message += '\n' except EOFError: message = json.dumps({'m': message, 't': epoch.get_epoch()}) - print(basicrequests.do_post_request('http://%s/chat/sendto' % (self.transport,), port=self.socks, data=message)) + print(basicrequests.do_post_request(self.pluginapi.onionr, 'http://%s/chat/sendto' % (self.transport,), port=self.socks, data=message)) message = '' except KeyboardInterrupt: self.shutdown = True diff --git a/onionr/static-data/default-plugins/chat/peerserver.py b/onionr/static-data/default-plugins/chat/peerserver.py index 40a9fa10..3189c948 100755 --- a/onionr/static-data/default-plugins/chat/peerserver.py +++ b/onionr/static-data/default-plugins/chat/peerserver.py @@ -45,12 +45,12 @@ def pingdirect(): def sendto(): try: msg = request.get_json(force=True) - except: + except json.JSONDecodeError: msg = '' else: msg = json.dumps(msg) localcommand.local_command('/chat/addrec/%s' % (g.peer,), post=True, postData=msg) - print(msg) + print('msg from', g.peer, msg) return Response('success') @direct_blueprint.route('/chat/poll')