From 80098d39c16198248a2a02951b75f062d35f1910 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sat, 17 Aug 2019 02:27:33 -0500 Subject: [PATCH] connections now able to be created and detected in webui --- .gitignore | 2 ++ onionr/httpapi/directconnections/__init__.py | 2 +- onionr/onionrservices/bootstrapservice.py | 2 +- onionr/static-data/www/chat/css/convos.css | 4 ++++ onionr/static-data/www/chat/js/main.js | 21 +++++++++++++++++-- .../www/shared/direct-connections.js | 6 ++++-- 6 files changed, 31 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index e6af0243..672aadb2 100755 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ onionr/data/config.ini onionr/data/*.db onionr/data-old/* onionr/data* +onionr/tor +onionr/tor.exe onionr/testdata onionr/*.pyc onionr/*.log diff --git a/onionr/httpapi/directconnections/__init__.py b/onionr/httpapi/directconnections/__init__.py index 08b70eae..7a626303 100644 --- a/onionr/httpapi/directconnections/__init__.py +++ b/onionr/httpapi/directconnections/__init__.py @@ -55,6 +55,6 @@ class DirectConnectionManagement: """Spawn a thread that will create the client and eventually add it to the communicator.active_services """ - threading.Thread(target=onionrservices.OnionrServices().create_client, args=[pubkey, communicator]).start() + threading.Thread(target=onionrservices.OnionrServices().create_client, args=[pubkey, communicator], daemon=True).start() return Response(resp) \ No newline at end of file diff --git a/onionr/onionrservices/bootstrapservice.py b/onionr/onionrservices/bootstrapservice.py index b824ae24..4304cf6f 100755 --- a/onionr/onionrservices/bootstrapservice.py +++ b/onionr/onionrservices/bootstrapservice.py @@ -85,6 +85,6 @@ def bootstrap_client_service(peer, comm_inst=None, bootstrap_timeout=300): # This line reached when server is shutdown by being bootstrapped # Add the address to the client pool if not comm_inst is None: - comm_inst.direct_connection_clients[peer] = bs_id + comm_inst.direct_connection_clients[peer] = response.service_id # Now that the bootstrap server has received a server, return the address return key_store.get(bs_id) diff --git a/onionr/static-data/www/chat/css/convos.css b/onionr/static-data/www/chat/css/convos.css index 7196e84f..4e65b76b 100644 --- a/onionr/static-data/www/chat/css/convos.css +++ b/onionr/static-data/www/chat/css/convos.css @@ -12,4 +12,8 @@ .chatContent{ padding-right: 5%; +} + +.connectStatus{ + float: right; } \ No newline at end of file diff --git a/onionr/static-data/www/chat/js/main.js b/onionr/static-data/www/chat/js/main.js index 20c8fb62..7e918956 100755 --- a/onionr/static-data/www/chat/js/main.js +++ b/onionr/static-data/www/chat/js/main.js @@ -18,16 +18,33 @@ */ friendList = {} convoListElement = document.getElementsByClassName('conversationList')[0] +firstConvoLoad = true function createConvoList(){ - + convoListElement.innerHTML = "" for (friend in friendList){ - var convoEntry = document.createElement('li') + let convoEntry = document.createElement('li') + let connectStatus = document.createElement('span') + + if (! firstConvoLoad){ + connectStatus.innerText = " X" + connectStatus.style.color = "red" + connectStatus.classList.add("connectStatus") + console.log(direct_connections) + if (direct_connections.hasOwnProperty(friend)){ + connectStatus.innerText = " ✅" + connectStatus.style.color = "green" + } + } + convoEntry.classList.add('convoEntry') convoEntry.setAttribute('data-pubkey', friend) convoEntry.innerText = friendList[friend] + convoEntry.appendChild(connectStatus) convoListElement.append(convoEntry) + firstConvoLoad = false } + setTimeout(function(){createConvoList()}, 3000) } fetch('/friends/list', { diff --git a/onionr/static-data/www/shared/direct-connections.js b/onionr/static-data/www/shared/direct-connections.js index 5bab83f1..8fda74b8 100644 --- a/onionr/static-data/www/shared/direct-connections.js +++ b/onionr/static-data/www/shared/direct-connections.js @@ -25,7 +25,7 @@ let waitForConnection = function(pubkey){ }}) .then((resp) => resp.text()) .then(function(resp) { - if (resp.text === ""){ + if (resp === ""){ // Try to get the client address again again in a few seconds setTimeout(function(){waitForConnection(pubkey)}, 3000) } @@ -51,9 +51,11 @@ let createConnection = function(pubkey){ }}) .then((resp) => resp.text()) .then(function(resp) { - alert(resp) if (resp === "pending"){ setTimeout(function(){waitForConnection(pubkey)}, 3000) } + else{ + direct_connections[pubkey] = resp + } }) } \ No newline at end of file