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

View File

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

View File

@ -189,7 +189,11 @@ HiddenServicePort 80 ''' + self.apiServerIP + ''':''' + str(self.hsPort)
return return
try: 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') os.remove(self.dataDir + 'torPid.txt')
except ProcessLookupError: except ProcessLookupError:
pass pass

View File

@ -23,6 +23,11 @@ from threading import Thread
import onionr, api, logger, communicator import onionr, api, logger, communicator
import onionrevents as events import onionrevents as events
from netcontroller import NetController from netcontroller import NetController
def _proper_shutdown(o_inst):
o_inst.onionrUtils.localCommand('shutdown')
sys.exit(1)
def daemon(o_inst): def daemon(o_inst):
''' '''
Starts the Onionr communication daemon Starts the Onionr communication daemon
@ -39,8 +44,7 @@ def daemon(o_inst):
time.sleep(0) time.sleep(0)
except KeyboardInterrupt: except KeyboardInterrupt:
logger.debug('Got keyboard interrupt, shutting down...') logger.debug('Got keyboard interrupt, shutting down...')
time.sleep(1) _proper_shutdown(o_inst)
o_inst.onionrUtils.localCommand('shutdown')
apiHost = '' apiHost = ''
while apiHost == '': while apiHost == '':
@ -64,7 +68,11 @@ def daemon(o_inst):
else: else:
logger.debug('.onion service disabled') logger.debug('.onion service disabled')
logger.debug('Using public key: %s' % (logger.colors.underline + o_inst.onionrCore._crypto.pubKey)) 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 o_inst.onionrCore.torPort = net.socksPort
communicatorThread = Thread(target=communicator.startCommunicator, args=(o_inst, str(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)') logger.error('Onionr seems to not be running (could not get api host)')
else: else:
url = 'http://%s/#%s' % (url, o_inst.onionrCore.config.get('client.webpassword')) 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) webbrowser.open_new_tab(url)

View File

@ -205,18 +205,19 @@ class POW:
else: else:
myCore = coreInst 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: try:
self.data = self.data.encode() self.data = self.data.encode()
except AttributeError: except AttributeError:
pass 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) logger.info('Computing POW (difficulty: %s)...' % self.difficulty)

View File

@ -4,6 +4,7 @@
"display_header" : false, "display_header" : false,
"minimum_block_pow": 4, "minimum_block_pow": 4,
"minimum_send_pow": 4, "minimum_send_pow": 4,
"use_subprocess_pow_if_possible": true,
"socket_servers": false, "socket_servers": false,
"security_level": 0, "security_level": 0,
"hide_created_blocks": true, "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 %*