work on direct connections and clandestine

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

View File

@ -319,6 +319,16 @@ class API:
def loadContacts():
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')
def boardContent(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)
bs = utils.bytesToStr(bl.bcontent) + '.onion'
if utils.validatePubKey(bl.signer) and utils.validateID(bs):
signer = utils.bytesToStr(bl.signer)
daemon.active_services.append(b)
daemon.active_services.append(bl.signer)
daemon.services.create_server(bl.signer, bs)
daemon.active_services.append(signer)
daemon.services.create_server(signer, bs)
daemon.decrementThreadCount('service_creator')

View File

@ -19,7 +19,7 @@
'''
# Imports some useful libraries
import locale, sys, os
import locale, sys, os, threading, json
locale.setlocale(locale.LC_ALL, '')
import onionrservices, logger
from onionrservices import bootstrapservice
@ -40,6 +40,29 @@ def exit_with_error(text=''):
class Clandestine:
def __init__(self, pluginapi):
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):
try:
@ -48,13 +71,16 @@ class Clandestine:
exit_with_error('Invalid public key specified')
except IndexError:
exit_with_error('You must specify a peer public key')
self.peer = peer
# Ask peer for transport address by creating block for them
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)
if self.myCore._utils.doGetRequest('http://%s/ping' % (peer_transport_address,), ignoreAPI=True, port=self.myCore.config.get('tor.socksport')) == 'pong!':
print('connected with', peer, 'on', peer_transport_address)
if self.myCore._utils.doGetRequest('http://%s/ping' % (peer_transport_address,), ignoreAPI=True, port=self.socks) == 'pong!':
print('connected', peer_transport_address)
threading.Thread(target=self._sender_loop).start()
def on_init(api, data = None):
'''

View File

@ -47,6 +47,8 @@ def sendto():
msg = ''
if msg == None or msg == '':
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)
return Response('success')