work on chat
This commit is contained in:
parent
a086198ca0
commit
ccbf687ad1
@ -21,11 +21,12 @@ from gevent.pywsgi import WSGIServer
|
|||||||
from stem.control import Controller
|
from stem.control import Controller
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
import logger, httpapi
|
import logger, httpapi
|
||||||
import onionrexceptions, config
|
import onionrexceptions, config, filepaths
|
||||||
from netcontroller import get_open_port
|
from netcontroller import get_open_port
|
||||||
from httpapi import apiutils
|
from httpapi import apiutils
|
||||||
from onionrutils import stringvalidators, basicrequests, bytesconverter
|
from onionrutils import stringvalidators, basicrequests, bytesconverter
|
||||||
from . import httpheaders
|
from . import httpheaders
|
||||||
|
import deadsimplekv as simplekv
|
||||||
|
|
||||||
class ConnectionServer:
|
class ConnectionServer:
|
||||||
def __init__(self, peer, address, comm_inst=None):
|
def __init__(self, peer, address, comm_inst=None):
|
||||||
@ -39,6 +40,7 @@ class ConnectionServer:
|
|||||||
service_ip = apiutils.setbindip.set_bind_IP()
|
service_ip = apiutils.setbindip.set_bind_IP()
|
||||||
http_server = WSGIServer(('127.0.0.1', service_port), service_app, log=None)
|
http_server = WSGIServer(('127.0.0.1', service_port), service_app, log=None)
|
||||||
comm_inst.service_greenlets.append(http_server)
|
comm_inst.service_greenlets.append(http_server)
|
||||||
|
key_store = simplekv.DeadSimpleKV(filepaths.cached_storage)
|
||||||
|
|
||||||
# TODO define basic endpoints useful for direct connections like stats
|
# 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))
|
raise ConnectionError('Could not reach %s bootstrap address %s' % (peer, address))
|
||||||
else:
|
else:
|
||||||
# If no connection error, create the service and save it to local global key store
|
# 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))
|
logger.info('hosting on %s with %s' % (response.service_id, peer))
|
||||||
http_server.serve_forever()
|
http_server.serve_forever()
|
||||||
http_server.stop()
|
http_server.stop()
|
||||||
self.onionr_inst.keyStore.delete('dc-' + response.service_id)
|
key_store.delete('dc-' + response.service_id)
|
@ -42,6 +42,7 @@ class Chat:
|
|||||||
self.peer = None
|
self.peer = None
|
||||||
self.transport = None
|
self.transport = None
|
||||||
self.shutdown = False
|
self.shutdown = False
|
||||||
|
self.pluginapi = pluginapi
|
||||||
|
|
||||||
def _sender_loop(self):
|
def _sender_loop(self):
|
||||||
print('Enter a message to send, with ctrl-d or -s on a new line.')
|
print('Enter a message to send, with ctrl-d or -s on a new line.')
|
||||||
@ -58,7 +59,7 @@ class Chat:
|
|||||||
message += '\n'
|
message += '\n'
|
||||||
except EOFError:
|
except EOFError:
|
||||||
message = json.dumps({'m': message, 't': epoch.get_epoch()})
|
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 = ''
|
message = ''
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
self.shutdown = True
|
self.shutdown = True
|
||||||
|
@ -45,12 +45,12 @@ def pingdirect():
|
|||||||
def sendto():
|
def sendto():
|
||||||
try:
|
try:
|
||||||
msg = request.get_json(force=True)
|
msg = request.get_json(force=True)
|
||||||
except:
|
except json.JSONDecodeError:
|
||||||
msg = ''
|
msg = ''
|
||||||
else:
|
else:
|
||||||
msg = json.dumps(msg)
|
msg = json.dumps(msg)
|
||||||
localcommand.local_command('/chat/addrec/%s' % (g.peer,), post=True, postData=msg)
|
localcommand.local_command('/chat/addrec/%s' % (g.peer,), post=True, postData=msg)
|
||||||
print(msg)
|
print('msg from', g.peer, msg)
|
||||||
return Response('success')
|
return Response('success')
|
||||||
|
|
||||||
@direct_blueprint.route('/chat/poll')
|
@direct_blueprint.route('/chat/poll')
|
||||||
|
Loading…
Reference in New Issue
Block a user