From fc7db42deb790e9ad7ab6336fa86b1df8ed2c7a6 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sat, 10 Oct 2020 04:26:51 +0000 Subject: [PATCH] do not upload plaintext to peers that do not support it, closes #14 --- src/communicatorutils/connectnewpeers.py | 8 ++++++++ src/communicatorutils/uploadblocks/__init__.py | 3 +++ src/etc/onionrvalues.py | 4 ++-- src/httpapi/miscpublicapi/endpoints.py | 5 +++++ src/setupkvvars/__init__.py | 1 + 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/communicatorutils/connectnewpeers.py b/src/communicatorutils/connectnewpeers.py index a95e724d..913ce81c 100755 --- a/src/communicatorutils/connectnewpeers.py +++ b/src/communicatorutils/connectnewpeers.py @@ -100,7 +100,15 @@ def connect_new_peer_to_communicator(shared_state, peer='', useBootstrap=False): else: kv.get('peerProfiles').append( onionrpeers.PeerProfiles(address)) + try: + del kv.get('plaintextDisabledPeers')[address] + except KeyError: + pass + if peeraction.peer_action( + shared_state, address, 'plaintext') == 'false': + kv.get('plaintextDisabledPeers')[address] = True break + else: # Mark a peer as tried if they failed to respond to ping tried.append(address) diff --git a/src/communicatorutils/uploadblocks/__init__.py b/src/communicatorutils/uploadblocks/__init__.py index 084595af..11b67e0a 100755 --- a/src/communicatorutils/uploadblocks/__init__.py +++ b/src/communicatorutils/uploadblocks/__init__.py @@ -68,6 +68,9 @@ def upload_blocks_from_communicator(comm_inst: 'OnionrCommunicatorDaemon'): for _ in range(min(len(kv.get('onlinePeers')), 6)): try: peer = onlinepeers.pick_online_peer(kv) + if peer in kv.get('plaintextDisabledPeers'): + logger.info(f"Cannot upload plaintext block to peer that denies it {peer}") # noqa + continue except onionrexceptions.OnlinePeerNeeded: continue try: diff --git a/src/etc/onionrvalues.py b/src/etc/onionrvalues.py index 9a7691a8..fdc849b8 100755 --- a/src/etc/onionrvalues.py +++ b/src/etc/onionrvalues.py @@ -23,10 +23,10 @@ import filepaths DENIABLE_PEER_ADDRESS = "OVPCZLOXD6DC5JHX4EQ3PSOGAZ3T24F75HQLIUZSDSMYPEOXCPFA" PASSWORD_LENGTH = 25 ONIONR_TAGLINE = 'Private P2P Communication - GPLv3 - https://Onionr.net' -ONIONR_VERSION = '6.0.0' +ONIONR_VERSION = '6.1.0' ONIONR_VERSION_CODENAME = 'Genesis' ONIONR_VERSION_TUPLE = tuple(ONIONR_VERSION.split('.')) # (MAJOR, MINOR, VERSION) -API_VERSION = '2' # increments of 1; only change when something fundamental about how the API works changes. This way other nodes know how to communicate without learning too much information about you. +API_VERSION = '3' # increments of 1; only change when something fundamental about how the API works changes. This way other nodes know how to communicate without learning too much information about you. MIN_PY_VERSION = 7 # min version of 7 so we can take advantage of non-cyclic type hints DEVELOPMENT_MODE = False IS_QUBES = False diff --git a/src/httpapi/miscpublicapi/endpoints.py b/src/httpapi/miscpublicapi/endpoints.py index eefb9788..9c575c07 100644 --- a/src/httpapi/miscpublicapi/endpoints.py +++ b/src/httpapi/miscpublicapi/endpoints.py @@ -58,6 +58,11 @@ class PublicEndpoints: return send_from_directory( config.get('www.public.path', 'static-data/www/public/'), path) + + @public_endpoints_bp.route('/plaintext') + def plaintext_enabled_endpoint(): + return Response(str(config.get("general.store_plaintext_blocks", True)).lower()) + @public_endpoints_bp.route('/ping') def ping(): # Endpoint to test if nodes are up diff --git a/src/setupkvvars/__init__.py b/src/setupkvvars/__init__.py index fc0809e9..af3b156a 100644 --- a/src/setupkvvars/__init__.py +++ b/src/setupkvvars/__init__.py @@ -27,6 +27,7 @@ if TYPE_CHECKING: def setup_kv(shared_vars: 'DeadSimpleKV'): """Init initial pseudo-variables.""" + shared_vars.put('plaintextDisabledPeers', {}) shared_vars.put('blockQueue', {}) shared_vars.put('shutdown', False) shared_vars.put('onlinePeers', [])