Onionr/onionr/static-data/default-plugins/esoteric/peerserver.py

56 lines
1.8 KiB
Python
Raw Permalink Normal View History

2019-03-29 17:37:51 +00:00
'''
2019-06-20 07:59:32 +00:00
Onionr - Private P2P Communication
2019-03-29 17:37:51 +00:00
HTTP endpoints for communicating with peers
'''
'''
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
2019-03-31 04:50:54 +00:00
import sys, os, json
2019-03-29 17:37:51 +00:00
import core
from onionrutils import localcommand
2019-03-29 17:37:51 +00:00
from flask import Response, request, redirect, Blueprint, abort, g
2019-03-31 04:50:54 +00:00
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
direct_blueprint = Blueprint('esoteric', __name__)
2019-03-29 17:37:51 +00:00
core_inst = core.Core()
storage_dir = core_inst.dataDir
@direct_blueprint.before_request
def request_setup():
core_inst.keyStore.refresh()
host = request.host
host = host.strip('.b32.i2p')
host = host.strip('.onion')
g.host = host
g.peer = core_inst.keyStore.get('dc-' + g.host)
@direct_blueprint.route('/esoteric/ping')
2019-03-29 17:37:51 +00:00
def pingdirect():
2019-03-31 04:50:54 +00:00
return 'pong!'
@direct_blueprint.route('/esoteric/sendto', methods=['POST', 'GET'])
2019-03-31 04:50:54 +00:00
def sendto():
try:
msg = request.get_json(force=True)
except:
msg = ''
else:
msg = json.dumps(msg)
localcommand.local_command(core_inst, '/esoteric/addrec/%s' % (g.peer,), post=True, postData=msg)
2019-03-31 04:50:54 +00:00
return Response('success')
@direct_blueprint.route('/esoteric/poll')
2019-03-31 04:50:54 +00:00
def poll_chat():
return Response(localcommand.local_command(core_inst, '/esoteric/gets/%s' % (g.peer,)))