From 06986d27033fae8fc49ec89cf1245db1add8923f Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Thu, 5 Jul 2018 02:31:47 -0500 Subject: [PATCH] * now use communicator2 by default * fixed shutdown command crash * now handle shutdown of api in communicator * work on new POW system (block hash being the POW hash) --- onionr/communicator2.py | 3 +++ onionr/core.py | 15 ++------------- onionr/onionr.py | 6 +----- onionr/onionrutils.py | 2 +- onionr/static-data/default_config.json | 2 +- 5 files changed, 8 insertions(+), 20 deletions(-) diff --git a/onionr/communicator2.py b/onionr/communicator2.py index f6de4b4e..e09b9481 100755 --- a/onionr/communicator2.py +++ b/onionr/communicator2.py @@ -89,9 +89,12 @@ class OnionrCommunicatorDaemon: # Main daemon loop, mainly for calling timers, don't do any complex operations here to avoid locking while not self.shutdown: for i in self.timers: + if self.shutdown: + break i.processTimer() time.sleep(self.delay) logger.info('Goodbye.') + self._core._utils.localCommand('shutdown') def lookupKeys(self): '''Lookup new keys''' diff --git a/onionr/core.py b/onionr/core.py index a85fda09..d220953c 100644 --- a/onionr/core.py +++ b/onionr/core.py @@ -725,26 +725,15 @@ class Core: signature = self._crypto.pubKeyEncrypt(signature, asymPeer, encodedData=True) else: raise onionrexceptions.InvalidPubkey(asymPeer + ' is not a valid base32 encoded ed25519 key') - - powProof = onionrproofs.POW(data) - - # wait for proof to complete - powToken = powProof.waitForResult() - - powToken = base64.b64encode(powToken[1]) - try: - powToken = powToken.decode() - except AttributeError: - pass # compile metadata metadata['meta'] = jsonMeta metadata['sig'] = signature metadata['signer'] = signer - metadata['powRandomToken'] = powToken metadata['time'] = str(self._utils.getEpoch()) - payload = json.dumps(metadata).encode() + b'\n' + data + payload = onionrproofs.POW(metadata, data) + retData = self.setData(payload) self.addToBlockDB(retData, selfInsert=True, dataSaved=True) self.setBlockType(retData, meta['type']) diff --git a/onionr/onionr.py b/onionr/onionr.py index bed40a99..20cc514e 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -42,7 +42,7 @@ except ImportError: ONIONR_TAGLINE = 'Anonymous P2P Platform - GPLv3 - https://Onionr.VoidNet.Tech' ONIONR_VERSION = '0.1.0' # for debugging and stuff ONIONR_VERSION_TUPLE = tuple(ONIONR_VERSION.split('.')) # (MAJOR, MINOR, VERSION) -API_VERSION = '3' # increments of 1; only change when something fundemental about how the API works changes. This way other nodes knows how to communicate without learning too much information about you. +API_VERSION = '4' # increments of 1; only change when something fundemental about how the API works changes. This way other nodes knows how to communicate without learning too much information about you. class Onionr: def __init__(self): @@ -604,10 +604,6 @@ class Onionr: try: events.event('daemon_stop', onionr = self) net = NetController(config.get('client.port', 59496)) - try: - self.onionrUtils.localCommand('shutdown') - except requests.exceptions.ConnectionError: - pass self.onionrCore.daemonQueueAdd('shutdown') net.killTor() except Exception as e: diff --git a/onionr/onionrutils.py b/onionr/onionrutils.py index e108a1dd..6e984bc2 100644 --- a/onionr/onionrutils.py +++ b/onionr/onionrutils.py @@ -169,7 +169,7 @@ class OnionrUtils: retData = requests.get(payload).text except Exception as error: if not silent: - logger.error('Failed to make local request (command: %s).' % command, error=error) + logger.debug('Failed to make local request (command: %s).' % command, error=error) retData = False return retData diff --git a/onionr/static-data/default_config.json b/onionr/static-data/default_config.json index 40958e97..95799594 100644 --- a/onionr/static-data/default_config.json +++ b/onionr/static-data/default_config.json @@ -3,7 +3,7 @@ "dev_mode": true, "display_header" : true, - "newCommunicator": false, + "newCommunicator": true, "dc_response": true, "dc_execcallbacks" : true