work on direct connections and clandestine

This commit is contained in:
Kevin Froman 2019-04-02 11:50:09 -05:00
parent 3d1b967f1f
commit f7ae054d09
5 changed files with 46 additions and 7 deletions

View File

@ -319,6 +319,16 @@ class API:
def loadContacts(): def loadContacts():
return send_from_directory('static-data/www/friends/', 'index.html') return send_from_directory('static-data/www/friends/', 'index.html')
@app.route('/serviceactive/<pubkey>')
def serviceActive(pubkey):
try:
if pubkey in self._core.onionrInst.communicatorInst.active_services:
return Response('true')
except AttributeError as e:
print('attribute error', str(e))
pass
return Response('false')
@app.route('/board/<path:path>', endpoint='boardContent') @app.route('/board/<path:path>', endpoint='boardContent')
def boardContent(path): def boardContent(path):
return send_from_directory('static-data/www/board/', path) return send_from_directory('static-data/www/board/', path)

View File

@ -11,8 +11,9 @@ def service_creator(daemon):
bl = onionrblockapi.Block(b, core=core, decrypt=True) bl = onionrblockapi.Block(b, core=core, decrypt=True)
bs = utils.bytesToStr(bl.bcontent) + '.onion' bs = utils.bytesToStr(bl.bcontent) + '.onion'
if utils.validatePubKey(bl.signer) and utils.validateID(bs): if utils.validatePubKey(bl.signer) and utils.validateID(bs):
signer = utils.bytesToStr(bl.signer)
daemon.active_services.append(b) daemon.active_services.append(b)
daemon.active_services.append(bl.signer) daemon.active_services.append(signer)
daemon.services.create_server(bl.signer, bs) daemon.services.create_server(signer, bs)
daemon.decrementThreadCount('service_creator') daemon.decrementThreadCount('service_creator')

View File

@ -70,7 +70,7 @@ class ConnectionServer:
response = controller.create_ephemeral_hidden_service({80: service_port}, await_publication = True, key_type='NEW', key_content = 'ED25519-V3') response = controller.create_ephemeral_hidden_service({80: service_port}, await_publication = True, key_type='NEW', key_content = 'ED25519-V3')
self.core_inst.keyStore.put('dc-' + response.service_id, self.core_inst._utils.bytesToStr(peer)) self.core_inst.keyStore.put('dc-' + response.service_id, self.core_inst._utils.bytesToStr(peer))
self.core_inst._utils.doPostRequest('http://' + address + '/bs/' + response.service_id, port=socks) self.core_inst._utils.doPostRequest('http://' + address + '/bs/' + response.service_id, port=socks)
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()
self.core_inst.keyStore.delete('dc-' + response.service_id) self.core_inst.keyStore.delete('dc-' + response.service_id)
http_server.stop() http_server.stop()

View File

@ -19,7 +19,7 @@
''' '''
# Imports some useful libraries # Imports some useful libraries
import locale, sys, os import locale, sys, os, threading, json
locale.setlocale(locale.LC_ALL, '') locale.setlocale(locale.LC_ALL, '')
import onionrservices, logger import onionrservices, logger
from onionrservices import bootstrapservice from onionrservices import bootstrapservice
@ -40,6 +40,29 @@ def exit_with_error(text=''):
class Clandestine: class Clandestine:
def __init__(self, pluginapi): def __init__(self, pluginapi):
self.myCore = pluginapi.get_core() self.myCore = pluginapi.get_core()
self.peer = None
self.transport = None
self.shutdown = False
def _sender_loop(self):
print('Enter a message to send, with ctrl-d or -s on a new line.')
print('-c on a new line or ctrl-c stops')
message = ''
while not self.shutdown:
try:
message += input()
if message == '-s':
raise EOFError
elif message == '-c':
raise KeyboardInterrupt
else:
message += '\n'
except EOFError:
message = json.dumps({'m': message, 't': self.myCore._utils.getEpoch()})
print(self.myCore._utils.doPostRequest('http://%s/clandestine/sendto' % (self.transport,), port=self.socks, data=message))
message = ''
except KeyboardInterrupt:
self.shutdown = True
def create(self): def create(self):
try: try:
@ -48,13 +71,16 @@ class Clandestine:
exit_with_error('Invalid public key specified') exit_with_error('Invalid public key specified')
except IndexError: except IndexError:
exit_with_error('You must specify a peer public key') exit_with_error('You must specify a peer public key')
self.peer = peer
# Ask peer for transport address by creating block for them # Ask peer for transport address by creating block for them
peer_transport_address = bootstrapservice.bootstrap_client_service(peer, self.myCore) peer_transport_address = bootstrapservice.bootstrap_client_service(peer, self.myCore)
self.transport = peer_transport_address
self.socks = self.myCore.config.get('tor.socksport')
print(peer_transport_address) print('connected with', peer, 'on', peer_transport_address)
if self.myCore._utils.doGetRequest('http://%s/ping' % (peer_transport_address,), ignoreAPI=True, port=self.myCore.config.get('tor.socksport')) == 'pong!': if self.myCore._utils.doGetRequest('http://%s/ping' % (peer_transport_address,), ignoreAPI=True, port=self.socks) == 'pong!':
print('connected', peer_transport_address) print('connected', peer_transport_address)
threading.Thread(target=self._sender_loop).start()
def on_init(api, data = None): def on_init(api, data = None):
''' '''

View File

@ -47,6 +47,8 @@ def sendto():
msg = '' msg = ''
if msg == None or msg == '': if msg == None or msg == '':
msg = json.dumps({'m': 'hello world', 't': core_inst._utils.getEpoch()}) msg = json.dumps({'m': 'hello world', 't': core_inst._utils.getEpoch()})
else:
msg = json.dumps(msg)
core_inst._utils.localCommand('/clandestine/addrec/%s' % (g.peer,), post=True, postData=msg) core_inst._utils.localCommand('/clandestine/addrec/%s' % (g.peer,), post=True, postData=msg)
return Response('success') return Response('success')