plugin example of connecting to dir conn
This commit is contained in:
parent
29db7e27d9
commit
3d1b967f1f
@ -39,8 +39,8 @@ def bootstrap_client_service(peer, core_inst=None, bootstrap_timeout=300):
|
|||||||
bootstrap_app = Flask(__name__)
|
bootstrap_app = Flask(__name__)
|
||||||
http_server = WSGIServer(('127.0.0.1', bootstrap_port), bootstrap_app, log=None)
|
http_server = WSGIServer(('127.0.0.1', bootstrap_port), bootstrap_app, log=None)
|
||||||
try:
|
try:
|
||||||
core_inst.onionrInst.communicatorInst
|
assert core_inst.onionrInst.communicatorInst is not None
|
||||||
except AttributeError:
|
except (AttributeError, AssertionError) as e:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
core_inst.onionrInst.communicatorInst.service_greenlets.append(http_server)
|
core_inst.onionrInst.communicatorInst.service_greenlets.append(http_server)
|
||||||
|
@ -51,6 +51,12 @@ class ConnectionServer:
|
|||||||
def get_ping():
|
def get_ping():
|
||||||
return "pong!"
|
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
|
@service_app.after_request
|
||||||
def afterReq(resp):
|
def afterReq(resp):
|
||||||
# Security headers
|
# Security headers
|
||||||
|
@ -20,8 +20,9 @@
|
|||||||
|
|
||||||
# Imports some useful libraries
|
# Imports some useful libraries
|
||||||
import locale, sys, os
|
import locale, sys, os
|
||||||
|
|
||||||
locale.setlocale(locale.LC_ALL, '')
|
locale.setlocale(locale.LC_ALL, '')
|
||||||
|
import onionrservices, logger
|
||||||
|
from onionrservices import bootstrapservice
|
||||||
|
|
||||||
plugin_name = 'clandestine'
|
plugin_name = 'clandestine'
|
||||||
PLUGIN_VERSION = '0.0.0'
|
PLUGIN_VERSION = '0.0.0'
|
||||||
@ -31,10 +32,30 @@ from . import controlapi, peerserver
|
|||||||
flask_blueprint = controlapi.flask_blueprint
|
flask_blueprint = controlapi.flask_blueprint
|
||||||
direct_blueprint = peerserver.direct_blueprint
|
direct_blueprint = peerserver.direct_blueprint
|
||||||
|
|
||||||
|
def exit_with_error(text=''):
|
||||||
|
if text != '':
|
||||||
|
logger.error(text)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
class Clandestine:
|
class Clandestine:
|
||||||
def __init__(self, pluginapi):
|
def __init__(self, pluginapi):
|
||||||
self.myCore = pluginapi.get_core()
|
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):
|
def on_init(api, data = None):
|
||||||
'''
|
'''
|
||||||
This event is called after Onionr is initialized, but before the command
|
This event is called after Onionr is initialized, but before the command
|
||||||
@ -44,4 +65,5 @@ def on_init(api, data = None):
|
|||||||
|
|
||||||
pluginapi = api
|
pluginapi = api
|
||||||
chat = Clandestine(pluginapi)
|
chat = Clandestine(pluginapi)
|
||||||
|
api.commands.register(['clandestine'], chat.create)
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user