From 737719cb5418b20dc1736d57c20b42b72eca9e12 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Wed, 12 Jun 2019 01:44:15 -0500 Subject: [PATCH] boilerplate and comment changes, added first subdirectory readme (for communicatorutils) --- README.md | 18 ++++++++++++++- onionr/communicatorutils/README.md | 23 +++++++++++++++++++ onionr/communicatorutils/connectnewpeers.py | 6 +++++ onionr/communicatorutils/downloadblocks.py | 2 +- onionr/communicatorutils/lookupadders.py | 4 ++-- onionr/communicatorutils/lookupblocks.py | 2 +- .../onionrcommunicatortimers.py | 3 +-- onionr/communicatorutils/onionrdaemontools.py | 4 +++- onionr/communicatorutils/proxypicker.py | 7 +++--- onionr/communicatorutils/reversesync.py | 4 ---- onionr/communicatorutils/servicecreator.py | 20 ++++++++++++++++ onionr/communicatorutils/uploadblocks.py | 2 +- 12 files changed, 79 insertions(+), 16 deletions(-) create mode 100644 onionr/communicatorutils/README.md delete mode 100644 onionr/communicatorutils/reversesync.py diff --git a/README.md b/README.md index af61cc2a..34491fad 100755 --- a/README.md +++ b/README.md @@ -36,10 +36,26 @@ The whitepaper (subject to change prior to alpha release) is available [here](do * [X] 🌐 Fully p2p/decentralized, no trackers or other single points of failure * [X] 🔒 End to end encryption of user data * [X] 📢 Optional non-encrypted blocks, useful for blog posts or public file sharing -* [X] 💻 Easy API for integration to websites +* [X] 💻 Easy HTTP API for integration to websites * [X] 🕵️ Metadata analysis resistance and anonymity * [X] 📡 Transport agnosticism (no internet required) +## Software Suite + +Onionr ships with various application plugins ready for use out of the box: + +Currently usable: + +* Mail +* Public anonymous chat +* Simple webpage hosting (Will be greatly extended) +* File sharing (Work in progress) + +Not yet usable: + +* Instant messaging +* Forum/BBS + **Onionr API and functionality is subject to non-backwards compatible change during pre-alpha development** # Screenshots diff --git a/onionr/communicatorutils/README.md b/onionr/communicatorutils/README.md new file mode 100644 index 00000000..2bd7caf1 --- /dev/null +++ b/onionr/communicatorutils/README.md @@ -0,0 +1,23 @@ +# communicatorutils + +The files in this submodule handle various subtasks and utilities for the onionr communicator. + +## Files: + +connectnewpeers.py: takes a communicator instance and has it connect to as many peers as needed, and/or to a new specified peer. + +daemonqueuehandler.py: checks for new commands in the daemon queue and processes them accordingly. + +downloadblocks.py: iterates a communicator instance's block download queue and attempts to download the blocks from online peers + +lookupadders.py: ask connected peers to share their list of peer transport addresses + +onionrcommunicataortimers.py: create a timer for a function to be launched on an interval. Control how many possible instances of a timer may be running a function at once and control if the timer should be ran in a thread or not. + +onionrdaemontools.py: contains the DaemonTools class which has a lot of etc functions useful for the communicator. Deprecated. + +proxypicker.py: returns a string name for the appropriate proxy to be used with a particular peer transport address. + +servicecreator.py: iterate connection blocks and create new direct connection servers for them. + +uploadblocks.py: iterate a communicator's upload queue and upload the blocks to connected peers \ No newline at end of file diff --git a/onionr/communicatorutils/connectnewpeers.py b/onionr/communicatorutils/connectnewpeers.py index 0ba358f6..ee1eb468 100644 --- a/onionr/communicatorutils/connectnewpeers.py +++ b/onionr/communicatorutils/connectnewpeers.py @@ -40,6 +40,7 @@ def connect_new_peer_to_communicator(comm_inst, peer='', useBootstrap=False): mainPeerList = comm_inst._core.listAdders() peerList = onionrpeers.getScoreSortedPeerList(comm_inst._core) + # If we don't have enough peers connected or random chance, select new peers to try if len(peerList) < 8 or secrets.randbelow(4) == 3: tryingNew = [] for x in comm_inst.newPeers: @@ -56,15 +57,19 @@ def connect_new_peer_to_communicator(comm_inst, peer='', useBootstrap=False): for address in peerList: if not config.get('tor.v3onions') and len(address) == 62: continue + # Don't connect to our own address if address == comm_inst._core.hsAddress: continue + # Don't connect to invalid address or if its already been tried/connected, or if its cooled down if len(address) == 0 or address in tried or address in comm_inst.onlinePeers or address in comm_inst.cooldownPeer: continue if comm_inst.shutdown: return + # Ping a peer, if comm_inst.peerAction(address, 'ping') == 'pong!': time.sleep(0.1) if address not in mainPeerList: + # Add a peer to our list if it isn't already since it successfully connected networkmerger.mergeAdders(address, comm_inst._core) if address not in comm_inst.onlinePeers: logger.info('Connected to ' + address) @@ -80,6 +85,7 @@ def connect_new_peer_to_communicator(comm_inst, peer='', useBootstrap=False): comm_inst.peerProfiles.append(onionrpeers.PeerProfiles(address, comm_inst._core)) break else: + # Mark a peer as tried if they failed to respond to ping tried.append(address) logger.debug('Failed to connect to ' + address) return retData \ No newline at end of file diff --git a/onionr/communicatorutils/downloadblocks.py b/onionr/communicatorutils/downloadblocks.py index a2d4908c..720e0eae 100644 --- a/onionr/communicatorutils/downloadblocks.py +++ b/onionr/communicatorutils/downloadblocks.py @@ -1,5 +1,5 @@ ''' - Onionr - P2P Microblogging Platform & Social network + Onionr - Private P2P Communication Download blocks using the communicator instance ''' diff --git a/onionr/communicatorutils/lookupadders.py b/onionr/communicatorutils/lookupadders.py index 6b9f474d..4f861682 100644 --- a/onionr/communicatorutils/lookupadders.py +++ b/onionr/communicatorutils/lookupadders.py @@ -1,5 +1,5 @@ ''' - Onionr - P2P Anonymous Storage Network + Onionr - Private P2P Communication Lookup new peer transport addresses using the communicator ''' @@ -26,7 +26,7 @@ def lookup_new_peer_transports_with_communicator(comm_inst): for i in range(tryAmount): # Download new peer address list from random online peers if len(newPeers) > 10000: - # Dont get new peers if we have too many queued up + # Don't get new peers if we have too many queued up break peer = comm_inst.pickOnlinePeer() newAdders = comm_inst.peerAction(peer, action='pex') diff --git a/onionr/communicatorutils/lookupblocks.py b/onionr/communicatorutils/lookupblocks.py index e3e7ab2e..0994d15c 100644 --- a/onionr/communicatorutils/lookupblocks.py +++ b/onionr/communicatorutils/lookupblocks.py @@ -1,5 +1,5 @@ ''' - Onionr - P2P Microblogging Platform & Social network + Onionr - Private P2P Communication Lookup new blocks with the communicator using a random connected peer ''' diff --git a/onionr/communicatorutils/onionrcommunicatortimers.py b/onionr/communicatorutils/onionrcommunicatortimers.py index a94a7821..b7255da4 100755 --- a/onionr/communicatorutils/onionrcommunicatortimers.py +++ b/onionr/communicatorutils/onionrcommunicatortimers.py @@ -1,6 +1,5 @@ -#!/usr/bin/env python3 ''' - Onionr - P2P Anonymous Storage Network + Onionr - Private P2P Communication This file contains timer control for the communicator ''' diff --git a/onionr/communicatorutils/onionrdaemontools.py b/onionr/communicatorutils/onionrdaemontools.py index 6148041f..78e1f3dd 100755 --- a/onionr/communicatorutils/onionrdaemontools.py +++ b/onionr/communicatorutils/onionrdaemontools.py @@ -1,5 +1,5 @@ ''' - Onionr - P2P Anonymous Storage Network + Onionr - Private P2P Communication Contains the CommunicatorUtils class which contains useful functions for the communicator daemon ''' @@ -18,6 +18,8 @@ along with this program. If not, see . ''' +# MODULE DEPRECATED + import onionrexceptions, onionrpeers, onionrproofs, logger import base64, sqlite3, os from dependencies import secrets diff --git a/onionr/communicatorutils/proxypicker.py b/onionr/communicatorutils/proxypicker.py index 7e1d1e38..a6461b5c 100644 --- a/onionr/communicatorutils/proxypicker.py +++ b/onionr/communicatorutils/proxypicker.py @@ -1,7 +1,7 @@ ''' - Onionr - P2P Anonymous Storage Network + Onionr - Private P2P Communication - Just picks a proxy + Just picks a proxy to use based on a peer's address ''' ''' This program is free software: you can redistribute it and/or modify @@ -22,4 +22,5 @@ def pick_proxy(peer_address): if peer_address.endswith('.onion'): return 'tor' elif peer_address.endswith('.i2p'): - return 'i2p' \ No newline at end of file + return 'i2p' + raise ValueError("Peer address was not string ending with acceptable value") \ No newline at end of file diff --git a/onionr/communicatorutils/reversesync.py b/onionr/communicatorutils/reversesync.py deleted file mode 100644 index 55355a88..00000000 --- a/onionr/communicatorutils/reversesync.py +++ /dev/null @@ -1,4 +0,0 @@ -class ReverseSync: - def __init__(self, communicator_inst): - return - \ No newline at end of file diff --git a/onionr/communicatorutils/servicecreator.py b/onionr/communicatorutils/servicecreator.py index fbb4c5b9..c1f2c7e2 100644 --- a/onionr/communicatorutils/servicecreator.py +++ b/onionr/communicatorutils/servicecreator.py @@ -1,3 +1,22 @@ +''' + Onionr - Private P2P Communication + + Creates an onionr direct connection service by scanning all connection blocks +''' +''' + 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 communicator, onionrblockapi def service_creator(daemon): assert isinstance(daemon, communicator.OnionrCommunicatorDaemon) @@ -5,6 +24,7 @@ def service_creator(daemon): utils = core._utils # Find socket connection blocks + # TODO cache blocks and only look at recently received ones con_blocks = core.getBlocksByType('con') for b in con_blocks: if not b in daemon.active_services: diff --git a/onionr/communicatorutils/uploadblocks.py b/onionr/communicatorutils/uploadblocks.py index fe6392b4..69d0353d 100644 --- a/onionr/communicatorutils/uploadblocks.py +++ b/onionr/communicatorutils/uploadblocks.py @@ -1,5 +1,5 @@ ''' - Onionr - P2P Microblogging Platform & Social network + Onionr - Private P2P Communication Upload blocks in the upload queue to peers from the communicator '''