Browse Source

boilerplate and comment changes, added first subdirectory readme (for communicatorutils)

refactorinsert
Kevin Froman 3 years ago
parent
commit
737719cb54
  1. 18
      README.md
  2. 23
      onionr/communicatorutils/README.md
  3. 6
      onionr/communicatorutils/connectnewpeers.py
  4. 2
      onionr/communicatorutils/downloadblocks.py
  5. 4
      onionr/communicatorutils/lookupadders.py
  6. 2
      onionr/communicatorutils/lookupblocks.py
  7. 3
      onionr/communicatorutils/onionrcommunicatortimers.py
  8. 4
      onionr/communicatorutils/onionrdaemontools.py
  9. 7
      onionr/communicatorutils/proxypicker.py
  10. 4
      onionr/communicatorutils/reversesync.py
  11. 20
      onionr/communicatorutils/servicecreator.py
  12. 2
      onionr/communicatorutils/uploadblocks.py

18
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

23
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

6
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

2
onionr/communicatorutils/downloadblocks.py

@ -1,5 +1,5 @@
'''
Onionr - P2P Microblogging Platform & Social network
Onionr - Private P2P Communication
Download blocks using the communicator instance
'''

4
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')

2
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
'''

3
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
'''

4
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 <https://www.gnu.org/licenses/>.
'''
# MODULE DEPRECATED
import onionrexceptions, onionrpeers, onionrproofs, logger
import base64, sqlite3, os
from dependencies import secrets

7
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'
return 'i2p'
raise ValueError("Peer address was not string ending with acceptable value")

4
onionr/communicatorutils/reversesync.py

@ -1,4 +0,0 @@
class ReverseSync:
def __init__(self, communicator_inst):
return

20
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 <https://www.gnu.org/licenses/>.
'''
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:

2
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
'''

Loading…
Cancel
Save