work on chat

This commit is contained in:
Kevin Froman 2019-08-16 15:41:56 -05:00
parent d8af21ab16
commit 602bc62897
7 changed files with 88 additions and 11 deletions

View File

@ -136,6 +136,9 @@ class OnionrCommunicatorDaemon:
else: else:
self.services = None self.services = None
# {peer_pubkey: ephemeral_address}, the address to reach them
self.direct_connection_clients = {}
# This timer creates deniable blocks, in an attempt to further obfuscate block insertion metadata # This timer creates deniable blocks, in an attempt to further obfuscate block insertion metadata
if config.get('general.insert_deniable_blocks', True): if config.get('general.insert_deniable_blocks', True):
deniableBlockTimer = OnionrCommunicatorTimers(self, deniableinserts.insert_deniable_block, 180, myArgs=[self], requiresPeer=True, maxThreads=1) deniableBlockTimer = OnionrCommunicatorTimers(self, deniableinserts.insert_deniable_block, 180, myArgs=[self], requiresPeer=True, maxThreads=1)

View File

@ -18,10 +18,9 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
''' '''
from flask import Response, Blueprint from flask import Response, Blueprint
import deadsimplekv
def _in_pool(pubkey, communicator): import filepaths
if pubkey in communicator.active_services
class DirectConnectionManagement: class DirectConnectionManagement:
def __init__(self, client_api): def __init__(self, client_api):
@ -29,6 +28,23 @@ class DirectConnectionManagement:
self.direct_conn_management_bp = direct_conn_management_bp self.direct_conn_management_bp = direct_conn_management_bp
communicator = client_api._too_many.get('OnionrCommunicatorDaemon') communicator = client_api._too_many.get('OnionrCommunicatorDaemon')
@direct_conn_management_bp.route('/isconnected/<pubkey>') cache = communicator.deadsimplekv(filepaths.cached_storage)
@direct_conn_management_bp.route('/dc-client/isconnected/<pubkey>')
def is_connected(pubkey): def is_connected(pubkey):
return resp = ""
if pubkey in communicator.direct_connection_clients:
resp = communicator.direct_connection_clients[pubkey]
return Response(resp)
@direct_conn_management_bp.route('/dc-client/connect/<pubkey>')
def make_new_connection(pubkey):
resp = "pending"
if pubkey in communicator.direct_connection_clients:
resp = communicator.active_services[pubkey]
"""Spawn a thread that will create the client and eventually add it to the
communicator.active_services
"""
return Response(resp)

View File

@ -86,7 +86,6 @@ class PrivateEndpoints:
@private_endpoints_bp.route('/getstats') @private_endpoints_bp.route('/getstats')
def getStats(): def getStats():
# returns node stats # returns node stats
#return Response("disabled")
while True: while True:
try: try:
return Response(client_api._too_many.get(SerializedData).getStats()) return Response(client_api._too_many.get(SerializedData).getStats())

View File

@ -52,7 +52,9 @@ class OnionrServices:
else: else:
return False return False
def create_client(self, peer): def create_client(self, peer, comm_inst=None):
# Create ephemeral onion service to bootstrap connection # Create ephemeral onion service to bootstrap connection
address = bootstrapservice.bootstrap_client_service(peer) address = bootstrapservice.bootstrap_client_service(peer)
if not comm_inst is None:
comm_inst.direct_connection_clients[peer] = address
return address return address

View File

@ -80,8 +80,10 @@ class ConnectionServer:
raise ConnectionError('Could not reach %s bootstrap address %s' % (peer, address)) raise ConnectionError('Could not reach %s bootstrap address %s' % (peer, address))
else: else:
# If no connection error, create the service and save it to local global key store # If no connection error, create the service and save it to local global key store
key_store.put('dc-' + response.service_id, bytesconverter.bytes_to_str(peer)) peer = bytesconverter.bytes_to_str(peer)
key_store.put('dc-' + peer, response.service_id)
key_store.flush()
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()
http_server.stop() http_server.stop()
key_store.delete('dc-' + response.service_id) key_store.delete('dc-' + peer)

View File

@ -0,0 +1,55 @@
/*
Onionr - Private P2P Communication
Functions to detect
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/>
*/
direct_connections = {}
let waitForConnection = function(pubkey){
fetch('/dc-client/isconnected/' + pubkey, {
headers: {
"token": webpass
}})
.then(function(resp) {
if (resp.ok){
if (resp.text === ""){
// Try to get the client address again again in a few seconds
setTimeout(function(){waitForConnection(pubkey)}, 3000)
}
else{
// add to the dc object
direct_connections[pubkey] = resp
}
}
})
}
let createConnection = function(pubkey){
if (direct_connections.hasOwnProperty(pubkey)){
return
}
fetch('/dc-client/connect/' + pubkey, {
headers: {
"token": webpass
}})
.then(function(resp) {
if (resp.ok){
if (resp.text === "pending"){
setTimeout(function(){waitForConnection(pubkey)}, 3000)
}
}
})
}