From a375117dd8813721e3f7721fdb9f75132c32b136 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Wed, 21 Aug 2019 03:03:24 -0500 Subject: [PATCH] work on chat --- docs/dev/specs/forward-secrecy.md | 5 ++++ onionr/communicatorutils/servicecreator.py | 9 +++++-- onionr/onionrservices/__init__.py | 8 +++++- onionr/onionrservices/serverexists.py | 30 ++++++++++++++++++++++ onionr/static-data/www/chat/js/resizes.js | 18 +++++++++++++ 5 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 docs/dev/specs/forward-secrecy.md create mode 100644 onionr/onionrservices/serverexists.py diff --git a/docs/dev/specs/forward-secrecy.md b/docs/dev/specs/forward-secrecy.md new file mode 100644 index 00000000..27851ae8 --- /dev/null +++ b/docs/dev/specs/forward-secrecy.md @@ -0,0 +1,5 @@ +# Onionr Forward Secrecy Spec v0.0.0 + +# Introduction + +Due to the natural trade-offs of implementing [forward secrecy](https://en.wikipedia.org/wiki/Forward_secrecy) in a distributed, decentralized system, Onionr has optional \ No newline at end of file diff --git a/onionr/communicatorutils/servicecreator.py b/onionr/communicatorutils/servicecreator.py index 17f6a19c..f1dbb78d 100755 --- a/onionr/communicatorutils/servicecreator.py +++ b/onionr/communicatorutils/servicecreator.py @@ -18,8 +18,10 @@ along with this program. If not, see . ''' import communicator, onionrblockapi +import logger from onionrutils import stringvalidators, bytesconverter from coredb import blockmetadb +from onionrservices import server_exists def service_creator(daemon): assert isinstance(daemon, communicator.OnionrCommunicatorDaemon) @@ -30,10 +32,13 @@ def service_creator(daemon): if not b in daemon.active_services: bl = onionrblockapi.Block(b, decrypt=True) bs = bytesconverter.bytes_to_str(bl.bcontent) + '.onion' + if server_exists(bl.signer): + continue if stringvalidators.validate_pub_key(bl.signer) and stringvalidators.validate_transport(bs): signer = bytesconverter.bytes_to_str(bl.signer) daemon.active_services.append(b) daemon.active_services.append(signer) - daemon.services.create_server(signer, bs, daemon) - + if not daemon.services.create_server(signer, bs, daemon): + daemon.active_services.remove(b) + daemon.active_services.remove(signer) daemon.decrementThreadCount('service_creator') diff --git a/onionr/onionrservices/__init__.py b/onionr/onionrservices/__init__.py index 975d6e90..a2a6a26a 100755 --- a/onionr/onionrservices/__init__.py +++ b/onionr/onionrservices/__init__.py @@ -19,9 +19,10 @@ ''' import time import stem -from . import connectionserver, bootstrapservice +from . import connectionserver, bootstrapservice, serverexists from onionrutils import stringvalidators, basicrequests import config +server_exists = serverexists.server_exists class OnionrServices: ''' Create a client or server for connecting to peer interfaces @@ -55,5 +56,10 @@ class OnionrServices: @staticmethod def create_client(peer, comm_inst=None): # Create ephemeral onion service to bootstrap connection + if not comm_inst == None: + try: + return comm_inst.direct_connection_clients[peer] + except KeyError: + pass address = bootstrapservice.bootstrap_client_service(peer, comm_inst) return address diff --git a/onionr/onionrservices/serverexists.py b/onionr/onionrservices/serverexists.py new file mode 100644 index 00000000..b7b049d8 --- /dev/null +++ b/onionr/onionrservices/serverexists.py @@ -0,0 +1,30 @@ +''' + Onionr - Private P2P Communication + + Function to check if an onion server is created for a peer or not +''' +''' + 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 . +''' +import deadsimplekv + +import filepaths +from onionrutils import bytesconverter + +def server_exists(peer: str) -> bool: + '''checks if an onion server is created for a peer or not''' + peer = bytesconverter.bytes_to_str(peer) + kv = deadsimplekv.DeadSimpleKV(filepaths.cached_storage) + kv.refresh() + return not kv.get('dc-' + peer) is None \ No newline at end of file diff --git a/onionr/static-data/www/chat/js/resizes.js b/onionr/static-data/www/chat/js/resizes.js index 94fc1ebe..5201ff91 100644 --- a/onionr/static-data/www/chat/js/resizes.js +++ b/onionr/static-data/www/chat/js/resizes.js @@ -1,3 +1,21 @@ +/* + Onionr - Private P2P Communication + + Resize chat elements to help with responsiveness + + 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 +*/ let doResize = function(){ let chatInput = document.getElementsByClassName('chatInput')[0] chatInput.style.width = "50%";