work on chat

master
Kevin Froman 2019-07-28 13:05:32 -05:00
parent a086198ca0
commit ccbf687ad1
3 changed files with 9 additions and 6 deletions

View File

@ -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)
key_store.delete('dc-' + response.service_id)

View File

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

View File

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