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

View File

@ -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:

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)")
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):

View File

@ -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:
@ -42,26 +48,27 @@ class OnionrCLIUI:
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)
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