+ added powchoice.py to use old pow on windows, temporary fix for subprocess method not working there

* various bug fixes
This commit is contained in:
KF 2019-06-14 20:31:01 -05:00
parent f5b3406684
commit 5e73f83c57
9 changed files with 51 additions and 28 deletions

View File

@ -29,7 +29,7 @@ import httpapi
from httpapi import friendsapi, profilesapi, configapi, miscpublicapi
from onionrservices import httpheaders
import onionr
config.reload()
class FDSafeHandler(WSGIHandler):
'''Our WSGI handler. Doesn't do much non-default except timeouts'''
def handle(self):
@ -57,6 +57,7 @@ def setBindIP(filePath=''):
else:
data = '127.0.0.1'
if filePath != '':
print(filePath)
with open(filePath, 'w') as bindFile:
bindFile.write(data)
return data

View File

@ -25,7 +25,7 @@ import onionrutils, onionrcrypto, onionrproofs, onionrevents as events, onionrex
import onionrblacklist
from onionrusers import onionrusers
import dbcreator, onionrstorage, serializeddata, subprocesspow
from etc import onionrvalues
from etc import onionrvalues, powchoice
if sys.version_info < (3, 6):
try:
@ -65,7 +65,7 @@ class Core:
self.dbCreate = dbcreator.DBCreator(self)
self.forwardKeysFile = self.dataDir + 'forward-keys.db'
self.keyStore = simplekv.DeadSimpleKV(self.dataDir + 'cachedstorage.dat', refresh_seconds=5)
# Socket data, defined here because of multithreading constraints with gevent
self.killSockets = False
self.startSocket = {}
@ -104,6 +104,7 @@ class Core:
else:
logger.warn('Warning: address bootstrap file not found ' + self.bootstrapFileLocation)
self.use_subprocess = powchoice.use_subprocess(self)
self._utils = onionrutils.OnionrUtils(self)
# Initialize the crypto object
self._crypto = onionrcrypto.OnionrCrypto(self)
@ -792,7 +793,10 @@ class Core:
metadata['expire'] = expire
# send block data (and metadata) to POW module to get tokenized block data
payload = subprocesspow.SubprocessPOW(data, metadata, self).start()
if self.use_subprocess:
payload = subprocesspow.SubprocessPOW(data, metadata, self).start()
else:
payload = onionrproofs.POW(metadata, data).waitForResult()
if payload != False:
try:
retData = self.setData(payload)

View File

@ -1,7 +1,7 @@
'''
Onionr - P2P Anonymous Storage Network
Onionr - Private P2P Communication
This file handles proof of memory functionality
This file does determinations for what proof of work module should be used
'''
'''
This program is free software: you can redistribute it and/or modify
@ -17,13 +17,11 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
class ProofOfMemory:
def __init__(self, commInst):
self.communicator = commInst
return
def checkRandomPeer(self):
return
def checkPeer(self, peer):
return
import platform
def use_subprocess(core_inst):
use = True
if not core_inst.config.get('general.use_subprocess_pow_if_possible', True):
use = False
if 'Windows' == platform.system():
use = False
return use

View File

@ -189,7 +189,11 @@ HiddenServicePort 80 ''' + self.apiServerIP + ''':''' + str(self.hsPort)
return
try:
os.kill(int(pidN), signal.SIGTERM)
try:
os.kill(int(pidN), signal.SIGTERM)
except PermissionError:
# seems to happen on win 10
pass
os.remove(self.dataDir + 'torPid.txt')
except ProcessLookupError:
pass

View File

@ -23,6 +23,11 @@ from threading import Thread
import onionr, api, logger, communicator
import onionrevents as events
from netcontroller import NetController
def _proper_shutdown(o_inst):
o_inst.onionrUtils.localCommand('shutdown')
sys.exit(1)
def daemon(o_inst):
'''
Starts the Onionr communication daemon
@ -39,8 +44,7 @@ def daemon(o_inst):
time.sleep(0)
except KeyboardInterrupt:
logger.debug('Got keyboard interrupt, shutting down...')
time.sleep(1)
o_inst.onionrUtils.localCommand('shutdown')
_proper_shutdown(o_inst)
apiHost = ''
while apiHost == '':
@ -64,7 +68,11 @@ def daemon(o_inst):
else:
logger.debug('.onion service disabled')
logger.debug('Using public key: %s' % (logger.colors.underline + o_inst.onionrCore._crypto.pubKey))
time.sleep(1)
try:
time.sleep(1)
except KeyboardInterrupt:
_proper_shutdown(o_inst)
o_inst.onionrCore.torPort = net.socksPort
communicatorThread = Thread(target=communicator.startCommunicator, args=(o_inst, str(net.socksPort)))

View File

@ -26,5 +26,5 @@ def open_home(o_inst):
logger.error('Onionr seems to not be running (could not get api host)')
else:
url = 'http://%s/#%s' % (url, o_inst.onionrCore.config.get('client.webpassword'))
print('If Onionr does not open automatically, use this URL:', url)
logger.info('If Onionr does not open automatically, use this URL:', url)
webbrowser.open_new_tab(url)

View File

@ -205,18 +205,19 @@ class POW:
else:
myCore = coreInst
dataLen = len(data) + len(json.dumps(metadata))
json_metadata = json.dumps(metadata).encode()
if forceDifficulty > 0:
self.difficulty = forceDifficulty
else:
# Calculate difficulty. Dumb for now, may use good algorithm in the future.
self.difficulty = getDifficultyForNewBlock(dataLen)
try:
self.data = self.data.encode()
except AttributeError:
pass
if forceDifficulty > 0:
self.difficulty = forceDifficulty
else:
# Calculate difficulty. Dumb for now, may use good algorithm in the future.
self.difficulty = getDifficultyForNewBlock(bytes(json_metadata + b'\n' + self.data))
logger.info('Computing POW (difficulty: %s)...' % self.difficulty)

View File

@ -4,6 +4,7 @@
"display_header" : false,
"minimum_block_pow": 4,
"minimum_send_pow": 4,
"use_subprocess_pow_if_possible": true,
"socket_servers": false,
"security_level": 0,
"hide_created_blocks": true,

6
run-windows-dev.bat Normal file
View File

@ -0,0 +1,6 @@
@echo off
set ONIONR_HOME=data%random%
echo Using %ONIONR_HOME%
setlocal
chdir onionr
python onionr.py %*