plugin example of connecting to dir conn
parent
063330cfee
commit
faf42071eb
|
@ -39,8 +39,8 @@ def bootstrap_client_service(peer, core_inst=None, bootstrap_timeout=300):
|
|||
bootstrap_app = Flask(__name__)
|
||||
http_server = WSGIServer(('127.0.0.1', bootstrap_port), bootstrap_app, log=None)
|
||||
try:
|
||||
core_inst.onionrInst.communicatorInst
|
||||
except AttributeError:
|
||||
assert core_inst.onionrInst.communicatorInst is not None
|
||||
except (AttributeError, AssertionError) as e:
|
||||
pass
|
||||
else:
|
||||
core_inst.onionrInst.communicatorInst.service_greenlets.append(http_server)
|
||||
|
|
|
@ -50,6 +50,12 @@ class ConnectionServer:
|
|||
@service_app.route('/ping')
|
||||
def get_ping():
|
||||
return "pong!"
|
||||
|
||||
@service_app.route('/shutdown')
|
||||
def shutdown_server():
|
||||
core_inst.onionrInst.communicatorInst.service_greenlets.remove(http_server)
|
||||
http_server.stop()
|
||||
return Response('goodbye')
|
||||
|
||||
@service_app.after_request
|
||||
def afterReq(resp):
|
||||
|
|
|
@ -20,8 +20,9 @@
|
|||
|
||||
# Imports some useful libraries
|
||||
import locale, sys, os
|
||||
|
||||
locale.setlocale(locale.LC_ALL, '')
|
||||
import onionrservices, logger
|
||||
from onionrservices import bootstrapservice
|
||||
|
||||
plugin_name = 'clandestine'
|
||||
PLUGIN_VERSION = '0.0.0'
|
||||
|
@ -31,9 +32,29 @@ from . import controlapi, peerserver
|
|||
flask_blueprint = controlapi.flask_blueprint
|
||||
direct_blueprint = peerserver.direct_blueprint
|
||||
|
||||
def exit_with_error(text=''):
|
||||
if text != '':
|
||||
logger.error(text)
|
||||
sys.exit(1)
|
||||
|
||||
class Clandestine:
|
||||
def __init__(self, pluginapi):
|
||||
self.myCore = pluginapi.get_core()
|
||||
|
||||
def create(self):
|
||||
try:
|
||||
peer = sys.argv[2]
|
||||
if not self.myCore._utils.validatePubKey(peer):
|
||||
exit_with_error('Invalid public key specified')
|
||||
except IndexError:
|
||||
exit_with_error('You must specify a peer public key')
|
||||
|
||||
# Ask peer for transport address by creating block for them
|
||||
peer_transport_address = bootstrapservice.bootstrap_client_service(peer, self.myCore)
|
||||
|
||||
print(peer_transport_address)
|
||||
if self.myCore._utils.doGetRequest('http://%s/ping' % (peer_transport_address,), ignoreAPI=True, port=self.myCore.config.get('tor.socksport')) == 'pong!':
|
||||
print('connected', peer_transport_address)
|
||||
|
||||
def on_init(api, data = None):
|
||||
'''
|
||||
|
@ -44,4 +65,5 @@ def on_init(api, data = None):
|
|||
|
||||
pluginapi = api
|
||||
chat = Clandestine(pluginapi)
|
||||
api.commands.register(['clandestine'], chat.create)
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue