diff --git a/onionr/communicator.py b/onionr/communicator.py index 54a512ac..14817a07 100755 --- a/onionr/communicator.py +++ b/onionr/communicator.py @@ -19,15 +19,13 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . ''' -import sys, os, core, config, json, requests, time, logger, threading, base64, onionr, uuid +import sys, os, core, config, json, requests, time, logger, threading, base64, onionr, uuid, binascii +from dependencies import secrets +from utils import networkmerger import onionrexceptions, onionrpeers, onionrevents as events, onionrplugins as plugins, onionrblockapi as block from communicatorutils import onionrdaemontools import onionrsockets, onionr, onionrproofs -import binascii -from communicatorutils import onionrcommunicatortimers -from dependencies import secrets -from defusedxml import minidom -from utils import networkmerger +from communicatorutils import onionrcommunicatortimers, proxypicker OnionrCommunicatorTimers = onionrcommunicatortimers.OnionrCommunicatorTimers @@ -48,10 +46,6 @@ class OnionrCommunicatorDaemon: self.proxyPort = proxyPort self._core = onionrInst.onionrCore - # initialize NIST beacon salt and time - self.nistSaltTimestamp = 0 - self.powSalt = 0 - self.blocksToUpload = [] # loop time.sleep delay in seconds @@ -610,11 +604,7 @@ class OnionrCommunicatorDaemon: triedPeers.append(peer) url = 'http://' + peer + '/upload' data = {'block': block.Block(bl).getRaw()} - proxyType = '' - if peer.endswith('.onion'): - proxyType = 'tor' - elif peer.endswith('.i2p'): - proxyType = 'i2p' + proxyType = proxypicker.pick_proxy(peer) logger.info("Uploading block to " + peer) if not self._core._utils.doPostRequest(url, data=data, proxyType=proxyType) == False: self._core._utils.localCommand('waitforshare/' + bl, post=True) diff --git a/onionr/communicatorutils/onionrdaemontools.py b/onionr/communicatorutils/onionrdaemontools.py index 70b405f7..d2b9ef17 100755 --- a/onionr/communicatorutils/onionrdaemontools.py +++ b/onionr/communicatorutils/onionrdaemontools.py @@ -30,16 +30,22 @@ class DaemonTools: ''' def __init__(self, daemon): self.daemon = daemon + self.announceProgress = {} self.announceCache = {} def announceNode(self): '''Announce our node to our peers''' retData = False announceFail = False + + # Do not let announceCache get too large + if len(self.announceCache) >= 10000: + self.announceCache.popitem() + if self.daemon._core.config.get('general.security_level', 0) == 0: # Announce to random online peers for i in self.daemon.onlinePeers: - if not i in self.announceCache: + if not i in self.announceCache and not i in self.announceProgress: peer = i break else: @@ -66,7 +72,9 @@ class DaemonTools: elif len(existingRand) > 0: data['random'] = existingRand else: + self.announceProgress[peer] = True proof = onionrproofs.DataPOW(combinedNodes, forceDifficulty=4) + del self.announceProgress[peer] try: data['random'] = base64.b64encode(proof.waitForResult()[1]) except TypeError: diff --git a/onionr/communicatorutils/proxypicker.py b/onionr/communicatorutils/proxypicker.py new file mode 100644 index 00000000..7e1d1e38 --- /dev/null +++ b/onionr/communicatorutils/proxypicker.py @@ -0,0 +1,25 @@ +''' + Onionr - P2P Anonymous Storage Network + + Just picks a proxy +''' +''' + 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 . +''' + +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 diff --git a/onionr/onionr.py b/onionr/onionr.py index 8e64214b..7acd2564 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -42,9 +42,9 @@ except ImportError: raise Exception("You need the PySocks module (for use with socks5 proxy to use Tor)") ONIONR_TAGLINE = 'Anonymous P2P Platform - GPLv3 - https://Onionr.net' -ONIONR_VERSION = '0.5.0' # for debugging and stuff +ONIONR_VERSION = '0.0.0' # for debugging and stuff ONIONR_VERSION_TUPLE = tuple(ONIONR_VERSION.split('.')) # (MAJOR, MINOR, VERSION) -API_VERSION = '5' # 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 = '0' # 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. class Onionr: def __init__(self): diff --git a/onionr/onionrfragment.py b/onionr/onionrfragment/__init__.py similarity index 100% rename from onionr/onionrfragment.py rename to onionr/onionrfragment/__init__.py diff --git a/onionr/static-data/default-plugins/cliui/main.py b/onionr/static-data/default-plugins/cliui/main.py index 59b59b0c..e1398a13 100755 --- a/onionr/static-data/default-plugins/cliui/main.py +++ b/onionr/static-data/default-plugins/cliui/main.py @@ -19,8 +19,10 @@ ''' # Imports some useful libraries -import logger, config, threading, time, uuid, subprocess, sys +import threading, time, uuid, subprocess, sys +import config, logger from onionrblockapi import Block +import onionrplugins plugin_name = 'cliui' PLUGIN_VERSION = '0.0.1' @@ -29,7 +31,11 @@ class OnionrCLIUI: def __init__(self, apiInst): self.api = apiInst self.myCore = apiInst.get_core() - return + self.shutdown = False + self.running = 'undetermined' + enabled = onionrplugins.get_enabled_plugins() + self.mail_enabled = 'pms' in enabled + self.flow_enabled = 'flow' in enabled def subCommand(self, command, args=None): try: @@ -41,6 +47,14 @@ class OnionrCLIUI: subprocess.call(['./onionr.py', command]) except KeyboardInterrupt: pass + + def isRunning(self): + while not self.shutdown: + if self.myCore._utils.localCommand('ping', maxWait=5) == 'pong!': + self.running = 'Yes' + else: + self.running = 'No' + time.sleep(5) def refresh(self): print('\n' * 80 + logger.colors.reset) @@ -48,20 +62,13 @@ class OnionrCLIUI: def start(self): '''Main CLI UI interface menu''' showMenu = True - isOnline = 'No' - firstRun = True choice = '' - if self.myCore._utils.localCommand('ping', maxWait=10) == 'pong!': - firstRun = False + threading.Thread(target=self.isRunning).start() while showMenu: - if self.myCore._utils.localCommand('ping', maxWait=2) == 'pong!': - isOnline = "Yes" - else: - isOnline = "No" - - print('''Daemon Running: ''' + isOnline + ''' -1. Flow (Anonymous public chat, use at your own risk) + print('Onionr\n------') + print('''Daemon Running: ''' + self.running + ''' +1. Flow (Anonymous public shout box, use at your own risk) 2. Mail (Secure email-like service) 3. File Sharing 4. Quit (Does not shutdown daemon) @@ -72,21 +79,27 @@ class OnionrCLIUI: choice = "quit" if choice in ("flow", "1"): - self.subCommand("flow") + if self.flow_enabled: + self.subCommand("flow") + else: + print('Plugin not enabled') elif choice in ("2", "mail"): - self.subCommand("mail") + if self.mail_enabled: + self.subCommand("mail") + else: + print('Plugin not enabled') elif choice in ("3", "file sharing", "file"): filename = input("Enter full path to file: ").strip() self.subCommand("addfile", filename) elif choice in ("4", "quit"): showMenu = False + self.shutdown = True elif choice == "": pass else: logger.error("Invalid choice") return - def on_init(api, data = None): ''' This event is called after Onionr is initialized, but before the command