bug fixes

This commit is contained in:
Kevin Froman 2019-03-04 16:29:44 -06:00
parent 45221291fa
commit 9b6553511b
6 changed files with 70 additions and 34 deletions

View File

@ -19,15 +19,13 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
''' '''
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 import onionrexceptions, onionrpeers, onionrevents as events, onionrplugins as plugins, onionrblockapi as block
from communicatorutils import onionrdaemontools from communicatorutils import onionrdaemontools
import onionrsockets, onionr, onionrproofs import onionrsockets, onionr, onionrproofs
import binascii from communicatorutils import onionrcommunicatortimers, proxypicker
from communicatorutils import onionrcommunicatortimers
from dependencies import secrets
from defusedxml import minidom
from utils import networkmerger
OnionrCommunicatorTimers = onionrcommunicatortimers.OnionrCommunicatorTimers OnionrCommunicatorTimers = onionrcommunicatortimers.OnionrCommunicatorTimers
@ -48,10 +46,6 @@ class OnionrCommunicatorDaemon:
self.proxyPort = proxyPort self.proxyPort = proxyPort
self._core = onionrInst.onionrCore self._core = onionrInst.onionrCore
# initialize NIST beacon salt and time
self.nistSaltTimestamp = 0
self.powSalt = 0
self.blocksToUpload = [] self.blocksToUpload = []
# loop time.sleep delay in seconds # loop time.sleep delay in seconds
@ -610,11 +604,7 @@ class OnionrCommunicatorDaemon:
triedPeers.append(peer) triedPeers.append(peer)
url = 'http://' + peer + '/upload' url = 'http://' + peer + '/upload'
data = {'block': block.Block(bl).getRaw()} data = {'block': block.Block(bl).getRaw()}
proxyType = '' proxyType = proxypicker.pick_proxy(peer)
if peer.endswith('.onion'):
proxyType = 'tor'
elif peer.endswith('.i2p'):
proxyType = 'i2p'
logger.info("Uploading block to " + peer) logger.info("Uploading block to " + peer)
if not self._core._utils.doPostRequest(url, data=data, proxyType=proxyType) == False: if not self._core._utils.doPostRequest(url, data=data, proxyType=proxyType) == False:
self._core._utils.localCommand('waitforshare/' + bl, post=True) self._core._utils.localCommand('waitforshare/' + bl, post=True)

View File

@ -30,16 +30,22 @@ class DaemonTools:
''' '''
def __init__(self, daemon): def __init__(self, daemon):
self.daemon = daemon self.daemon = daemon
self.announceProgress = {}
self.announceCache = {} self.announceCache = {}
def announceNode(self): def announceNode(self):
'''Announce our node to our peers''' '''Announce our node to our peers'''
retData = False retData = False
announceFail = 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: if self.daemon._core.config.get('general.security_level', 0) == 0:
# Announce to random online peers # Announce to random online peers
for i in self.daemon.onlinePeers: 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 peer = i
break break
else: else:
@ -66,7 +72,9 @@ class DaemonTools:
elif len(existingRand) > 0: elif len(existingRand) > 0:
data['random'] = existingRand data['random'] = existingRand
else: else:
self.announceProgress[peer] = True
proof = onionrproofs.DataPOW(combinedNodes, forceDifficulty=4) proof = onionrproofs.DataPOW(combinedNodes, forceDifficulty=4)
del self.announceProgress[peer]
try: try:
data['random'] = base64.b64encode(proof.waitForResult()[1]) data['random'] = base64.b64encode(proof.waitForResult()[1])
except TypeError: except TypeError:

View File

@ -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 <https://www.gnu.org/licenses/>.
'''
def pick_proxy(peer_address):
if peer_address.endswith('.onion'):
return 'tor'
elif peer_address.endswith('.i2p'):
return 'i2p'

View File

@ -42,9 +42,9 @@ except ImportError:
raise Exception("You need the PySocks module (for use with socks5 proxy to use Tor)") 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_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) 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: class Onionr:
def __init__(self): def __init__(self):

View File

@ -19,8 +19,10 @@
''' '''
# Imports some useful libraries # 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 from onionrblockapi import Block
import onionrplugins
plugin_name = 'cliui' plugin_name = 'cliui'
PLUGIN_VERSION = '0.0.1' PLUGIN_VERSION = '0.0.1'
@ -29,7 +31,11 @@ class OnionrCLIUI:
def __init__(self, apiInst): def __init__(self, apiInst):
self.api = apiInst self.api = apiInst
self.myCore = apiInst.get_core() 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): def subCommand(self, command, args=None):
try: try:
@ -42,26 +48,27 @@ class OnionrCLIUI:
except KeyboardInterrupt: except KeyboardInterrupt:
pass 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): def refresh(self):
print('\n' * 80 + logger.colors.reset) print('\n' * 80 + logger.colors.reset)
def start(self): def start(self):
'''Main CLI UI interface menu''' '''Main CLI UI interface menu'''
showMenu = True showMenu = True
isOnline = 'No'
firstRun = True
choice = '' choice = ''
if self.myCore._utils.localCommand('ping', maxWait=10) == 'pong!': threading.Thread(target=self.isRunning).start()
firstRun = False
while showMenu: while showMenu:
if self.myCore._utils.localCommand('ping', maxWait=2) == 'pong!': print('Onionr\n------')
isOnline = "Yes" print('''Daemon Running: ''' + self.running + '''
else: 1. Flow (Anonymous public shout box, use at your own risk)
isOnline = "No"
print('''Daemon Running: ''' + isOnline + '''
1. Flow (Anonymous public chat, use at your own risk)
2. Mail (Secure email-like service) 2. Mail (Secure email-like service)
3. File Sharing 3. File Sharing
4. Quit (Does not shutdown daemon) 4. Quit (Does not shutdown daemon)
@ -72,21 +79,27 @@ class OnionrCLIUI:
choice = "quit" choice = "quit"
if choice in ("flow", "1"): 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"): 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"): elif choice in ("3", "file sharing", "file"):
filename = input("Enter full path to file: ").strip() filename = input("Enter full path to file: ").strip()
self.subCommand("addfile", filename) self.subCommand("addfile", filename)
elif choice in ("4", "quit"): elif choice in ("4", "quit"):
showMenu = False showMenu = False
self.shutdown = True
elif choice == "": elif choice == "":
pass pass
else: else:
logger.error("Invalid choice") logger.error("Invalid choice")
return return
def on_init(api, data = None): def on_init(api, data = None):
''' '''
This event is called after Onionr is initialized, but before the command This event is called after Onionr is initialized, but before the command